You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2017/12/01 15:49:28 UTC
[05/23] ant git commit: Normalise tabulation and line breaks (cf
master)
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
index b6c3f96..89cd3da 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
@@ -1,316 +1,316 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.util.Properties;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class LayoutPreservingPropertiesTest {
-
- /**
- * Tests that a properties file read by the
- * LayoutPreservingPropertiesFile and then saves the properties in
- * it.
- */
- @Test
- public void testPreserve() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
- FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- lpf.load(fis);
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // now compare original and tmp for property equivalence
- Properties originalProps = new Properties();
- originalProps.load(new FileInputStream(simple));
-
- Properties tmpProps = new Properties();
- tmpProps.load(new FileInputStream(tmp));
-
- assertEquals("properties corrupted", originalProps, tmpProps);
-
- // and now make sure that the comments made it into the new file
- String s = readFile(tmp);
- assertTrue("missing comment", s.indexOf("# a comment") > -1);
- assertTrue("missing comment", s.indexOf("! more comment") > -1);
- }
-
- /**
- * Tests that names and value are properly escaped when being
- * written out.
- */
- @Test
- public void testEscaping() throws Exception {
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
-
- lpf.setProperty(" prop one ", " leading and trailing spaces ");
- lpf.setProperty("prop\ttwo", "contains\ttab");
- lpf.setProperty("prop\nthree", "contains\nnewline");
- lpf.setProperty("prop\rfour", "contains\rcarraige return");
- lpf.setProperty("prop\ffive", "contains\fform feed");
- lpf.setProperty("prop\\six", "contains\\backslash");
- lpf.setProperty("prop:seven", "contains:colon");
- lpf.setProperty("prop=eight", "contains=equals");
- lpf.setProperty("prop#nine", "contains#hash");
- lpf.setProperty("prop!ten", "contains!exclamation");
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue(s.indexOf("\\ prop\\ one\\ =\\ \\ leading and trailing"
- + " spaces ") > -1);
- assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") > -1);
- assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") > -1);
- assertTrue(s.indexOf("prop\\rfour=contains\\rcarraige return") > -1);
- assertTrue(s.indexOf("prop\\\\six=contains\\\\backslash") > -1);
- assertTrue(s.indexOf("prop\\:seven=contains\\:colon") > -1);
- assertTrue(s.indexOf("prop\\=eight=contains\\=equals") > -1);
- assertTrue(s.indexOf("prop\\#nine=contains\\#hash") > -1);
- assertTrue(s.indexOf("prop\\!ten=contains\\!exclamation") > -1);
- }
-
- /**
- * Tests that properties are correctly indexed, so that when we set
- * an existing property, it updates the logical line, and it doesn't
- * append a new one.
- */
- @Test
- public void testOverwrite() throws Exception {
- File unusual = new File(System.getProperty("root"),
- "src/etc/testcases/util/unusual.properties");
- FileInputStream fis = new FileInputStream(unusual);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- lpf.load(fis);
-
- lpf.setProperty(" prop one ", "new one");
- lpf.setProperty("prop\ttwo", "new two");
- lpf.setProperty("prop\nthree", "new three");
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue(s.indexOf("\\ prop\\ one\\ =\\ \\ leading and"
- + " trailing spaces ") == -1);
- assertTrue(s.indexOf("\\ prop\\ one\\ =new one") > -1);
- assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") == -1);
- assertTrue(s.indexOf("prop\\ttwo=new two") > -1);
- assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") == -1);
- assertTrue(s.indexOf("prop\\nthree=new three") > -1);
- }
-
- @Test
- public void testStoreWithHeader() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
- FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- lpf.load(fis);
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(tmp);
- lpf.store(fos, "file-header");
- fos.close();
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue("should have had header ", s.startsWith("#file-header"));
- }
-
- @Test
- public void testClear() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
- FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- lpf.load(fis);
-
- lpf.clear();
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue("should have had no properties ",
- s.indexOf("prop.alpha") == -1);
- assertTrue("should have had no properties ",
- s.indexOf("prop.beta") == -1);
- assertTrue("should have had no properties ",
- s.indexOf("prop.gamma") == -1);
-
- assertTrue("should have had no comments",
- s.indexOf("# a comment") == -1);
- assertTrue("should have had no comments",
- s.indexOf("! more comment") == -1);
- assertTrue("should have had no comments",
- s.indexOf("# now a line wrapping one") == -1);
- }
-
- @Test
- public void testRemove() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
- FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- lpf.load(fis);
-
- lpf.remove("prop.beta");
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue("should not have had prop.beta",
- s.indexOf("prop.beta") == -1);
- assertTrue("should have had prop.beta's comment",
- s.indexOf("! more comment") > -1);
- }
-
- @Test
- public void testRemoveWithComment() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
- FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- lpf.load(fis);
-
- lpf.setRemoveComments(true);
-
- lpf.remove("prop.beta");
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue("should not have had prop.beta",
- s.indexOf("prop.beta") == -1);
- assertTrue("should not have had prop.beta's comment",
- s.indexOf("! more comment") == -1);
- }
-
- @Test
- public void testClone() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
- FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf1 = new LayoutPreservingProperties();
- lpf1.load(fis);
-
- LayoutPreservingProperties lpf2 =
- (LayoutPreservingProperties) lpf1.clone();
-
- lpf2.setProperty("prop.new", "a new property");
- lpf2.setProperty("prop.beta", "a new value for beta");
-
- assertEquals("size of original is wrong", 3, lpf1.size());
- assertEquals("size of clone is wrong", 4, lpf2.size());
-
- File tmp1 = File.createTempFile("tmp", "props");
- tmp1.deleteOnExit();
- lpf1.saveAs(tmp1);
- String s1 = readFile(tmp1);
-
- File tmp2 = File.createTempFile("tmp", "props");
- tmp2.deleteOnExit();
- lpf2.saveAs(tmp2);
- String s2 = readFile(tmp2);
-
- // check original is untouched
- assertTrue("should have had 'simple'", s1.indexOf("simple") > -1);
- assertTrue("should not have had prop.new", s1.indexOf("prop.new") == -1);
-
- // check clone has the changes
- assertTrue("should have had 'a new value for beta'",
- s2.indexOf("a new value for beta") > -1);
- assertTrue("should have had prop.new", s2.indexOf("prop.new") > -1);
- }
-
- @Test
- public void testPreserveEscapeName() throws Exception {
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- File unusual = new File(System.getProperty("root"),
- "src/etc/testcases/util/unusual.properties");
- FileInputStream fis = new FileInputStream(unusual);
- lpf.load(fis);
-
- lpf.setProperty("prop:seven", "new value for seven");
- lpf.setProperty("prop=eight", "new value for eight");
- lpf.setProperty("prop eleven", "new value for eleven");
-
- lpf.setProperty("alpha", "new value for alpha");
- lpf.setProperty("beta", "new value for beta");
-
- File tmp = File.createTempFile("tmp", "props");
- tmp.deleteOnExit();
- lpf.saveAs(tmp);
-
- // and check that the resulting file looks okay
- String s = readFile(tmp);
-
- assertTrue(s.indexOf("prop\\:seven=new value for seven") > -1);
- assertTrue(s.indexOf("prop\\=eight=new value for eight") > -1);
- assertTrue(s.indexOf("prop\\ eleven=new value for eleven") > -1);
- assertTrue(s.indexOf("alpha=new value for alpha") > -1);
- assertTrue(s.indexOf("beta=new value for beta") > -1);
-
- assertTrue(s.indexOf("prop\\:seven=contains\\:colon") == -1);
- assertTrue(s.indexOf("prop\\=eight=contains\\=equals") == -1);
- assertTrue(s.indexOf("alpha:set with a colon") == -1);
- assertTrue(s.indexOf("beta set with a space") == -1);
- }
-
- private static String readFile(File f) throws IOException {
- FileInputStream fis = new FileInputStream(f);
- InputStreamReader isr = new InputStreamReader(fis);
- String s = FileUtils.readFully(isr);
- isr.close();
- fis.close();
- return s;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class LayoutPreservingPropertiesTest {
+
+ /**
+ * Tests that a properties file read by the
+ * LayoutPreservingPropertiesFile and then saves the properties in
+ * it.
+ */
+ @Test
+ public void testPreserve() throws Exception {
+ File simple = new File(System.getProperty("root"),
+ "src/etc/testcases/util/simple.properties");
+ FileInputStream fis = new FileInputStream(simple);
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ lpf.load(fis);
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // now compare original and tmp for property equivalence
+ Properties originalProps = new Properties();
+ originalProps.load(new FileInputStream(simple));
+
+ Properties tmpProps = new Properties();
+ tmpProps.load(new FileInputStream(tmp));
+
+ assertEquals("properties corrupted", originalProps, tmpProps);
+
+ // and now make sure that the comments made it into the new file
+ String s = readFile(tmp);
+ assertTrue("missing comment", s.indexOf("# a comment") > -1);
+ assertTrue("missing comment", s.indexOf("! more comment") > -1);
+ }
+
+ /**
+ * Tests that names and value are properly escaped when being
+ * written out.
+ */
+ @Test
+ public void testEscaping() throws Exception {
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+
+ lpf.setProperty(" prop one ", " leading and trailing spaces ");
+ lpf.setProperty("prop\ttwo", "contains\ttab");
+ lpf.setProperty("prop\nthree", "contains\nnewline");
+ lpf.setProperty("prop\rfour", "contains\rcarraige return");
+ lpf.setProperty("prop\ffive", "contains\fform feed");
+ lpf.setProperty("prop\\six", "contains\\backslash");
+ lpf.setProperty("prop:seven", "contains:colon");
+ lpf.setProperty("prop=eight", "contains=equals");
+ lpf.setProperty("prop#nine", "contains#hash");
+ lpf.setProperty("prop!ten", "contains!exclamation");
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue(s.indexOf("\\ prop\\ one\\ =\\ \\ leading and trailing"
+ + " spaces ") > -1);
+ assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") > -1);
+ assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") > -1);
+ assertTrue(s.indexOf("prop\\rfour=contains\\rcarraige return") > -1);
+ assertTrue(s.indexOf("prop\\\\six=contains\\\\backslash") > -1);
+ assertTrue(s.indexOf("prop\\:seven=contains\\:colon") > -1);
+ assertTrue(s.indexOf("prop\\=eight=contains\\=equals") > -1);
+ assertTrue(s.indexOf("prop\\#nine=contains\\#hash") > -1);
+ assertTrue(s.indexOf("prop\\!ten=contains\\!exclamation") > -1);
+ }
+
+ /**
+ * Tests that properties are correctly indexed, so that when we set
+ * an existing property, it updates the logical line, and it doesn't
+ * append a new one.
+ */
+ @Test
+ public void testOverwrite() throws Exception {
+ File unusual = new File(System.getProperty("root"),
+ "src/etc/testcases/util/unusual.properties");
+ FileInputStream fis = new FileInputStream(unusual);
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ lpf.load(fis);
+
+ lpf.setProperty(" prop one ", "new one");
+ lpf.setProperty("prop\ttwo", "new two");
+ lpf.setProperty("prop\nthree", "new three");
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue(s.indexOf("\\ prop\\ one\\ =\\ \\ leading and"
+ + " trailing spaces ") == -1);
+ assertTrue(s.indexOf("\\ prop\\ one\\ =new one") > -1);
+ assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") == -1);
+ assertTrue(s.indexOf("prop\\ttwo=new two") > -1);
+ assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") == -1);
+ assertTrue(s.indexOf("prop\\nthree=new three") > -1);
+ }
+
+ @Test
+ public void testStoreWithHeader() throws Exception {
+ File simple = new File(System.getProperty("root"),
+ "src/etc/testcases/util/simple.properties");
+ FileInputStream fis = new FileInputStream(simple);
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ lpf.load(fis);
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ FileOutputStream fos = new FileOutputStream(tmp);
+ lpf.store(fos, "file-header");
+ fos.close();
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue("should have had header ", s.startsWith("#file-header"));
+ }
+
+ @Test
+ public void testClear() throws Exception {
+ File simple = new File(System.getProperty("root"),
+ "src/etc/testcases/util/simple.properties");
+ FileInputStream fis = new FileInputStream(simple);
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ lpf.load(fis);
+
+ lpf.clear();
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue("should have had no properties ",
+ s.indexOf("prop.alpha") == -1);
+ assertTrue("should have had no properties ",
+ s.indexOf("prop.beta") == -1);
+ assertTrue("should have had no properties ",
+ s.indexOf("prop.gamma") == -1);
+
+ assertTrue("should have had no comments",
+ s.indexOf("# a comment") == -1);
+ assertTrue("should have had no comments",
+ s.indexOf("! more comment") == -1);
+ assertTrue("should have had no comments",
+ s.indexOf("# now a line wrapping one") == -1);
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ File simple = new File(System.getProperty("root"),
+ "src/etc/testcases/util/simple.properties");
+ FileInputStream fis = new FileInputStream(simple);
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ lpf.load(fis);
+
+ lpf.remove("prop.beta");
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue("should not have had prop.beta",
+ s.indexOf("prop.beta") == -1);
+ assertTrue("should have had prop.beta's comment",
+ s.indexOf("! more comment") > -1);
+ }
+
+ @Test
+ public void testRemoveWithComment() throws Exception {
+ File simple = new File(System.getProperty("root"),
+ "src/etc/testcases/util/simple.properties");
+ FileInputStream fis = new FileInputStream(simple);
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ lpf.load(fis);
+
+ lpf.setRemoveComments(true);
+
+ lpf.remove("prop.beta");
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue("should not have had prop.beta",
+ s.indexOf("prop.beta") == -1);
+ assertTrue("should not have had prop.beta's comment",
+ s.indexOf("! more comment") == -1);
+ }
+
+ @Test
+ public void testClone() throws Exception {
+ File simple = new File(System.getProperty("root"),
+ "src/etc/testcases/util/simple.properties");
+ FileInputStream fis = new FileInputStream(simple);
+ LayoutPreservingProperties lpf1 = new LayoutPreservingProperties();
+ lpf1.load(fis);
+
+ LayoutPreservingProperties lpf2 =
+ (LayoutPreservingProperties) lpf1.clone();
+
+ lpf2.setProperty("prop.new", "a new property");
+ lpf2.setProperty("prop.beta", "a new value for beta");
+
+ assertEquals("size of original is wrong", 3, lpf1.size());
+ assertEquals("size of clone is wrong", 4, lpf2.size());
+
+ File tmp1 = File.createTempFile("tmp", "props");
+ tmp1.deleteOnExit();
+ lpf1.saveAs(tmp1);
+ String s1 = readFile(tmp1);
+
+ File tmp2 = File.createTempFile("tmp", "props");
+ tmp2.deleteOnExit();
+ lpf2.saveAs(tmp2);
+ String s2 = readFile(tmp2);
+
+ // check original is untouched
+ assertTrue("should have had 'simple'", s1.indexOf("simple") > -1);
+ assertTrue("should not have had prop.new", s1.indexOf("prop.new") == -1);
+
+ // check clone has the changes
+ assertTrue("should have had 'a new value for beta'",
+ s2.indexOf("a new value for beta") > -1);
+ assertTrue("should have had prop.new", s2.indexOf("prop.new") > -1);
+ }
+
+ @Test
+ public void testPreserveEscapeName() throws Exception {
+ LayoutPreservingProperties lpf = new LayoutPreservingProperties();
+ File unusual = new File(System.getProperty("root"),
+ "src/etc/testcases/util/unusual.properties");
+ FileInputStream fis = new FileInputStream(unusual);
+ lpf.load(fis);
+
+ lpf.setProperty("prop:seven", "new value for seven");
+ lpf.setProperty("prop=eight", "new value for eight");
+ lpf.setProperty("prop eleven", "new value for eleven");
+
+ lpf.setProperty("alpha", "new value for alpha");
+ lpf.setProperty("beta", "new value for beta");
+
+ File tmp = File.createTempFile("tmp", "props");
+ tmp.deleteOnExit();
+ lpf.saveAs(tmp);
+
+ // and check that the resulting file looks okay
+ String s = readFile(tmp);
+
+ assertTrue(s.indexOf("prop\\:seven=new value for seven") > -1);
+ assertTrue(s.indexOf("prop\\=eight=new value for eight") > -1);
+ assertTrue(s.indexOf("prop\\ eleven=new value for eleven") > -1);
+ assertTrue(s.indexOf("alpha=new value for alpha") > -1);
+ assertTrue(s.indexOf("beta=new value for beta") > -1);
+
+ assertTrue(s.indexOf("prop\\:seven=contains\\:colon") == -1);
+ assertTrue(s.indexOf("prop\\=eight=contains\\=equals") == -1);
+ assertTrue(s.indexOf("alpha:set with a colon") == -1);
+ assertTrue(s.indexOf("beta set with a space") == -1);
+ }
+
+ private static String readFile(File f) throws IOException {
+ FileInputStream fis = new FileInputStream(f);
+ InputStreamReader isr = new InputStreamReader(fis);
+ String s = FileUtils.readFully(isr);
+ isr.close();
+ fis.close();
+ return s;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java
index d7da277..82c3634 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java
@@ -1,75 +1,75 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.util;
-
-import java.io.File;
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * @since Ant 1.6
- */
-public class LazyFileOutputStreamTest {
- private LazyFileOutputStream los;
- private final static File f = new File("test.txt");
-
- @Before
- public void setUp() {
- los = new LazyFileOutputStream(f);
- }
-
- @After
- public void tearDown() throws IOException {
- try {
- los.close();
- } finally {
- f.delete();
- }
- }
-
- @Test
- public void testNoFileWithoutWrite() throws IOException {
- los.close();
- assertTrue(f + " has not been written.", !f.exists());
- }
-
- @Test
- public void testOpen() throws IOException {
- los.open();
- los.close();
- assertTrue(f + " has been written.", f.exists());
- }
-
- @Test
- public void testSingleByte() throws IOException {
- los.write(0);
- los.close();
- assertTrue(f + " has been written.", f.exists());
- }
-
- @Test
- public void testByteArray() throws IOException {
- los.write(new byte[] {0});
- los.close();
- assertTrue(f + " has been written.", f.exists());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @since Ant 1.6
+ */
+public class LazyFileOutputStreamTest {
+ private LazyFileOutputStream los;
+ private final static File f = new File("test.txt");
+
+ @Before
+ public void setUp() {
+ los = new LazyFileOutputStream(f);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ try {
+ los.close();
+ } finally {
+ f.delete();
+ }
+ }
+
+ @Test
+ public void testNoFileWithoutWrite() throws IOException {
+ los.close();
+ assertTrue(f + " has not been written.", !f.exists());
+ }
+
+ @Test
+ public void testOpen() throws IOException {
+ los.open();
+ los.close();
+ assertTrue(f + " has been written.", f.exists());
+ }
+
+ @Test
+ public void testSingleByte() throws IOException {
+ los.write(0);
+ los.close();
+ assertTrue(f + " has been written.", f.exists());
+ }
+
+ @Test
+ public void testByteArray() throws IOException {
+ los.write(new byte[] {0});
+ los.close();
+ assertTrue(f + " has been written.", f.exists());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java
index 0ffd997..1fa23e8 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java
@@ -1,153 +1,153 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-
-public class LineOrientedOutputStreamTest {
-
- private static String LINE = "This is a line";
- private DummyStream stream;
-
-
- @Before
- public void setUp() {
- stream = new DummyStream();
- }
-
- @After
- public void tearDown() throws IOException {
- if (stream != null) {
- stream.close();
- }
- }
-
- @Test
- public void testLineWithLinefeedArray() throws IOException {
- writeByteArray();
- writeAsArray('\n');
- stream.assertInvoked();
- }
-
- @Test
- public void testLineWithLinefeedSingleBytes() throws IOException {
- writeSingleBytes();
- stream.write('\n');
- stream.assertInvoked();
- }
-
- @Test
- public void testLineWithCariagereturnArray() throws IOException {
- writeByteArray();
- writeAsArray('\r');
- stream.assertInvoked();
- }
-
- @Test
- public void testLineWithCariagereturnSingleBytes() throws IOException {
- writeSingleBytes();
- stream.write('\r');
- stream.assertInvoked();
- }
-
- @Test
- public void testLineWithCariagereturnLinefeedArray() throws IOException {
- writeByteArray();
- writeAsArray('\r');
- writeAsArray('\n');
- stream.assertInvoked();
- }
-
- @Test
- public void testLineWithCariagereturnLinefeedSingleBytes() throws IOException {
- writeSingleBytes();
- stream.write('\r');
- stream.write('\n');
- stream.assertInvoked();
- }
-
- @Test
- public void testFlushArray() throws IOException {
- writeByteArray();
- stream.flush();
- stream.assertNotInvoked();
- }
-
- @Test
- public void testFlushSingleBytes() throws IOException {
- writeSingleBytes();
- stream.flush();
- stream.assertNotInvoked();
- }
-
- @Test
- public void testCloseArray() throws IOException {
- writeByteArray();
- stream.close();
- stream.assertInvoked();
- stream = null;
- }
-
- @Test
- public void testCloseSingleBytes() throws IOException {
- writeSingleBytes();
- stream.close();
- stream.assertInvoked();
- stream = null;
- }
-
- private void writeByteArray() throws IOException {
- stream.write(LINE.getBytes(), 0, LINE.length());
- }
-
- private void writeSingleBytes() throws IOException {
- byte[] b = LINE.getBytes();
- for (int i = 0; i < b.length; i++) {
- stream.write(b[i]);
- }
- }
-
- private void writeAsArray(char c) throws IOException {
- stream.write(new byte[] {(byte) c}, 0, 1);
- }
-
- private class DummyStream extends LineOrientedOutputStream {
- private boolean invoked;
- protected void processLine(String line) {
- assertFalse("Only one line", invoked);
- assertEquals(LINE, line);
- invoked = true;
- }
-
- private void assertInvoked() {
- assertTrue("At least one line", invoked);
- }
- private void assertNotInvoked() {
- assertTrue("No output", !invoked);
- }
- }
-}// LineOrientedOutputStreamTest
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import java.io.IOException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+
+public class LineOrientedOutputStreamTest {
+
+ private static String LINE = "This is a line";
+ private DummyStream stream;
+
+
+ @Before
+ public void setUp() {
+ stream = new DummyStream();
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ if (stream != null) {
+ stream.close();
+ }
+ }
+
+ @Test
+ public void testLineWithLinefeedArray() throws IOException {
+ writeByteArray();
+ writeAsArray('\n');
+ stream.assertInvoked();
+ }
+
+ @Test
+ public void testLineWithLinefeedSingleBytes() throws IOException {
+ writeSingleBytes();
+ stream.write('\n');
+ stream.assertInvoked();
+ }
+
+ @Test
+ public void testLineWithCariagereturnArray() throws IOException {
+ writeByteArray();
+ writeAsArray('\r');
+ stream.assertInvoked();
+ }
+
+ @Test
+ public void testLineWithCariagereturnSingleBytes() throws IOException {
+ writeSingleBytes();
+ stream.write('\r');
+ stream.assertInvoked();
+ }
+
+ @Test
+ public void testLineWithCariagereturnLinefeedArray() throws IOException {
+ writeByteArray();
+ writeAsArray('\r');
+ writeAsArray('\n');
+ stream.assertInvoked();
+ }
+
+ @Test
+ public void testLineWithCariagereturnLinefeedSingleBytes() throws IOException {
+ writeSingleBytes();
+ stream.write('\r');
+ stream.write('\n');
+ stream.assertInvoked();
+ }
+
+ @Test
+ public void testFlushArray() throws IOException {
+ writeByteArray();
+ stream.flush();
+ stream.assertNotInvoked();
+ }
+
+ @Test
+ public void testFlushSingleBytes() throws IOException {
+ writeSingleBytes();
+ stream.flush();
+ stream.assertNotInvoked();
+ }
+
+ @Test
+ public void testCloseArray() throws IOException {
+ writeByteArray();
+ stream.close();
+ stream.assertInvoked();
+ stream = null;
+ }
+
+ @Test
+ public void testCloseSingleBytes() throws IOException {
+ writeSingleBytes();
+ stream.close();
+ stream.assertInvoked();
+ stream = null;
+ }
+
+ private void writeByteArray() throws IOException {
+ stream.write(LINE.getBytes(), 0, LINE.length());
+ }
+
+ private void writeSingleBytes() throws IOException {
+ byte[] b = LINE.getBytes();
+ for (int i = 0; i < b.length; i++) {
+ stream.write(b[i]);
+ }
+ }
+
+ private void writeAsArray(char c) throws IOException {
+ stream.write(new byte[] {(byte) c}, 0, 1);
+ }
+
+ private class DummyStream extends LineOrientedOutputStream {
+ private boolean invoked;
+ protected void processLine(String line) {
+ assertFalse("Only one line", invoked);
+ assertEquals(LINE, line);
+ invoked = true;
+ }
+
+ private void assertInvoked() {
+ assertTrue("At least one line", invoked);
+ }
+ private void assertNotInvoked() {
+ assertTrue("No output", !invoked);
+ }
+ }
+}// LineOrientedOutputStreamTest
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java b/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java
index 4b88792..bfd2cda 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java
@@ -1,165 +1,165 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertEquals;
-
-public class LinkedHashtableTest {
-
- private static final Object K1 = new Object();
- private static final Object K2 = new Object();
- private static final Object V1 = new Object();
- private static final Object V2 = new Object();
- private Hashtable h = new LinkedHashtable();
-
- public void testClear() {
- h.put(K1, V1);
- h.clear();
- assertTrue(h.isEmpty());
- }
-
- public void testClone() {
- h.put(K1, V1);
- Hashtable h2 = (Hashtable) h.clone();
- assertTrue(h2 instanceof LinkedHashtable);
- assertTrue(h2.containsKey(K1));
- }
-
- @Test
- public void testContainsAndPut() {
- h.put(K1, V1);
- assertTrue(h.contains(K1));
- assertTrue(h.containsKey(K1));
- assertTrue(h.containsValue(V1));
- assertFalse(h.containsKey(K2));
- }
-
- @Test
- public void testGet() {
- assertNull(h.get(K1));
- h.put(K1, V1);
- assertSame(V1, h.get(K1));
- }
-
- @Test
- public void testIsEmpty() {
- assertTrue(h.isEmpty());
- h.put(K1, V1);
- assertFalse(h.isEmpty());
- }
-
- @Test
- public void testPutReturnValue() {
- assertNull(h.put(K1, V1));
- assertSame(V1, h.put(K1, V2));
- }
-
- @Test
- public void testPutAll() {
- LinkedHashtable h2 = new LinkedHashtable();
- h.put(K1, V1);
- h2.putAll(h);
- assertTrue(h2.containsKey(K1));
- }
-
- @Test
- public void testRemove() {
- h.put(K1, V1);
- assertSame(V1, h.remove(K1));
- assertTrue(h.isEmpty());
- assertNull(h.remove(K1));
- }
-
- @Test
- public void testSize() {
- assertEquals(0, h.size());
- h.put(K1, V1);
- assertEquals(1, h.size());
- }
-
- @Test
- public void testKeys() {
- multiSetup();
- assertKeys(CollectionUtils.asIterator(h.keys()));
- }
-
- @Test
- public void testKeySet() {
- multiSetup();
- assertKeys(h.keySet().iterator());
- }
-
- @Test
- public void testElements() {
- multiSetup();
- assertValues(CollectionUtils.asIterator(h.elements()));
- }
-
- @Test
- public void testValues() {
- multiSetup();
- assertValues(h.values().iterator());
- }
-
- @Test
- public void testEntrySet() {
- multiSetup();
- Iterator i = h.entrySet().iterator();
- assertTrue(i.hasNext());
- Map.Entry e = (Map.Entry) i.next();
- assertSame(K1, e.getKey());
- assertSame(V1, e.getValue());
- assertTrue(i.hasNext());
- e = (Map.Entry) i.next();
- assertSame(K2, e.getKey());
- assertSame(V2, e.getValue());
- assertFalse(i.hasNext());
- }
-
- private void multiSetup() {
- h.put(K1, V1);
- h.put(K2, V2);
- }
-
- private static void assertKeys(Iterator i) {
- assertTrue(i.hasNext());
- assertSame(K1, i.next());
- assertTrue(i.hasNext());
- assertSame(K2, i.next());
- assertFalse(i.hasNext());
- }
-
- private static void assertValues(Iterator i) {
- assertTrue(i.hasNext());
- assertSame(V1, i.next());
- assertTrue(i.hasNext());
- assertSame(V2, i.next());
- assertFalse(i.hasNext());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+
+public class LinkedHashtableTest {
+
+ private static final Object K1 = new Object();
+ private static final Object K2 = new Object();
+ private static final Object V1 = new Object();
+ private static final Object V2 = new Object();
+ private Hashtable h = new LinkedHashtable();
+
+ public void testClear() {
+ h.put(K1, V1);
+ h.clear();
+ assertTrue(h.isEmpty());
+ }
+
+ public void testClone() {
+ h.put(K1, V1);
+ Hashtable h2 = (Hashtable) h.clone();
+ assertTrue(h2 instanceof LinkedHashtable);
+ assertTrue(h2.containsKey(K1));
+ }
+
+ @Test
+ public void testContainsAndPut() {
+ h.put(K1, V1);
+ assertTrue(h.contains(K1));
+ assertTrue(h.containsKey(K1));
+ assertTrue(h.containsValue(V1));
+ assertFalse(h.containsKey(K2));
+ }
+
+ @Test
+ public void testGet() {
+ assertNull(h.get(K1));
+ h.put(K1, V1);
+ assertSame(V1, h.get(K1));
+ }
+
+ @Test
+ public void testIsEmpty() {
+ assertTrue(h.isEmpty());
+ h.put(K1, V1);
+ assertFalse(h.isEmpty());
+ }
+
+ @Test
+ public void testPutReturnValue() {
+ assertNull(h.put(K1, V1));
+ assertSame(V1, h.put(K1, V2));
+ }
+
+ @Test
+ public void testPutAll() {
+ LinkedHashtable h2 = new LinkedHashtable();
+ h.put(K1, V1);
+ h2.putAll(h);
+ assertTrue(h2.containsKey(K1));
+ }
+
+ @Test
+ public void testRemove() {
+ h.put(K1, V1);
+ assertSame(V1, h.remove(K1));
+ assertTrue(h.isEmpty());
+ assertNull(h.remove(K1));
+ }
+
+ @Test
+ public void testSize() {
+ assertEquals(0, h.size());
+ h.put(K1, V1);
+ assertEquals(1, h.size());
+ }
+
+ @Test
+ public void testKeys() {
+ multiSetup();
+ assertKeys(CollectionUtils.asIterator(h.keys()));
+ }
+
+ @Test
+ public void testKeySet() {
+ multiSetup();
+ assertKeys(h.keySet().iterator());
+ }
+
+ @Test
+ public void testElements() {
+ multiSetup();
+ assertValues(CollectionUtils.asIterator(h.elements()));
+ }
+
+ @Test
+ public void testValues() {
+ multiSetup();
+ assertValues(h.values().iterator());
+ }
+
+ @Test
+ public void testEntrySet() {
+ multiSetup();
+ Iterator i = h.entrySet().iterator();
+ assertTrue(i.hasNext());
+ Map.Entry e = (Map.Entry) i.next();
+ assertSame(K1, e.getKey());
+ assertSame(V1, e.getValue());
+ assertTrue(i.hasNext());
+ e = (Map.Entry) i.next();
+ assertSame(K2, e.getKey());
+ assertSame(V2, e.getValue());
+ assertFalse(i.hasNext());
+ }
+
+ private void multiSetup() {
+ h.put(K1, V1);
+ h.put(K2, V2);
+ }
+
+ private static void assertKeys(Iterator i) {
+ assertTrue(i.hasNext());
+ assertSame(K1, i.next());
+ assertTrue(i.hasNext());
+ assertSame(K2, i.next());
+ assertFalse(i.hasNext());
+ }
+
+ private static void assertValues(Iterator i) {
+ assertTrue(i.hasNext());
+ assertSame(V1, i.next());
+ assertTrue(i.hasNext());
+ assertSame(V2, i.next());
+ assertFalse(i.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java
index a4e4735..9935edd 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java
@@ -1,43 +1,43 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.util;
-
-import java.io.File;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
-/**
- * @since Ant 1.6
- */
-public class LoaderUtilsTest {
-
- @Test
- public void testGetXyzSource() {
- File f1 = LoaderUtils.getClassSource(LoaderUtils.class);
- assertNotNull(f1);
-
- File f2 = LoaderUtils.getResourceSource(null,
- "org/apache/tools/ant/taskdefs/defaults.properties");
- assertNotNull(f2);
-
- assertEquals(f1.getAbsolutePath(), f2.getAbsolutePath());
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import java.io.File;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @since Ant 1.6
+ */
+public class LoaderUtilsTest {
+
+ @Test
+ public void testGetXyzSource() {
+ File f1 = LoaderUtils.getClassSource(LoaderUtils.class);
+ assertNotNull(f1);
+
+ File f2 = LoaderUtils.getResourceSource(null,
+ "org/apache/tools/ant/taskdefs/defaults.properties");
+ assertNotNull(f2);
+
+ assertEquals(f1.getAbsolutePath(), f2.getAbsolutePath());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java b/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java
index d02d11e..fdf7393 100644
--- a/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java
@@ -1,43 +1,43 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- package org.apache.tools.ant.util;
-
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertEquals;
-
-public class PackageNameMapperTest {
-
- @Test
- public void testMapping() {
- PackageNameMapper mapper = new PackageNameMapper();
- mapper.setFrom("*.java");
- mapper.setTo("TEST-*.xml");
- String file = fixupPath("org/apache/tools/ant/util/PackageNameMapperTest.java");
- String result = mapper.mapFileName(file)[0];
-
- assertEquals("TEST-org.apache.tools.ant.util.PackageNameMapperTest.xml",
- result);
- }
-
- private String fixupPath(String file) {
- return file.replace('/', File.separatorChar);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+ package org.apache.tools.ant.util;
+
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+
+public class PackageNameMapperTest {
+
+ @Test
+ public void testMapping() {
+ PackageNameMapper mapper = new PackageNameMapper();
+ mapper.setFrom("*.java");
+ mapper.setTo("TEST-*.xml");
+ String file = fixupPath("org/apache/tools/ant/util/PackageNameMapperTest.java");
+ String result = mapper.mapFileName(file)[0];
+
+ assertEquals("TEST-org.apache.tools.ant.util.PackageNameMapperTest.xml",
+ result);
+ }
+
+ private String fixupPath(String file) {
+ return file.replace('/', File.separatorChar);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
index 3cfc93ffa..bd07251 100644
--- a/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java
@@ -1,142 +1,142 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.util;
-
-import org.junit.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Test for ReaderInputStream
- */
-public class ReaderInputStreamTest {
-
- @Test
- public void testSimple() throws Exception {
- compareBytes("abc", "utf-8");
- }
-
- @Test
- public void testSimple16() throws Exception {
- compareBytes("a", "utf-16");
- }
-
- @Test
- public void testSimpleAbc16() throws Exception {
- // THIS WILL FAIL.
- //compareBytes("abc", "utf-16");
- byte[] bytes = new byte[40];
- int pos = 0;
- ReaderInputStream r = new ReaderInputStream(
- new StringReader("abc"), "utf-16");
- for (int i = 0; true; ++i) {
- int res = r.read();
- if (res == -1) {
- break;
- }
- bytes[pos++] = (byte) res;
- }
- bytes = "abc".getBytes("utf-16");
- // String n = new String(bytes, 0, pos, "utf-16");
- new String(bytes, 0, bytes.length, "utf-16");
- }
-
- @Test
- public void testReadZero() throws Exception {
- ReaderInputStream r = new ReaderInputStream(
- new StringReader("abc"));
- byte[] bytes = new byte[30];
- // First read in zero bytes
- r.read(bytes, 0, 0);
- // Now read in the string
- int readin = r.read(bytes, 0, 10);
- // Make sure that the counts are the same
- assertEquals("abc".getBytes().length, readin);
- }
-
- @Test
- public void testPreample() throws Exception {
- byte[] bytes = "".getBytes("utf-16");
- System.out.println("Preample len is " + bytes.length);
- }
-
- @Test
- public void testIso88591ToUtf8() throws Exception {
- InputStreamReader fin = null;
- ReaderInputStream r = null;
- FileInputStream utf8 = null;
- try {
- fin = new InputStreamReader(new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/input/iso8859-1")),
- "ISO8859_1");
- r = new ReaderInputStream(fin, "UTF8");
-
- ByteArrayOutputStream actualOS = new ByteArrayOutputStream();
- int b = r.read();
- while (b > -1) {
- actualOS.write((byte) b);
- b = r.read();
- }
-
- utf8 = new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/expected/utf-8"));
- ByteArrayOutputStream expectedOS = new ByteArrayOutputStream();
- b = utf8.read();
- while (b > -1) {
- expectedOS.write((byte) b);
- b = utf8.read();
- }
-
- byte[] expected = expectedOS.toByteArray();
- byte[] actual = actualOS.toByteArray();
- assertEquals("length", expected.length, actual.length);
- for (int i = 0; i < actual.length; i++) {
- assertEquals("byte " + i, expected[i], actual[i]);
- }
- } finally {
- FileUtils.close(fin);
- FileUtils.close(r);
- FileUtils.close(utf8);
- }
- }
-
- private void compareBytes(String s, String encoding) throws Exception {
- byte[] expected = s.getBytes(encoding);
-
- ReaderInputStream r = new ReaderInputStream(
- new StringReader(s), encoding);
- for (int i = 0; i < expected.length; ++i) {
- int expect = expected[i] & 0xFF;
- int read = r.read();
- if (expect != read) {
- fail("Mismatch in ReaderInputStream at index " + i
- + " expecting " + expect + " got " + read + " for string "
- + s + " with encoding " + encoding);
- }
- }
- if (r.read() != -1) {
- fail("Mismatch in ReaderInputStream - EOF not seen for string "
- + s + " with encoding " + encoding);
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Test for ReaderInputStream
+ */
+public class ReaderInputStreamTest {
+
+ @Test
+ public void testSimple() throws Exception {
+ compareBytes("abc", "utf-8");
+ }
+
+ @Test
+ public void testSimple16() throws Exception {
+ compareBytes("a", "utf-16");
+ }
+
+ @Test
+ public void testSimpleAbc16() throws Exception {
+ // THIS WILL FAIL.
+ //compareBytes("abc", "utf-16");
+ byte[] bytes = new byte[40];
+ int pos = 0;
+ ReaderInputStream r = new ReaderInputStream(
+ new StringReader("abc"), "utf-16");
+ for (int i = 0; true; ++i) {
+ int res = r.read();
+ if (res == -1) {
+ break;
+ }
+ bytes[pos++] = (byte) res;
+ }
+ bytes = "abc".getBytes("utf-16");
+ // String n = new String(bytes, 0, pos, "utf-16");
+ new String(bytes, 0, bytes.length, "utf-16");
+ }
+
+ @Test
+ public void testReadZero() throws Exception {
+ ReaderInputStream r = new ReaderInputStream(
+ new StringReader("abc"));
+ byte[] bytes = new byte[30];
+ // First read in zero bytes
+ r.read(bytes, 0, 0);
+ // Now read in the string
+ int readin = r.read(bytes, 0, 10);
+ // Make sure that the counts are the same
+ assertEquals("abc".getBytes().length, readin);
+ }
+
+ @Test
+ public void testPreample() throws Exception {
+ byte[] bytes = "".getBytes("utf-16");
+ System.out.println("Preample len is " + bytes.length);
+ }
+
+ @Test
+ public void testIso88591ToUtf8() throws Exception {
+ InputStreamReader fin = null;
+ ReaderInputStream r = null;
+ FileInputStream utf8 = null;
+ try {
+ fin = new InputStreamReader(new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/input/iso8859-1")),
+ "ISO8859_1");
+ r = new ReaderInputStream(fin, "UTF8");
+
+ ByteArrayOutputStream actualOS = new ByteArrayOutputStream();
+ int b = r.read();
+ while (b > -1) {
+ actualOS.write((byte) b);
+ b = r.read();
+ }
+
+ utf8 = new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/expected/utf-8"));
+ ByteArrayOutputStream expectedOS = new ByteArrayOutputStream();
+ b = utf8.read();
+ while (b > -1) {
+ expectedOS.write((byte) b);
+ b = utf8.read();
+ }
+
+ byte[] expected = expectedOS.toByteArray();
+ byte[] actual = actualOS.toByteArray();
+ assertEquals("length", expected.length, actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ assertEquals("byte " + i, expected[i], actual[i]);
+ }
+ } finally {
+ FileUtils.close(fin);
+ FileUtils.close(r);
+ FileUtils.close(utf8);
+ }
+ }
+
+ private void compareBytes(String s, String encoding) throws Exception {
+ byte[] expected = s.getBytes(encoding);
+
+ ReaderInputStream r = new ReaderInputStream(
+ new StringReader(s), encoding);
+ for (int i = 0; i < expected.length; ++i) {
+ int expect = expected[i] & 0xFF;
+ int read = r.read();
+ if (expect != read) {
+ fail("Mismatch in ReaderInputStream at index " + i
+ + " expecting " + expect + " got " + read + " for string "
+ + s + " with encoding " + encoding);
+ }
+ }
+ if (r.read() != -1) {
+ fail("Mismatch in ReaderInputStream - EOF not seen for string "
+ + s + " with encoding " + encoding);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java
index b27ee34..96cc9cb 100644
--- a/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java
@@ -1,63 +1,63 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Echo;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.ResourceFactory;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Tests for org.apache.tools.ant.util.ResourceUtils.
- */
-public class ResourceUtilsTest implements ResourceFactory, FileNameMapper {
-
- private Echo taskINeedForLogging = new Echo();
-
- @Before
- public void setUp() {
- taskINeedForLogging.setProject(new Project());
- }
-
- @Test
- public void testNoDuplicates() {
- Resource r = new Resource("samual vimes", true, 1, false);
- Resource[] toNew =
- ResourceUtils.selectOutOfDateSources(taskINeedForLogging,
- new Resource[] {r},
- this, this);
- assertEquals(1, toNew.length);
- }
-
- /* ============ ResourceFactory interface ====================== */
- public Resource getResource(String name) {
- return new Resource(name); // implies lastModified == 0
- }
-
- /* ============ FileNameMapper interface ======================= */
- public void setFrom(String s) {}
- public void setTo(String s) {}
- public String[] mapFileName(String s) {
- return new String[] {"fred colon", "carrot ironfoundersson"};
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Echo;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for org.apache.tools.ant.util.ResourceUtils.
+ */
+public class ResourceUtilsTest implements ResourceFactory, FileNameMapper {
+
+ private Echo taskINeedForLogging = new Echo();
+
+ @Before
+ public void setUp() {
+ taskINeedForLogging.setProject(new Project());
+ }
+
+ @Test
+ public void testNoDuplicates() {
+ Resource r = new Resource("samual vimes", true, 1, false);
+ Resource[] toNew =
+ ResourceUtils.selectOutOfDateSources(taskINeedForLogging,
+ new Resource[] {r},
+ this, this);
+ assertEquals(1, toNew.length);
+ }
+
+ /* ============ ResourceFactory interface ====================== */
+ public Resource getResource(String name) {
+ return new Resource(name); // implies lastModified == 0
+ }
+
+ /* ============ FileNameMapper interface ======================= */
+ public void setFrom(String s) {}
+ public void setTo(String s) {}
+ public String[] mapFileName(String s) {
+ return new String[] {"fred colon", "carrot ironfoundersson"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
index 4dc43ee..bf5b0d4 100644
--- a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
@@ -1,170 +1,170 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.util;
-
-import java.util.Vector;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Test for StringUtils
- */
-public class StringUtilsTest {
-
- @Test
- public void testSplit(){
- final String data = "a,b,,";
- Vector res = StringUtils.split(data, ',');
- assertEquals(4, res.size());
- assertEquals("a", res.elementAt(0));
- assertEquals("b", res.elementAt(1));
- assertEquals("", res.elementAt(2));
- assertEquals("", res.elementAt(3));
- }
-
- @Test
- public void testSplitLines(){
- final String data = "a\r\nb\nc\nd\ne";
- Vector res = StringUtils.lineSplit(data);
- assertEquals(5, res.size());
- assertEquals("a\r", res.elementAt(0));
- assertEquals("b", res.elementAt(1));
- assertEquals("c", res.elementAt(2));
- assertEquals("d", res.elementAt(3));
- assertEquals("e", res.elementAt(4));
- }
-
- @Test
- public void testReplace() {
- final String data = "abcabcabca";
- String res = StringUtils.replace(data, "a", "");
- assertEquals("bcbcbc", res);
- }
-
- @Test
- public void testEndsWithBothEmpty() {
- assertTrue( StringUtils.endsWith( new StringBuffer(), "") );
- }
-
- @Test
- public void testEndsWithEmptyString() {
- assertTrue( StringUtils.endsWith( new StringBuffer("12234545"), "") );
- }
-
- @Test
- public void testEndsWithShorterString() {
- assertTrue( StringUtils.endsWith( new StringBuffer("12345678"), "78"));
- }
-
- @Test
- public void testEndsWithSameString() {
- assertTrue( StringUtils.endsWith( new StringBuffer("123"), "123"));
- }
-
- @Test
- public void testEndsWithLongerString() {
- assertFalse( StringUtils.endsWith( new StringBuffer("12"), "1245"));
- }
-
- @Test
- public void testEndsWithNoMatch() {
- assertFalse( StringUtils.endsWith( new StringBuffer("12345678"), "789"));
- }
-
- @Test
- public void testEndsWithEmptyBuffer() {
- assertFalse( StringUtils.endsWith( new StringBuffer(""), "12345667") );
- }
-
- @Test
- public void testEndsWithJDKPerf() {
- StringBuffer buf = getFilledBuffer(1024*300, 'a');
- for (int i = 0; i < 1000; i++) {
- assertTrue(buf.toString().endsWith("aa"));
- }
- }
-
- @Test
- public void testEndsWithPerf() {
- StringBuffer buf = getFilledBuffer(1024*300, 'a');
- for (int i = 0; i < 1000; i++) {
- assertTrue(StringUtils.endsWith(buf, "aa"));
- }
- }
-
- private StringBuffer getFilledBuffer(int size, char ch) {
- StringBuffer buf = new StringBuffer(size);
- for (int i = 0; i < size; i++) { buf.append(ch); };
- return buf;
- }
-
- @Test
- public void testParseHumanSizes() throws Exception {
- final long KILOBYTE = 1024;
- final long MEGABYTE = KILOBYTE * 1024;
- final long GIGABYTE = MEGABYTE * 1024;
- final long TERABYTE = GIGABYTE * 1024;
- final long PETABYTE = TERABYTE * 1024;
- assertEquals(StringUtils.parseHumanSizes("1K"), KILOBYTE);
- assertEquals(StringUtils.parseHumanSizes("1M"), MEGABYTE);
- assertEquals(StringUtils.parseHumanSizes("1G"), GIGABYTE);
- assertEquals(StringUtils.parseHumanSizes("1T"), TERABYTE);
- assertEquals(StringUtils.parseHumanSizes("1P"), PETABYTE);
- assertEquals(StringUtils.parseHumanSizes("1"), 1L);
- }
-
- @Test
- public void testRemoveSuffix() {
- String prefix = "Prefix";
- String name = "Name";
- String suffix = "Suffix";
- String input = prefix + name + suffix;
- assertEquals(
- "Does not remove the suffix right.",
- prefix + name,
- StringUtils.removeSuffix(input, suffix)
- );
- assertEquals(
- "Should leave the string unattended.",
- prefix + name + suffix,
- StringUtils.removeSuffix(input, "bla")
- );
- }
-
- @Test
- public void testRemovePrefix() {
- String prefix = "Prefix";
- String name = "Name";
- String suffix = "Suffix";
- String input = prefix + name + suffix;
- assertEquals(
- "Does not remove the prefix right.",
- name + suffix,
- StringUtils.removePrefix(input, prefix)
- );
- assertEquals(
- "Should leave the string unattended.",
- prefix + name + suffix,
- StringUtils.removePrefix(input, "bla")
- );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import java.util.Vector;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for StringUtils
+ */
+public class StringUtilsTest {
+
+ @Test
+ public void testSplit(){
+ final String data = "a,b,,";
+ Vector res = StringUtils.split(data, ',');
+ assertEquals(4, res.size());
+ assertEquals("a", res.elementAt(0));
+ assertEquals("b", res.elementAt(1));
+ assertEquals("", res.elementAt(2));
+ assertEquals("", res.elementAt(3));
+ }
+
+ @Test
+ public void testSplitLines(){
+ final String data = "a\r\nb\nc\nd\ne";
+ Vector res = StringUtils.lineSplit(data);
+ assertEquals(5, res.size());
+ assertEquals("a\r", res.elementAt(0));
+ assertEquals("b", res.elementAt(1));
+ assertEquals("c", res.elementAt(2));
+ assertEquals("d", res.elementAt(3));
+ assertEquals("e", res.elementAt(4));
+ }
+
+ @Test
+ public void testReplace() {
+ final String data = "abcabcabca";
+ String res = StringUtils.replace(data, "a", "");
+ assertEquals("bcbcbc", res);
+ }
+
+ @Test
+ public void testEndsWithBothEmpty() {
+ assertTrue( StringUtils.endsWith( new StringBuffer(), "") );
+ }
+
+ @Test
+ public void testEndsWithEmptyString() {
+ assertTrue( StringUtils.endsWith( new StringBuffer("12234545"), "") );
+ }
+
+ @Test
+ public void testEndsWithShorterString() {
+ assertTrue( StringUtils.endsWith( new StringBuffer("12345678"), "78"));
+ }
+
+ @Test
+ public void testEndsWithSameString() {
+ assertTrue( StringUtils.endsWith( new StringBuffer("123"), "123"));
+ }
+
+ @Test
+ public void testEndsWithLongerString() {
+ assertFalse( StringUtils.endsWith( new StringBuffer("12"), "1245"));
+ }
+
+ @Test
+ public void testEndsWithNoMatch() {
+ assertFalse( StringUtils.endsWith( new StringBuffer("12345678"), "789"));
+ }
+
+ @Test
+ public void testEndsWithEmptyBuffer() {
+ assertFalse( StringUtils.endsWith( new StringBuffer(""), "12345667") );
+ }
+
+ @Test
+ public void testEndsWithJDKPerf() {
+ StringBuffer buf = getFilledBuffer(1024*300, 'a');
+ for (int i = 0; i < 1000; i++) {
+ assertTrue(buf.toString().endsWith("aa"));
+ }
+ }
+
+ @Test
+ public void testEndsWithPerf() {
+ StringBuffer buf = getFilledBuffer(1024*300, 'a');
+ for (int i = 0; i < 1000; i++) {
+ assertTrue(StringUtils.endsWith(buf, "aa"));
+ }
+ }
+
+ private StringBuffer getFilledBuffer(int size, char ch) {
+ StringBuffer buf = new StringBuffer(size);
+ for (int i = 0; i < size; i++) { buf.append(ch); };
+ return buf;
+ }
+
+ @Test
+ public void testParseHumanSizes() throws Exception {
+ final long KILOBYTE = 1024;
+ final long MEGABYTE = KILOBYTE * 1024;
+ final long GIGABYTE = MEGABYTE * 1024;
+ final long TERABYTE = GIGABYTE * 1024;
+ final long PETABYTE = TERABYTE * 1024;
+ assertEquals(StringUtils.parseHumanSizes("1K"), KILOBYTE);
+ assertEquals(StringUtils.parseHumanSizes("1M"), MEGABYTE);
+ assertEquals(StringUtils.parseHumanSizes("1G"), GIGABYTE);
+ assertEquals(StringUtils.parseHumanSizes("1T"), TERABYTE);
+ assertEquals(StringUtils.parseHumanSizes("1P"), PETABYTE);
+ assertEquals(StringUtils.parseHumanSizes("1"), 1L);
+ }
+
+ @Test
+ public void testRemoveSuffix() {
+ String prefix = "Prefix";
+ String name = "Name";
+ String suffix = "Suffix";
+ String input = prefix + name + suffix;
+ assertEquals(
+ "Does not remove the suffix right.",
+ prefix + name,
+ StringUtils.removeSuffix(input, suffix)
+ );
+ assertEquals(
+ "Should leave the string unattended.",
+ prefix + name + suffix,
+ StringUtils.removeSuffix(input, "bla")
+ );
+ }
+
+ @Test
+ public void testRemovePrefix() {
+ String prefix = "Prefix";
+ String name = "Name";
+ String suffix = "Suffix";
+ String input = prefix + name + suffix;
+ assertEquals(
+ "Does not remove the prefix right.",
+ name + suffix,
+ StringUtils.removePrefix(input, prefix)
+ );
+ assertEquals(
+ "Should leave the string unattended.",
+ prefix + name + suffix,
+ StringUtils.removePrefix(input, "bla")
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java
index 6f4b037..d1de1b1 100644
--- a/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java
@@ -1,40 +1,40 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import static org.junit.Assert.assertFalse;
-
-import java.io.IOException;
-
-import org.apache.tools.ant.taskdefs.condition.Os;
-import org.junit.Assume;
-import org.junit.Test;
-
-public class SymlinkUtilsTest {
-
- private static final SymbolicLinkUtils SYMLINK_UTILS =
- SymbolicLinkUtils.getSymbolicLinkUtils();
-
- @Test
- public void testRootIsNoSymlink() throws IOException {
- Assume.assumeFalse("Symlink doesn't work on Windows", Os.isFamily("windows"));
- assertFalse(SYMLINK_UTILS.isSymbolicLink("/"));
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import static org.junit.Assert.assertFalse;
+
+import java.io.IOException;
+
+import org.apache.tools.ant.taskdefs.condition.Os;
+import org.junit.Assume;
+import org.junit.Test;
+
+public class SymlinkUtilsTest {
+
+ private static final SymbolicLinkUtils SYMLINK_UTILS =
+ SymbolicLinkUtils.getSymbolicLinkUtils();
+
+ @Test
+ public void testRootIsNoSymlink() throws IOException {
+ Assume.assumeFalse("Symlink doesn't work on Windows", Os.isFamily("windows"));
+ assertFalse(SYMLINK_UTILS.isSymbolicLink("/"));
+ }
+
+}