You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/04/24 05:09:01 UTC
[2/6] ant git commit: Make “root” a field, where necessary
Make “root” a field, where necessary
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/cc88acc4
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/cc88acc4
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/cc88acc4
Branch: refs/heads/master
Commit: cc88acc4f2f72d880970fd645c38f3a05315a87b
Parents: f6cffb3
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Tue Apr 24 07:04:18 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Tue Apr 24 07:08:44 2018 +0200
----------------------------------------------------------------------
.../ant/types/resources/FileResourceTest.java | 6 +-
.../apache/tools/ant/util/FileUtilsTest.java | 36 ++++++------
.../util/LayoutPreservingPropertiesTest.java | 60 ++++++++------------
3 files changed, 49 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/cc88acc4/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
index 690ace6..361855c 100644
--- a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
@@ -18,6 +18,7 @@
package org.apache.tools.ant.types.resources;
import java.io.File;
+import java.io.IOException;
import org.apache.tools.ant.Project;
import org.junit.Before;
@@ -34,8 +35,9 @@ public class FileResourceTest {
private File root;
@Before
- public void setUp() {
- root = new File(System.getProperty("root"));
+ public void setUp() throws IOException {
+ root = (System.getProperty("root") == null) ? new File(".").getCanonicalFile()
+ : new File(System.getProperty("root"));
}
@Test
http://git-wip-us.apache.org/repos/asf/ant/blob/cc88acc4/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
index c759d71..2285512 100644
--- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
@@ -50,6 +50,7 @@ public class FileUtilsTest {
public ExpectedException thrown = ExpectedException.none();
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+ private static final String projectRoot = System.getProperty("root");
private File removeThis;
private String root;
@@ -232,14 +233,17 @@ public class FileUtilsTest {
}
@Test
- public void testNormalizeDosOrNetwareFailures() {
+ public void testNormalizeSlashDosOrNetware() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
thrown.expect(BuildException.class);
- try {
- FILE_UTILS.normalize("/").getPath();
- } finally {
- FILE_UTILS.normalize("\\").getPath();
- }
+ FILE_UTILS.normalize("/").getPath();
+ }
+
+ @Test
+ public void testNormalizeBackSlashDosOrNetware() {
+ assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
+ thrown.expect(BuildException.class);
+ FILE_UTILS.normalize("\\").getPath();
}
@Test
@@ -401,20 +405,20 @@ public class FileUtilsTest {
@Test
public void testContentEquals() throws IOException {
assertTrue("Non existing files",
- FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"),
- new File(System.getProperty("root"), "bar")));
+ FILE_UTILS.contentEquals(new File(projectRoot, "foo"),
+ new File(projectRoot, "bar")));
assertFalse("One exists, the other one doesn\'t",
- FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"),
- new File(System.getProperty("root"), "build.xml")));
+ FILE_UTILS.contentEquals(new File(projectRoot, "foo"),
+ new File(projectRoot, "build.xml")));
assertFalse("Don\'t compare directories",
- FILE_UTILS.contentEquals(new File(System.getProperty("root"), "src"),
- new File(System.getProperty("root"), "src")));
+ FILE_UTILS.contentEquals(new File(projectRoot, "src"),
+ new File(projectRoot, "src")));
assertTrue("File equals itself",
- FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"),
- new File(System.getProperty("root"), "build.xml")));
+ FILE_UTILS.contentEquals(new File(projectRoot, "build.xml"),
+ new File(projectRoot, "build.xml")));
assertFalse("Files are different",
- FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"),
- new File(System.getProperty("root"), "docs.xml")));
+ FILE_UTILS.contentEquals(new File(projectRoot, "build.xml"),
+ new File(projectRoot, "docs.xml")));
}
/**
http://git-wip-us.apache.org/repos/asf/ant/blob/cc88acc4/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 30c8791..6e0f969 100644
--- a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
+import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
@@ -34,6 +35,14 @@ import static org.junit.Assert.assertThat;
public class LayoutPreservingPropertiesTest {
+ private static final String root = System.getProperty("root");
+
+ private LayoutPreservingProperties lpf;
+
+ @Before
+ public void setUp() {
+ lpf = new LayoutPreservingProperties();
+ }
/**
* Tests that a properties file read by the
* LayoutPreservingPropertiesFile and then saves the properties in
@@ -41,10 +50,8 @@ public class LayoutPreservingPropertiesTest {
*/
@Test
public void testPreserve() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
+ File simple = new File(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");
@@ -72,8 +79,6 @@ public class LayoutPreservingPropertiesTest {
*/
@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");
@@ -110,10 +115,8 @@ public class LayoutPreservingPropertiesTest {
*/
@Test
public void testOverwrite() throws Exception {
- File unusual = new File(System.getProperty("root"),
- "src/etc/testcases/util/unusual.properties");
+ File unusual = new File(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");
@@ -137,10 +140,8 @@ public class LayoutPreservingPropertiesTest {
@Test
public void testStoreWithHeader() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
+ File simple = new File(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");
@@ -155,10 +156,8 @@ public class LayoutPreservingPropertiesTest {
@Test
public void testClear() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
+ File simple = new File(root, "src/etc/testcases/util/simple.properties");
FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
lpf.load(fis);
lpf.clear();
@@ -181,10 +180,8 @@ public class LayoutPreservingPropertiesTest {
@Test
public void testRemove() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
+ File simple = new File(root, "src/etc/testcases/util/simple.properties");
FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
lpf.load(fis);
lpf.remove("prop.beta");
@@ -202,10 +199,8 @@ public class LayoutPreservingPropertiesTest {
@Test
public void testRemoveWithComment() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
+ File simple = new File(root, "src/etc/testcases/util/simple.properties");
FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
lpf.load(fis);
lpf.setRemoveComments(true);
@@ -225,29 +220,26 @@ public class LayoutPreservingPropertiesTest {
@Test
public void testClone() throws Exception {
- File simple = new File(System.getProperty("root"),
- "src/etc/testcases/util/simple.properties");
+ File simple = new File(root, "src/etc/testcases/util/simple.properties");
FileInputStream fis = new FileInputStream(simple);
- LayoutPreservingProperties lpf1 = new LayoutPreservingProperties();
- lpf1.load(fis);
+ lpf.load(fis);
- LayoutPreservingProperties lpf2 =
- (LayoutPreservingProperties) lpf1.clone();
+ LayoutPreservingProperties lpfClone = (LayoutPreservingProperties) lpf.clone();
- lpf2.setProperty("prop.new", "a new property");
- lpf2.setProperty("prop.beta", "a new value for beta");
+ lpfClone.setProperty("prop.new", "a new property");
+ lpfClone.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());
+ assertEquals("size of original is wrong", 3, lpf.size());
+ assertEquals("size of clone is wrong", 4, lpfClone.size());
File tmp1 = File.createTempFile("tmp", "props");
tmp1.deleteOnExit();
- lpf1.saveAs(tmp1);
+ lpf.saveAs(tmp1);
String s1 = readFile(tmp1);
File tmp2 = File.createTempFile("tmp", "props");
tmp2.deleteOnExit();
- lpf2.saveAs(tmp2);
+ lpfClone.saveAs(tmp2);
String s2 = readFile(tmp2);
// check original is untouched
@@ -261,9 +253,7 @@ public class LayoutPreservingPropertiesTest {
@Test
public void testPreserveEscapeName() throws Exception {
- LayoutPreservingProperties lpf = new LayoutPreservingProperties();
- File unusual = new File(System.getProperty("root"),
- "src/etc/testcases/util/unusual.properties");
+ File unusual = new File(root, "src/etc/testcases/util/unusual.properties");
FileInputStream fis = new FileInputStream(unusual);
lpf.load(fis);