Browse Source

More matchers/fixtures/optimizations

master
Gintas Grigelionis 7 years ago
parent
commit
4b1d9ae3a6
20 changed files with 502 additions and 513 deletions
  1. +12
    -9
      src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java
  2. +2
    -1
      src/tests/junit/org/apache/tools/ant/ProjectTest.java
  3. +26
    -17
      src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java
  4. +2
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java
  5. +9
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java
  6. +3
    -4
      src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java
  7. +4
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java
  8. +4
    -4
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java
  9. +1
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
  10. +1
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java
  11. +10
    -26
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java
  12. +2
    -6
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java
  13. +93
    -86
      src/tests/junit/org/apache/tools/ant/types/FileListTest.java
  14. +10
    -16
      src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
  15. +7
    -8
      src/tests/junit/org/apache/tools/ant/types/MapperTest.java
  16. +132
    -123
      src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
  17. +51
    -68
      src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java
  18. +0
    -1
      src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java
  19. +0
    -1
      src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java
  20. +133
    -126
      src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java

+ 12
- 9
src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java View File

@@ -18,8 +18,11 @@


package org.apache.tools.ant; package org.apache.tools.ant;


import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
@@ -395,7 +398,7 @@ public class DirectoryScannerTest {
Set<String> set = ds.getScannedDirs(); Set<String> set = ds.getScannedDirs();
assertFalse("empty set", set.isEmpty()); assertFalse("empty set", set.isEmpty());
String s = "alpha/beta/gamma/".replace('/', File.separatorChar); String s = "alpha/beta/gamma/".replace('/', File.separatorChar);
assertFalse("scanned " + s, set.contains(s));
assertThat("scanned " + s, set, not(hasItem(s)));
} }


@Test @Test
@@ -515,16 +518,16 @@ public class DirectoryScannerTest {
ds.scan(); ds.scan();
List<String> dirs = Arrays.asList(ds.getExcludedDirectories()); List<String> dirs = Arrays.asList(ds.getExcludedDirectories());
assertEquals(2, dirs.size()); assertEquals(2, dirs.size());
assertTrue("beta is excluded", dirs.contains("alpha/beta"
.replace('/', File.separatorChar)));
assertTrue("gamma is excluded", dirs.contains("alpha/beta/gamma"
.replace('/', File.separatorChar)));
assertThat("beta is excluded", dirs,
hasItem("alpha/beta".replace('/', File.separatorChar)));
assertThat("gamma is excluded", dirs,
hasItem("alpha/beta/gamma".replace('/', File.separatorChar)));
List<String> files = Arrays.asList(ds.getExcludedFiles()); List<String> files = Arrays.asList(ds.getExcludedFiles());
assertEquals(2, files.size()); assertEquals(2, files.size());
assertTrue("beta.xml is excluded", files.contains("alpha/beta/beta.xml"
.replace('/', File.separatorChar)));
assertTrue("gamma.xml is excluded", files.contains("alpha/beta/gamma/gamma.xml"
.replace('/', File.separatorChar)));
assertThat("beta.xml is excluded", files,
hasItem("alpha/beta/beta.xml".replace('/', File.separatorChar)));
assertThat("gamma.xml is excluded", files,
hasItem("alpha/beta/gamma/gamma.xml".replace('/', File.separatorChar)));
} }


@Test @Test


+ 2
- 1
src/tests/junit/org/apache/tools/ant/ProjectTest.java View File

@@ -34,6 +34,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasValue;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@@ -262,7 +263,7 @@ public class ProjectTest {


@Test @Test
public void testTaskDefinitionContains() { public void testTaskDefinitionContains() {
assertTrue(p.getTaskDefinitions().contains(org.apache.tools.ant.taskdefs.Echo.class));
assertThat(p.getTaskDefinitions(), hasValue(org.apache.tools.ant.taskdefs.Echo.class));
} }


/** /**


+ 26
- 17
src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java View File

@@ -21,10 +21,11 @@ package org.apache.tools.ant.filters;
import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeThat;


import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
@@ -115,8 +116,9 @@ public class TokenFilterTest {
public void testReplaceRegex() throws IOException { public void testReplaceRegex() throws IOException {


buildRule.executeTarget("hasregex"); buildRule.executeTarget("hasregex");
assumeTrue("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world"));
assumeThat("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp"),
containsString("bye world"));


buildRule.executeTarget("replaceregex"); buildRule.executeTarget("replaceregex");
String contents = getFileString(buildRule.getProject().getProperty("output") + "/replaceregex"); String contents = getFileString(buildRule.getProject().getProperty("output") + "/replaceregex");
@@ -131,8 +133,9 @@ public class TokenFilterTest {
@Test @Test
public void testFilterReplaceRegex() throws IOException { public void testFilterReplaceRegex() throws IOException {
buildRule.executeTarget("hasregex"); buildRule.executeTarget("hasregex");
assumeTrue("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world"));
assumeThat("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp"),
containsString("bye world"));


buildRule.executeTarget("filterreplaceregex"); buildRule.executeTarget("filterreplaceregex");
assertThat(getFileString(buildRule.getProject().getProperty("output") + "/filterreplaceregex"), assertThat(getFileString(buildRule.getProject().getProperty("output") + "/filterreplaceregex"),
@@ -143,8 +146,9 @@ public class TokenFilterTest {
@Test @Test
public void testHandleDollerMatch() throws IOException { public void testHandleDollerMatch() throws IOException {
buildRule.executeTarget("hasregex"); buildRule.executeTarget("hasregex");
assumeTrue("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world"));
assumeThat("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp"),
containsString("bye world"));


buildRule.executeTarget("dollermatch"); buildRule.executeTarget("dollermatch");
} }
@@ -184,9 +188,12 @@ public class TokenFilterTest {
@Test @Test
public void testContainsRegex() throws IOException { public void testContainsRegex() throws IOException {
buildRule.executeTarget("hasregex"); buildRule.executeTarget("hasregex");
assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world"));
assertThat("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp"),
containsString("bye world"));


//expectFileContains(buildRule.getProject().getProperty("output") + "/replaceregexp", "bye world");
// assertThat(buildRule.getProject().getProperty("output") + "/replaceregexp",
// containsString("bye world"));


buildRule.executeTarget("containsregex"); buildRule.executeTarget("containsregex");
String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex"); String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex");
@@ -198,8 +205,9 @@ public class TokenFilterTest {
@Test @Test
public void testFilterContainsRegex() throws IOException { public void testFilterContainsRegex() throws IOException {
buildRule.executeTarget("hasregex"); buildRule.executeTarget("hasregex");
assumeTrue("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world"));
assumeThat("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp"),
containsString("bye world"));


buildRule.executeTarget("filtercontainsregex"); buildRule.executeTarget("filtercontainsregex");
String contents = getFileString(buildRule.getProject().getProperty("output") + "/filtercontainsregex"); String contents = getFileString(buildRule.getProject().getProperty("output") + "/filtercontainsregex");
@@ -211,8 +219,9 @@ public class TokenFilterTest {
@Test @Test
public void testContainsRegex2() throws IOException { public void testContainsRegex2() throws IOException {
buildRule.executeTarget("hasregex"); buildRule.executeTarget("hasregex");
assumeTrue("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world"));
assumeThat("Regex not present",
getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp"),
containsString("bye world"));


buildRule.executeTarget("containsregex2"); buildRule.executeTarget("containsregex2");
assertThat(getFileString(buildRule.getProject().getProperty("output") + "/containsregex2"), assertThat(getFileString(buildRule.getProject().getProperty("output") + "/containsregex2"),
@@ -230,8 +239,8 @@ public class TokenFilterTest {


@Test @Test
public void testScriptFilter() throws IOException { public void testScriptFilter() throws IOException {
assumeTrue("Project does not have 'testScriptFilter' target",
buildRule.getProject().getTargets().contains("testScriptFilter"));
assumeThat("Project does not have 'testScriptFilter' target",
buildRule.getProject().getTargets(), hasKey("testScriptFilter"));
buildRule.executeTarget("scriptfilter"); buildRule.executeTarget("scriptfilter");
assertThat(getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter"), assertThat(getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter"),
containsString("HELLO WORLD")); containsString("HELLO WORLD"));
@@ -240,8 +249,8 @@ public class TokenFilterTest {


@Test @Test
public void testScriptFilter2() throws IOException { public void testScriptFilter2() throws IOException {
assumeTrue("Project does not have 'testScriptFilter' target",
buildRule.getProject().getTargets().contains("testScriptFilter"));
assumeThat("Project does not have 'testScriptFilter' target",
buildRule.getProject().getTargets(), hasKey("testScriptFilter"));
buildRule.executeTarget("scriptfilter2"); buildRule.executeTarget("scriptfilter2");
assertThat(getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter2"), assertThat(getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter2"),
containsString("HELLO MOON")); containsString("HELLO MOON"));


+ 2
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java View File

@@ -234,7 +234,8 @@ public class ManifestClassPathTest {
String tmpCanonicalPath = tmpdir.getCanonicalPath(); String tmpCanonicalPath = tmpdir.getCanonicalPath();
driveLetter = tmpCanonicalPath.substring(0, 1).toUpperCase(); driveLetter = tmpCanonicalPath.substring(0, 1).toUpperCase();
} catch (IOException ioe) { } catch (IOException ioe) {
System.out.println("exception happened getting canonical path of java.io.tmpdir : " + ioe.getMessage());
System.out.println("exception happened getting canonical path of java.io.tmpdir : "
+ ioe.getMessage());
} }
String altDriveLetter = null; String altDriveLetter = null;
try { try {


+ 9
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java View File

@@ -21,6 +21,7 @@ package org.apache.tools.ant.taskdefs;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;


import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
@@ -28,9 +29,10 @@ import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;


/** /**
*/ */
@@ -61,16 +63,14 @@ public class ProtectedJarMethodsTest {
"foo", "foo",
}; };
Jar.grabFilesAndDirs(archive, dirs, files); Jar.grabFilesAndDirs(archive, dirs, files);

assertEquals(expectedDirs.length, dirs.size()); assertEquals(expectedDirs.length, dirs.size());
for (String expectedDir : expectedDirs) {
assertTrue("Found " + expectedDir,
dirs.contains(expectedDir));
}
Arrays.stream(expectedDirs).forEach(expectedDir -> assertThat("Found " + expectedDir,
dirs, hasItem(expectedDir)));

assertEquals(expectedFiles.length, files.size()); assertEquals(expectedFiles.length, files.size());
for (String expectedFile : expectedFiles) {
assertTrue("Found " + expectedFile,
files.contains(expectedFile));
}
Arrays.stream(expectedFiles).forEach(expectedFile -> assertThat("Found " + expectedFile,
files, hasItem(expectedFile)));
} }


@Test @Test


+ 3
- 4
src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java View File

@@ -25,6 +25,7 @@ import org.junit.Test;


import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


@@ -139,12 +140,10 @@ public class SyncTest {
} }


public void assertFileIsPresent(String f) { public void assertFileIsPresent(String f) {
assertTrue("Expected file " + f,
buildRule.getProject().resolveFile(f).exists());
assertTrue("Expected file " + f, buildRule.getProject().resolveFile(f).exists());
} }


public void assertFileIsNotPresent(String f) { public void assertFileIsNotPresent(String f) {
assertTrue("Didn't expect file " + f,
!buildRule.getProject().resolveFile(f).exists());
assertFalse("Didn't expect file " + f, buildRule.getProject().resolveFile(f).exists());
} }
} }

+ 4
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java View File

@@ -35,8 +35,9 @@ import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;


import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -270,7 +271,7 @@ public class DefaultCompilerAdapterTest {
assertNotNull(cmd[0]); assertNotNull(cmd[0]);
final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline()); final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
//No modulesourcepath //No modulesourcepath
assertFalse(cmdLine.contains("--module-source-path"));
assertThat(cmdLine, not(hasItem("--module-source-path")));
//The -sourcepath has to be followed by src //The -sourcepath has to be followed by src
int index = cmdLine.indexOf("-sourcepath"); int index = cmdLine.indexOf("-sourcepath");
assertTrue(index != -1 && index < cmdLine.size() - 1); assertTrue(index != -1 && index < cmdLine.size() - 1);
@@ -328,7 +329,7 @@ public class DefaultCompilerAdapterTest {
assertNotNull(cmd[0]); assertNotNull(cmd[0]);
final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline()); final List<String> cmdLine = Arrays.asList(cmd[0].getCommandline());
//No sourcepath //No sourcepath
assertFalse(cmdLine.contains("-sourcepath"));
assertThat(cmdLine, not(hasItem("-sourcepath")));
//The --module-source-path has to be followed by the pattern //The --module-source-path has to be followed by the pattern
int index = cmdLine.indexOf("--module-source-path"); int index = cmdLine.indexOf("--module-source-path");
assertTrue(index != -1 && index < cmdLine.size() - 1); assertTrue(index != -1 && index < cmdLine.size() - 1);


+ 4
- 4
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java View File

@@ -588,8 +588,8 @@ public class JUnitTaskTest {
public void testCheckDuplicateAntJar() throws Exception { public void testCheckDuplicateAntJar() throws Exception {
setupCheckDuplicateTest(); setupCheckDuplicateTest();
buildRule.executeTarget("testCheckForkedPath"); buildRule.executeTarget("testCheckForkedPath");
assertTrue("Expecting the warning about the duplicate ant jar",
buildRule.getLog().contains("WARNING: multiple versions of ant detected in path for junit"));
assertThat("Expecting the warning about the duplicate ant jar", buildRule.getLog(),
containsString("WARNING: multiple versions of ant detected in path for junit"));
} }


@Test @Test
@@ -597,8 +597,8 @@ public class JUnitTaskTest {
setupCheckDuplicateTest(); setupCheckDuplicateTest();
buildRule.getProject().setProperty("includeantruntime", "no"); buildRule.getProject().setProperty("includeantruntime", "no");
buildRule.executeTarget("testCheckForkedPath"); buildRule.executeTarget("testCheckForkedPath");
assertFalse("Unexpected warning about the duplicate ant jar",
buildRule.getLog().contains("WARNING: multiple versions of ant detected in path for junit"));
assertThat("Unexpected warning about the duplicate ant jar", buildRule.getLog(),
not(containsString("WARNING: multiple versions of ant detected in path for junit")));
} }


private void delete(File f) { private void delete(File f) {


+ 1
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java View File

@@ -135,7 +135,7 @@ public class JUnitTestRunnerTest {
public void testInvalidTestCase() { public void testInvalidTestCase() {
TestRunner runner = createRunner(InvalidTestCase.class); TestRunner runner = createRunner(InvalidTestCase.class);
runner.run(); runner.run();
// On junit3 this is a FAILURE, on junit4 this is an ERROR
// For JUnit 3 this is a FAILURE, for JUnit 4 this is an ERROR
int ret = runner.getRetCode(); int ret = runner.getRetCode();
if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
fail("Unexpected result " + ret + " from junit runner"); fail("Unexpected result " + ret + " from junit runner");


+ 1
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java View File

@@ -78,9 +78,7 @@ public class ScpTest {


@After @After
public void tearDown() { public void tearDown() {
for (File file : cleanUpList) {
file.delete();
}
cleanUpList.forEach(File::delete);
} }


@Test @Test


+ 10
- 26
src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java View File

@@ -42,8 +42,8 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;


import java.io.File; import java.io.File;
@@ -88,12 +88,10 @@ public class SymlinkTest {
public void testDelete() { public void testDelete() {
buildRule.executeTarget("test-delete"); buildRule.executeTarget("test-delete");
Project p = buildRule.getProject(); Project p = buildRule.getProject();
String linkDeleted = p.getProperty("test.delete.link.still.there");
assertNotNull("Actual file deleted by symlink", assertNotNull("Actual file deleted by symlink",
p.getProperty("test.delete.file.still.there")); p.getProperty("test.delete.file.still.there"));
if (linkDeleted != null) {
fail(linkDeleted);
}
String linkDeleted = p.getProperty("test.delete.link.still.there");
assertNull(linkDeleted, linkDeleted);
} }


@Test @Test
@@ -144,11 +142,7 @@ public class SymlinkTest {
p.getProperty("test.record.dir2.recorded")); p.getProperty("test.record.dir2.recorded"));


String dir3rec = p.getProperty("test.record.dir3.recorded"); String dir3rec = p.getProperty("test.record.dir3.recorded");

if (dir3rec != null) {
fail(dir3rec);
}

assertNull(dir3rec, dir3rec);
} }


@Test @Test
@@ -159,18 +153,11 @@ public class SymlinkTest {
String link2Rem = p.getProperty("test.recreate.link2.not.removed"); String link2Rem = p.getProperty("test.recreate.link2.not.removed");
String link3Rem = p.getProperty("test.recreate.link3.not.removed"); String link3Rem = p.getProperty("test.recreate.link3.not.removed");
String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed"); String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed");
if (link1Rem != null) {
fail(link1Rem);
}
if (link2Rem != null) {
fail(link2Rem);
}
if (link3Rem != null) {
fail(link3Rem);
}
if (dirlinkRem != null) {
fail(dirlinkRem);
}

assertNull(link1Rem, link1Rem);
assertNull(link2Rem ,link2Rem);
assertNull(link3Rem ,link3Rem);
assertNull(dirlinkRem ,dirlinkRem);


assertNotNull("Failed to recreate link1", assertNotNull("Failed to recreate link1",
p.getProperty("test.recreate.link1.recreated")); p.getProperty("test.recreate.link1.recreated"));
@@ -182,10 +169,7 @@ public class SymlinkTest {
p.getProperty("test.recreate.dirlink.recreated")); p.getProperty("test.recreate.dirlink.recreated"));


String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice"); String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");

if (doubleRecreate != null) {
fail(doubleRecreate);
}
assertNull(doubleRecreate, doubleRecreate);


assertNotNull("Failed to alter dirlink3", assertNotNull("Failed to alter dirlink3",
p.getProperty("test.recreate.dirlink3.was.altered")); p.getProperty("test.recreate.dirlink3.was.altered"));


+ 2
- 6
src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java View File

@@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.vss;


import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
@@ -461,12 +462,7 @@ public class MSVSSTest implements MSVSSConstants {
} }


// Count the number of empty strings // Count the number of empty strings
int cnt = 0;
for (String argument : sGeneratedCmdLine) {
if (argument.isEmpty()) {
cnt++;
}
}
int cnt = (int) Arrays.stream(sGeneratedCmdLine).filter(String::isEmpty).count();
// We have extra elements // We have extra elements
assertFalse("extra args", genLength - cnt > sTestCmdLine.length); assertFalse("extra args", genLength - cnt > sTestCmdLine.length);
} }


+ 93
- 86
src/tests/junit/org/apache/tools/ant/types/FileListTest.java View File

@@ -23,11 +23,11 @@ import org.apache.tools.ant.BuildFileRule;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import java.io.File; import java.io.File;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


/** /**
* Some tests for filelist. * Some tests for filelist.
@@ -35,111 +35,118 @@ import static org.junit.Assert.fail;


public class FileListTest { public class FileListTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


private FileList f;

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/types/filelist.xml"); buildRule.configureProject("src/etc/testcases/types/filelist.xml");
f = new FileList();
} }


/**
* Can add reference to FileList with directory attribute set.
*/
@Test @Test
public void testEmptyElementIfIsReference() {
FileList f = new FileList();
public void testEmptyElementSetDirThenRefid() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
f.setDir(buildRule.getProject().resolveFile(".")); f.setDir(buildRule.getProject().resolveFile("."));
try {
f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to FileList with directory attribute set.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
}


f = new FileList();
@Test
public void testEmptyElementSetFilesThenRefid() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
f.setFiles("foo.xml,c/d/bar.xml"); f.setFiles("foo.xml,c/d/bar.xml");
try {
f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to FileList with file attribute set.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
}


f = new FileList();
@Test
public void testEmptyElementSetRefidThenFiles() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
f.setFiles("a/b/foo.java");
}

@Test
public void testEmptyElementSetRefidThenDir() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
f.setRefid(new Reference(buildRule.getProject(), "dummyref")); f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
f.setFiles("a/b/foo.java");
fail("Can set files in FileList that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
try {
f.setDir(buildRule.getProject().resolveFile("."));
fail("Can set dir in FileList that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
f.setDir(buildRule.getProject().resolveFile("."));
} }


@Test @Test
public void testCircularReferenceCheck() {
FileList f = new FileList();
public void testCircularReferenceCheckDir() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
buildRule.getProject().addReference("dummy", f); buildRule.getProject().addReference("dummy", f);
f.setRefid(new Reference(buildRule.getProject(), "dummy")); f.setRefid(new Reference(buildRule.getProject(), "dummy"));
try {
f.getDir(buildRule.getProject());
fail("Can make FileList a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
try {
f.getFiles(buildRule.getProject());
fail("Can make FileList a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}

// dummy1 --> dummy2 --> dummy3 --> dummy1
FileList f1 = new FileList();
buildRule.getProject().addReference("dummy1", f1);
f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
FileList f2 = new FileList();
buildRule.getProject().addReference("dummy2", f2);
f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
FileList f3 = new FileList();
buildRule.getProject().addReference("dummy3", f3);
f3.setRefid(new Reference(buildRule.getProject(), "dummy1"));
try {
f1.getDir(buildRule.getProject());
fail("Can make circular reference.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
try {
f1.getFiles(buildRule.getProject());
fail("Can make circular reference.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}

// dummy1 --> dummy2 --> dummy3
f.getDir(buildRule.getProject());
}

@Test
public void testCircularReferenceCheckFiles() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
buildRule.getProject().addReference("dummy", f);
f.setRefid(new Reference(buildRule.getProject(), "dummy"));
f.getFiles(buildRule.getProject());
}

@Test
public void testLoopReferenceCheckDir() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
// dummy --> dummyA --> dummyB --> dummy
buildRule.getProject().addReference("dummy", f);
f.setRefid(new Reference(buildRule.getProject(), "dummyA"));
FileList fa = new FileList();
buildRule.getProject().addReference("dummyA", fa);
fa.setRefid(new Reference(buildRule.getProject(), "dummyB"));
FileList fb = new FileList();
buildRule.getProject().addReference("dummyB", fb);
fb.setRefid(new Reference(buildRule.getProject(), "dummy"));
f.getDir(buildRule.getProject());
}

@Test
public void testLoopReferenceCheckFiles() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
// dummy --> dummyA --> dummyB --> dummy
buildRule.getProject().addReference("dummy", f);
f.setRefid(new Reference(buildRule.getProject(), "dummyA"));
FileList fa = new FileList();
buildRule.getProject().addReference("dummyA", fa);
fa.setRefid(new Reference(buildRule.getProject(), "dummyB"));
FileList fb = new FileList();
buildRule.getProject().addReference("dummyB", fb);
fb.setRefid(new Reference(buildRule.getProject(), "dummy"));
f.getFiles(buildRule.getProject());
}

@Test
public void testLoopReferenceCheck() {
// dummy --> dummyA --> dummyB
// (which has the Project's basedir as root). // (which has the Project's basedir as root).
f1 = new FileList();
buildRule.getProject().addReference("dummy1", f1);
f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
f2 = new FileList();
buildRule.getProject().addReference("dummy2", f2);
f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
f3 = new FileList();
buildRule.getProject().addReference("dummy3", f3);
f3.setDir(buildRule.getProject().resolveFile("."));
File dir = f1.getDir(buildRule.getProject());
buildRule.getProject().addReference("dummy", f);
f.setRefid(new Reference(buildRule.getProject(), "dummyA"));
FileList fa = new FileList();
buildRule.getProject().addReference("dummyA", fa);
fa.setRefid(new Reference(buildRule.getProject(), "dummyB"));
FileList fb = new FileList();
buildRule.getProject().addReference("dummyB", fb);
fb.setDir(buildRule.getProject().resolveFile("."));
File dir = f.getDir(buildRule.getProject());
assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir()); assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir());
} }




+ 10
- 16
src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java View File

@@ -208,12 +208,7 @@ public class FilterSetTest {
File file1 = new File(System.getProperty("root"), name1); File file1 = new File(System.getProperty("root"), name1);
File file2 = new File(System.getProperty("root"), name2); File file2 = new File(System.getProperty("root"), name2);



if (!file1.exists() || !file2.exists()) {
return false;
}

if (file1.length() != file2.length()) {
if (!file1.exists() || !file2.exists() || file1.length() != file2.length()) {
return false; return false;
} }


@@ -221,16 +216,15 @@ public class FilterSetTest {
byte[] buffer1 = new byte[BUF_SIZE]; byte[] buffer1 = new byte[BUF_SIZE];
byte[] buffer2 = new byte[BUF_SIZE]; byte[] buffer2 = new byte[BUF_SIZE];


@SuppressWarnings("resource")
FileInputStream fis1 = new FileInputStream(file1);
@SuppressWarnings("resource")
FileInputStream fis2 = new FileInputStream(file2);
int read = 0;
while ((read = fis1.read(buffer1)) != -1) {
fis2.read(buffer2);
for (int i = 0; i < read; ++i) {
if (buffer1[i] != buffer2[i]) {
return false;
try (FileInputStream fis1 = new FileInputStream(file1);
FileInputStream fis2 = new FileInputStream(file2)) {
int read = 0;
while ((read = fis1.read(buffer1)) != -1) {
fis2.read(buffer2);
for (int i = 0; i < read; ++i) {
if (buffer1[i] != buffer2[i]) {
return false;
}
} }
} }
} }


+ 7
- 8
src/tests/junit/org/apache/tools/ant/types/MapperTest.java View File

@@ -34,9 +34,11 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


/** /**
@@ -169,12 +171,9 @@ public class MapperTest {
assertNotNull("no filenames mapped", targets); assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 3, targets.length); assertEquals("wrong number of filenames mapped", 3, targets.length);
List<String> list = Arrays.asList(targets); List<String> list = Arrays.asList(targets);
assertTrue("cannot find expected target \"tofilename\"",
list.contains("tofilename"));
assertTrue("cannot find expected target \"fromfilename\"",
list.contains("fromfilename"));
assertTrue("cannot find expected target \"mergefile\"",
list.contains("mergefile"));
assertThat("cannot find expected target \"tofilename\"", list, hasItem("tofilename"));
assertThat("cannot find expected target \"fromfilename\"", list, hasItem("fromfilename"));
assertThat("cannot find expected target \"mergefile\"", list, hasItem("mergefile"));
} }


/** /**
@@ -216,8 +215,8 @@ public class MapperTest {
assertNotNull("no filenames mapped", targets); assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 2, targets.length); assertEquals("wrong number of filenames mapped", 2, targets.length);
List<String> list = Arrays.asList(targets); List<String> list = Arrays.asList(targets);
assertTrue("cannot find expected target \"def\"", list.contains("def"));
assertTrue("cannot find expected target \"ghi\"", list.contains("ghi"));
assertThat("cannot find expected target \"def\"", list, hasItem("def"));
assertThat("cannot find expected target \"ghi\"", list, hasItem("ghi"));


targets = fileNameMapper.mapFileName("z"); targets = fileNameMapper.mapFileName("z");
assertNull(targets); assertNull(targets);


+ 132
- 123
src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java View File

@@ -21,12 +21,13 @@ package org.apache.tools.ant.types;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import java.io.File; import java.io.File;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


/** /**
* JUnit 4 testcases for org.apache.tools.ant.types.PatternSet. * JUnit 4 testcases for org.apache.tools.ant.types.PatternSet.
@@ -36,151 +37,160 @@ import static org.junit.Assert.fail;


public class PatternSetTest { public class PatternSetTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

private Project project; private Project project;


private PatternSet p;

@Before @Before
public void setUp() { public void setUp() {
project = new Project(); project = new Project();
project.setBasedir("."); project.setBasedir(".");
p = new PatternSet();
} }


@Test @Test
public void testEmptyElementIfIsReference() {
PatternSet p = new PatternSet();
public void testEmptyElementSetIncludesThenRefid() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
p.setIncludes("**/*.java"); p.setIncludes("**/*.java");
try {
p.setRefid(new Reference(project, "dummyref"));
fail("Can add reference to PatternSet with elements from setIncludes");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
p.setRefid(new Reference(project, "dummyref"));
}


p = new PatternSet();
@Test
public void testEmptyElementSetRefidThenIncludes() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
p.setRefid(new Reference(project, "dummyref")); p.setRefid(new Reference(project, "dummyref"));
try {
p.setIncludes("**/*.java");
fail("Can set includes in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
p.setIncludes("**/*.java");
}


p = new PatternSet();
@Test
public void testEmptyElementSetRefidThenIncludesfile() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
p.setRefid(new Reference(project, "dummyref")); p.setRefid(new Reference(project, "dummyref"));
try {
p.setIncludesfile(new File("/a")); p.setIncludesfile(new File("/a"));
fail("Can set includesfile in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
try {
p.setExcludes("**/*.java");
fail("Can set excludes in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
try {
p.setExcludesfile(new File("/a"));
fail("Can set excludesfile in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
try {
p.createInclude();
fail("Can add nested include in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
try {
p.createExclude();
fail("Can add nested exclude in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
try {
p.createIncludesFile();
fail("Can add nested includesfile in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
try {
p.createExcludesFile();
fail("Can add nested excludesfile in PatternSet that is a reference.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
} }


@Test @Test
public void testCircularReferenceCheck() {
PatternSet p = new PatternSet();
public void testEmptyElementSetRefidThenExclude() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
p.setRefid(new Reference(project, "dummyref"));
p.setExcludes("**/*.java");
}

@Test
public void testEmptyElementSetRefidThenExcludesfile() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
p.setRefid(new Reference(project, "dummyref"));
p.setExcludesfile(new File("/a"));
}

@Test
public void testEmptyElementSetRefidThenAddInclude() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
p.setRefid(new Reference(project, "dummyref"));
p.createInclude();
}

@Test
public void testEmptyElementSetRefidThenAddExclude() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
p.setRefid(new Reference(project, "dummyref"));
p.createExclude();
}

@Test
public void testEmptyElementSetRefidThenAddIncludesfile() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
p.setRefid(new Reference(project, "dummyref"));
p.createIncludesFile();
}

@Test
public void testEmptyElementSetRefidThenAddExcludesfile() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
p.setRefid(new Reference(project, "dummyref"));
p.createExcludesFile();
}

@Test
public void testCircularReferenceCheckIncludePaterns() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
project.addReference("dummy", p);
p.setRefid(new Reference(project, "dummy"));
p.getIncludePatterns(project);
}

@Test
public void testCircularReferenceCheckExcludePatterns() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
project.addReference("dummy", p); project.addReference("dummy", p);
p.setRefid(new Reference(project, "dummy")); p.setRefid(new Reference(project, "dummy"));
try {
p.getIncludePatterns(project);
fail("Can make PatternSet a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
try {
p.getExcludePatterns(project);
fail("Can make PatternSet a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}

// dummy1 --> dummy2 --> dummy3 --> dummy1
PatternSet p1 = new PatternSet();
project.addReference("dummy1", p1);
p1.setRefid(new Reference(project, "dummy2"));
PatternSet p2 = new PatternSet();
project.addReference("dummy2", p2);
p2.setRefid(new Reference(project, "dummy3"));
PatternSet p3 = new PatternSet();
project.addReference("dummy3", p3);
p3.setRefid(new Reference(project, "dummy1"));
try {
p1.getIncludePatterns(project);
fail("Can make circular reference.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
try {
p1.getExcludePatterns(project);
fail("Can make circular reference.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}

// dummy1 --> dummy2 --> dummy3
p.getExcludePatterns(project);
}

@Test
public void testLoopReferenceCheckIncludePaterns() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
// dummy --> dummyA --> dummyB --> dummy
project.addReference("dummy", p);
p.setRefid(new Reference(project, "dummyA"));
PatternSet pa = new PatternSet();
project.addReference("dummyA", pa);
pa.setRefid(new Reference(project, "dummyB"));
PatternSet pb = new PatternSet();
project.addReference("dummyB", pb);
pb.setRefid(new Reference(project, "dummy"));
p.getIncludePatterns(project);
}

@Test
public void testLoopReferenceCheckExcludePaterns() {
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
// dummy --> dummyA --> dummyB --> dummy
project.addReference("dummy", p);
p.setRefid(new Reference(project, "dummyA"));
PatternSet pa = new PatternSet();
project.addReference("dummyA", pa);
pa.setRefid(new Reference(project, "dummyB"));
PatternSet pb = new PatternSet();
project.addReference("dummyB", pb);
pb.setRefid(new Reference(project, "dummy"));
p.getExcludePatterns(project);
}

@Test
public void testLoopReferenceCheck() {
// dummy --> dummyA --> dummyB
// (which holds patterns "include" and "exclude") // (which holds patterns "include" and "exclude")
p1 = new PatternSet();
project.addReference("dummy1", p1);
p1.setRefid(new Reference(project, "dummy2"));
p2 = new PatternSet();
project.addReference("dummy2", p2);
p2.setRefid(new Reference(project, "dummy3"));
p3 = new PatternSet();
project.addReference("dummy3", p3);
p3.setIncludes("include");
p3.createExclude().setName("exclude");
String[] i = p1.getIncludePatterns(project);
project.addReference("dummy", p);
p.setRefid(new Reference(project, "dummyA"));
PatternSet pa = new PatternSet();
project.addReference("dummyA", pa);
pa.setRefid(new Reference(project, "dummyB"));
PatternSet pb = new PatternSet();
project.addReference("dummyB", pb);
pb.setIncludes("include");
pb.createExclude().setName("exclude");
String[] i = p.getIncludePatterns(project);
assertEquals("One include pattern buried deep inside a nested patternset structure", assertEquals("One include pattern buried deep inside a nested patternset structure",
1, i.length); 1, i.length);
assertEquals("include", i[0]); assertEquals("include", i[0]);
i = p3.getExcludePatterns(project);
i = pb.getExcludePatterns(project);
assertEquals("One exclude pattern buried deep inside a nested patternset structure", assertEquals("One exclude pattern buried deep inside a nested patternset structure",
1, i.length); 1, i.length);
assertEquals("exclude", i[0]); assertEquals("exclude", i[0]);
@@ -188,7 +198,6 @@ public class PatternSetTest {


@Test @Test
public void testNestedPatternset() { public void testNestedPatternset() {
PatternSet p = new PatternSet();
p.setIncludes("**/*.java"); p.setIncludes("**/*.java");


PatternSet nested = new PatternSet(); PatternSet nested = new PatternSet();


+ 51
- 68
src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java View File

@@ -25,18 +25,22 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.rules.ExpectedException;


public class ResourceListTest { public class ResourceListTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


private ResourceList rl;

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/types/resources/resourcelist.xml"); buildRule.configureProject("src/etc/testcases/types/resources/resourcelist.xml");
rl = new ResourceList();
} }


@After @After
@@ -45,90 +49,69 @@ public class ResourceListTest {
} }


@Test @Test
public void testEmptyElementWithReference() {
ResourceList rl = new ResourceList();
public void testEmptyElementSetEncodingThenRefid() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
rl.setEncoding("foo"); rl.setEncoding("foo");
try {
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to ResourceList with encoding attribute set.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
}


rl = new ResourceList();
@Test
public void testEmptyElementSetRefidThenEncoding() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify more than one attribute when using refid");
rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
rl.setEncoding("foo");
fail("Can set encoding in ResourceList that is a reference");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid",
be.getMessage());
}
rl.setEncoding("foo");
}


rl = new ResourceList();
@Test
public void testEmptyElementAddFileResourceThenRefid() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
rl.add(new FileResource(buildRule.getProject(), ".")); rl.add(new FileResource(buildRule.getProject(), "."));
try {
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to ResourceList with nested resource collection.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
}


rl = new ResourceList();
@Test
public void testEmptyElementAddRefidThenFileResource() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
rl.add(new FileResource(buildRule.getProject(), "."));
fail("Can add reference to ResourceList with nested resource collection.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
rl.add(new FileResource(buildRule.getProject(), "."));
}


rl = new ResourceList();
@Test
public void testEmptyElementAddFilterChainThenRefid() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
rl.addFilterChain(new FilterChain()); rl.addFilterChain(new FilterChain());
try {
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to ResourceList with nested filter chain.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
}


rl = new ResourceList();
@Test
public void testEmptyElementAddRefidThenFilterChain() {
thrown.expect(BuildException.class);
thrown.expectMessage("You must not specify nested elements when using refid");
rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
rl.addFilterChain(new FilterChain());
fail("Can add reference to ResourceList with nested filter chain.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid",
be.getMessage());
}
rl.addFilterChain(new FilterChain());
} }


@Test @Test
public void testCircularReference() { public void testCircularReference() {
ResourceList rl1 = new ResourceList();
rl1.setProject(buildRule.getProject());
rl1.setRefid(new Reference(buildRule.getProject(), "foo"));
thrown.expect(BuildException.class);
thrown.expectMessage("This data type contains a circular reference.");
rl.setProject(buildRule.getProject());
rl.setRefid(new Reference(buildRule.getProject(), "foo"));


ResourceList rl2 = new ResourceList();
rl2.setProject(buildRule.getProject());
buildRule.getProject().addReference("foo", rl2);
ResourceList resourceList = new ResourceList();
resourceList.setProject(buildRule.getProject());
buildRule.getProject().addReference("foo", resourceList);


Union u = new Union(); Union u = new Union();
u.add(rl1);
u.add(rl);
u.setProject(buildRule.getProject()); u.setProject(buildRule.getProject());


rl2.add(u);

try {
rl2.size();
fail("Can make ResourceList a Reference to itself.");
} catch (BuildException be) {
assertEquals("This data type contains a circular reference.",
be.getMessage());
}
resourceList.add(u);
resourceList.size();
} }
} }

+ 0
- 1
src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java View File

@@ -26,7 +26,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;


/** /**


+ 0
- 1
src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java View File

@@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


/** /**
* Tests Type Selectors. * Tests Type Selectors.


+ 133
- 126
src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -26,7 +26,9 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;


import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
@@ -35,7 +37,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;


/** /**
@@ -44,6 +46,9 @@ import static org.junit.Assume.assumeTrue;
*/ */
public class FileUtilsTest { public class FileUtilsTest {


@Rule
public ExpectedException thrown = ExpectedException.none();

private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private File removeThis; private File removeThis;
private String root; private String root;
@@ -77,7 +82,8 @@ public class FileUtilsTest {
FileOutputStream fos = new FileOutputStream(removeThis); FileOutputStream fos = new FileOutputStream(removeThis);
fos.write(new byte[0]); fos.write(new byte[0]);
fos.close(); fos.close();
assumeTrue("Could not change file modified time", removeThis.setLastModified(removeThis.lastModified() - 2000));
assumeTrue("Could not change file modified time",
removeThis.setLastModified(removeThis.lastModified() - 2000));
long modTime = removeThis.lastModified(); long modTime = removeThis.lastModified();
assertNotEquals(0, modTime); assertNotEquals(0, modTime);


@@ -103,82 +109,90 @@ public class FileUtilsTest {
} }


@Test @Test
public void testResolveFile() {
if (!Os.isFamily("dos") && !Os.isFamily("netware")) {
/*
* Start with simple absolute file names.
*/
assertEquals(File.separator,
FILE_UTILS.resolveFile(null, "/").getPath());
assertEquals(File.separator,
FILE_UTILS.resolveFile(null, "\\").getPath());
} else {
assertEqualsIgnoreDriveCase(localize(File.separator),
public void testResolveFilePosix() {
assumeTrue("DOS or NetWare", !Os.isFamily("dos") && !Os.isFamily("netware"));
/*
* Start with simple absolute file names.
*/
assertEquals(File.separator, FILE_UTILS.resolveFile(null, "/").getPath());
assertEquals(File.separator, FILE_UTILS.resolveFile(null, "\\").getPath());
}

@Test
public void testResolveFileDosOrNetware() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
assertEqualsIgnoreDriveCase(localize(File.separator),
FILE_UTILS.resolveFile(null, "/").getPath()); FILE_UTILS.resolveFile(null, "/").getPath());
assertEqualsIgnoreDriveCase(localize(File.separator),
assertEqualsIgnoreDriveCase(localize(File.separator),
FILE_UTILS.resolveFile(null, "\\").getPath()); FILE_UTILS.resolveFile(null, "\\").getPath());
/*
* throw in drive letters
*/
String driveSpec = "C:";
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:";
assertEquals(driveSpecLower + "\\",
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpecLower + "\\",
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
/*
* promised to eliminate consecutive slashes after drive letter.
*/
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
}
/*
* throw in drive letters
*/
String driveSpec = "C:";
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:";
assertEquals(driveSpecLower + "\\",
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpecLower + "\\",
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
/*
* promised to eliminate consecutive slashes after drive letter.
*/
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
if (Os.isFamily("netware")) { if (Os.isFamily("netware")) {
/* /*
* throw in NetWare volume names * throw in NetWare volume names
*/ */
String driveSpec = "SYS:";
driveSpec = "SYS:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "sys:";
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
driveSpecLower = "sys:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
/* /*
* promised to eliminate consecutive slashes after drive letter. * promised to eliminate consecutive slashes after drive letter.
*/ */
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
} else if (!Os.isFamily("dos")) {
/*
* drive letters must be considered just normal filenames.
*/
String driveSpec = "C:";
String udir = System.getProperty("user.dir");
assertEquals(udir + File.separator + driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(udir + File.separator + driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:";
assertEquals(udir + File.separator + driveSpecLower,
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(udir + File.separator + driveSpecLower,
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
} }

}
@Test
public void testResolveFileNotDos() {
assumeFalse("is DOS", Os.isFamily("dos"));
/* /*
* Now test some relative file name magic.
* drive letters must be considered just normal filenames.
*/ */
String driveSpec = "C:";
String udir = System.getProperty("user.dir");
assertEquals(udir + File.separator + driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
assertEquals(udir + File.separator + driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:";
assertEquals(udir + File.separator + driveSpecLower,
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(udir + File.separator + driveSpecLower,
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
}

/*
* Test some relative file name magic.
*/
@Test
public void testResolveRelativeFile() {
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "4").getPath()); FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
@@ -203,95 +217,94 @@ public class FileUtilsTest {
} }


@Test @Test
public void testNormalize() {
if (!Os.isFamily("dos") && !Os.isFamily("netware")) {
/*
* Start with simple absolute file names.
*/
assertEquals(File.separator,
FILE_UTILS.normalize("/").getPath());
assertEquals(File.separator,
FILE_UTILS.normalize("\\").getPath());
} else {
try {
FILE_UTILS.normalize("/").getPath();
fail("normalized \"/\" on dos or netware");
} catch (Exception e) {
}
try {
FILE_UTILS.normalize("\\").getPath();
fail("normalized \"\\\" on dos or netware");
} catch (Exception e) {
}
public void testNormalizePosix() {
assumeTrue("DOS or NetWare", !Os.isFamily("dos") && !Os.isFamily("netware"));
/*
* Start with simple absolute file names.
*/
assertEquals(File.separator, FILE_UTILS.normalize("/").getPath());
assertEquals(File.separator, FILE_UTILS.normalize("\\").getPath());

// Expected exception caught
thrown.expect(BuildException.class);
String driveSpec = "C:";
assertEquals(driveSpec, FILE_UTILS.normalize(driveSpec).getPath());
}

@Test
public void testNormalizeDosOrNetwareFailures() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
thrown.expect(IOException.class);
try {
FILE_UTILS.normalize("/").getPath();
} finally {
FILE_UTILS.normalize("\\").getPath();
} }
}


@Test
public void testNormalizeDosOrNetware() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
if (Os.isFamily("dos")) { if (Os.isFamily("dos")) {
/* /*
* throw in drive letters * throw in drive letters
*/ */
String driveSpec = "C:"; String driveSpec = "C:";
try {
FILE_UTILS.normalize(driveSpec).getPath();
fail(driveSpec + " is not an absolute path");
} catch (Exception e) {
}
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "/").getPath());
FILE_UTILS.normalize(driveSpec + "/").getPath());
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "\\").getPath());
FILE_UTILS.normalize(driveSpec + "\\").getPath());
String driveSpecLower = "c:"; String driveSpecLower = "c:";
assertEquals(driveSpecLower + "\\", assertEquals(driveSpecLower + "\\",
FILE_UTILS.normalize(driveSpecLower + "/").getPath());
FILE_UTILS.normalize(driveSpecLower + "/").getPath());
assertEquals(driveSpecLower + "\\", assertEquals(driveSpecLower + "\\",
FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
/* /*
* promised to eliminate consecutive slashes after drive letter. * promised to eliminate consecutive slashes after drive letter.
*/ */
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "/////").getPath());
FILE_UTILS.normalize(driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());

// Expected exception caught
thrown.expect(BuildException.class);
FILE_UTILS.normalize(driveSpec).getPath();
} else if (Os.isFamily("netware")) { } else if (Os.isFamily("netware")) {
/* /*
* throw in NetWare volume names * throw in NetWare volume names
*/ */
String driveSpec = "SYS:"; String driveSpec = "SYS:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec).getPath());
FILE_UTILS.normalize(driveSpec).getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "/").getPath());
FILE_UTILS.normalize(driveSpec + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "\\").getPath());
FILE_UTILS.normalize(driveSpec + "\\").getPath());
String driveSpecLower = "sys:"; String driveSpecLower = "sys:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpecLower).getPath());
FILE_UTILS.normalize(driveSpecLower).getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpecLower + "/").getPath());
FILE_UTILS.normalize(driveSpecLower + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
assertEquals(driveSpec + "\\junk", assertEquals(driveSpec + "\\junk",
FILE_UTILS.normalize(driveSpecLower + "\\junk").getPath());
FILE_UTILS.normalize(driveSpecLower + "\\junk").getPath());
/* /*
* promised to eliminate consecutive slashes after drive letter. * promised to eliminate consecutive slashes after drive letter.
*/ */
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "/////").getPath());
FILE_UTILS.normalize(driveSpec + "/////").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
} else {
try {
String driveSpec = "C:";
assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec).getPath());
fail("Expected failure, C: isn't an absolute path on other os's");
} catch (BuildException e) {
// Passed test
}
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
} }
}


/*
* Now test some relative file name magic.
*/
/**
* Test some relative file name magic.
*/
@Test
public void testNormalizeRelativeFile() {
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/4")).getPath()); FILE_UTILS.normalize(localize("/1/2/3/4")).getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
@@ -309,16 +322,13 @@ public class FileUtilsTest {
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath()); FILE_UTILS.normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath());


try {
FILE_UTILS.normalize("foo");
fail("foo is not an absolute path");
} catch (BuildException e) {
// Expected exception caught
}

assertEquals("will not go outside FS root (but will not throw an exception either)", assertEquals("will not go outside FS root (but will not throw an exception either)",
new File(localize("/1/../../b")), new File(localize("/1/../../b")),
FILE_UTILS.normalize(localize("/1/../../b"))); FILE_UTILS.normalize(localize("/1/../../b")));

// Expected exception caught
thrown.expect(BuildException.class);
FILE_UTILS.normalize("foo");
} }


/** /**
@@ -326,15 +336,12 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void testNullArgs() { public void testNullArgs() {
try {
FILE_UTILS.normalize(null);
fail("successfully normalized a null-file");
} catch (NullPointerException npe) {
// Expected exception caught
}

File f = FILE_UTILS.resolveFile(null, "a"); File f = FILE_UTILS.resolveFile(null, "a");
assertEquals(f, new File("a").getAbsoluteFile()); assertEquals(f, new File("a").getAbsoluteFile());

// Expected exception caught
thrown.expect(NullPointerException.class);
FILE_UTILS.normalize(null);
} }






Loading…
Cancel
Save