Browse Source

Simplify tests, use Rule and/or try with resources

master
Gintas Grigelionis 6 years ago
parent
commit
2165dd2255
6 changed files with 233 additions and 281 deletions
  1. +4
    -14
      src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java
  2. +9
    -12
      src/tests/junit/org/apache/tools/ant/taskdefs/ExecStreamRedirectorTest.java
  3. +5
    -10
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
  4. +182
    -189
      src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
  5. +21
    -34
      src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
  6. +12
    -22
      src/tests/junit/org/apache/tools/ant/util/PermissionUtilsTest.java

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

@@ -18,6 +18,7 @@


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


import static org.apache.tools.ant.util.FileUtils.readFully;
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;
@@ -32,7 +33,6 @@ import java.io.IOException;
import java.io.Reader; import java.io.Reader;


import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.util.FileUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -44,8 +44,6 @@ public class TokenFilterTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();

@Before @Before
public void setUp() { public void setUp() {
buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml"); buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml");
@@ -268,23 +266,15 @@ public class TokenFilterTest {
// ----------------------------------------------------- // -----------------------------------------------------


private String getFileString(String filename) throws IOException { private String getFileString(String filename) throws IOException {
Reader r = null;
try {
r = new FileReader(FILE_UTILS.resolveFile(buildRule.getProject().getBaseDir(),filename));
return FileUtils.readFully(r);
}
finally {
FileUtils.close(r);
try (Reader r = new FileReader(buildRule.getProject().resolveFile(filename))) {
return readFully(r);
} }
} }




public static class Capitalize implements TokenFilter.Filter { public static class Capitalize implements TokenFilter.Filter {
public String filter(String token) { public String filter(String token) {
if (token.isEmpty()) {
return token;
}
return token.substring(0, 1).toUpperCase() + token.substring(1);
return token.isEmpty() ? token : token.substring(0, 1).toUpperCase() + token.substring(1);
} }
} }




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

@@ -4,6 +4,7 @@ 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.TemporaryFolder;


import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@@ -23,10 +24,15 @@ public class ExecStreamRedirectorTest {
@Rule @Rule
public BuildFileRule buildRule = new BuildFileRule(); public BuildFileRule buildRule = new BuildFileRule();


@Rule
public TemporaryFolder folder = new TemporaryFolder();

private File outputDir;

@Before @Before
public void setUp() {
public void setUp() throws IOException {
buildRule.configureProject("src/etc/testcases/taskdefs/exec/exec-with-redirector.xml"); buildRule.configureProject("src/etc/testcases/taskdefs/exec/exec-with-redirector.xml");
final File outputDir = this.createTmpDir();
outputDir = folder.newFolder(String.valueOf("temp-" + System.nanoTime()));
buildRule.getProject().setUserProperty("output", outputDir.toString()); buildRule.getProject().setUserProperty("output", outputDir.toString());
buildRule.executeTarget("setUp"); buildRule.executeTarget("setUp");
} }
@@ -47,10 +53,9 @@ public class ExecStreamRedirectorTest {
buildRule.executeTarget("list-dir"); buildRule.executeTarget("list-dir");


// verify the redirected output // verify the redirected output
final String outputDirPath = buildRule.getProject().getProperty("output");
byte[] dirListingOutput = null; byte[] dirListingOutput = null;
for (int i = 1; i <= 16; i++) { for (int i = 1; i <= 16; i++) {
final File redirectedOutputFile = new File(outputDirPath, "ls" + i + ".txt");
final File redirectedOutputFile = new File(outputDir, "ls" + i + ".txt");
assertTrue(redirectedOutputFile + " is missing or not a regular file", assertTrue(redirectedOutputFile + " is missing or not a regular file",
redirectedOutputFile.isFile()); redirectedOutputFile.isFile());
final byte[] redirectedOutput = readAllBytes(redirectedOutputFile); final byte[] redirectedOutput = readAllBytes(redirectedOutputFile);
@@ -68,14 +73,6 @@ public class ExecStreamRedirectorTest {
} }
} }


private File createTmpDir() {
final File tmpDir = new File(System.getProperty("java.io.tmpdir"),
String.valueOf("temp-" + System.nanoTime()));
tmpDir.mkdir();
tmpDir.deleteOnExit();
return tmpDir;
}

private static byte[] readAllBytes(final File file) throws IOException { private static byte[] readAllBytes(final File file) throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (FileInputStream fis = new FileInputStream(file)) { try (FileInputStream fis = new FileInputStream(file)) {


+ 5
- 10
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java View File

@@ -18,6 +18,7 @@


package org.apache.tools.ant.taskdefs.optional.junit; package org.apache.tools.ant.taskdefs.optional.junit;


import static org.apache.tools.ant.util.FileUtils.getFileUtils;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -88,12 +89,9 @@ public class JUnitReportTest {
assertTrue("Can't read the report file.", reportFile.canRead()); assertTrue("Can't read the report file.", reportFile.canRead());
assertTrue("File shouldn't be empty.", reportFile.length() > 0); assertTrue("File shouldn't be empty.", reportFile.length() > 0);
// conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
URL reportUrl = new URL(FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()));
InputStream reportStream = reportUrl.openStream();
try {
URL reportUrl = new URL(getFileUtils().toURI(reportFile.getAbsolutePath()));
try (InputStream reportStream = reportUrl.openStream()) {
assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
} finally {
FileUtils.close(reportStream);
} }
} }


@@ -126,16 +124,13 @@ public class JUnitReportTest {
public void testStackTraceLineBreaks() throws Exception { public void testStackTraceLineBreaks() throws Exception {
buildRule.executeTarget("testStackTraceLineBreaks"); buildRule.executeTarget("testStackTraceLineBreaks");
assertIndexCreated(); assertIndexCreated();
FileReader r = null;
try {
r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html"));
try (FileReader r = new FileReader(new File(buildRule.getOutputDir(),
"html/sampleproject/coins/0_CoinTest.html"))) {
String report = FileUtils.readFully(r); String report = FileUtils.readFully(r);
assertThat("output must contain <br>:\n" + report, report, assertThat("output must contain <br>:\n" + report, report,
containsString("junit.framework.AssertionFailedError: DOEG<br>")); containsString("junit.framework.AssertionFailedError: DOEG<br>"));
assertThat("#51049: output must translate line breaks:\n" + report, report, assertThat("#51049: output must translate line breaks:\n" + report, report,
containsString("cur['line.separator'] = '\\r\\n';")); containsString("cur['line.separator'] = '\\r\\n';"));
} finally {
FileUtils.close(r);
} }
} }




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

@@ -30,13 +30,15 @@ import java.util.Optional;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicTestNames; import org.apache.tools.ant.MagicTestNames;
import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.After;
import org.junit.Assert;
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 org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;


import static org.apache.tools.ant.util.FileUtils.getFileUtils;
import static org.apache.tools.ant.util.FileUtils.isCaseSensitiveFileSystem;
import static org.apache.tools.ant.util.FileUtils.isContextRelativePath;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -56,9 +58,10 @@ public class FileUtilsTest {
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();


private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
@Rule
public TemporaryFolder folder = new TemporaryFolder();

private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY); private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY);
private File removeThis;
private String root; private String root;


@Before @Before
@@ -67,13 +70,6 @@ public class FileUtilsTest {
root = new File(File.separator).getAbsolutePath().toUpperCase(); root = new File(File.separator).getAbsolutePath().toUpperCase();
} }


@After
public void tearDown() {
if (removeThis != null && removeThis.exists() && !removeThis.delete()) {
removeThis.deleteOnExit();
}
}

/** /**
* test modification. * test modification.
* Since Ant1.7, the method being tested no longer uses * Since Ant1.7, the method being tested no longer uses
@@ -86,17 +82,16 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void testSetLastModified() throws IOException { public void testSetLastModified() throws IOException {
removeThis = new File("dummy");
FileOutputStream fos = new FileOutputStream(removeThis);
fos.write(new byte[0]);
fos.close();
File removeThis = folder.newFile("dummy");
try (FileOutputStream fos = new FileOutputStream(removeThis)) {
fos.write(new byte[0]);
}
assumeTrue("Could not change file modified time", assumeTrue("Could not change file modified time",
removeThis.setLastModified(removeThis.lastModified() - 2000)); removeThis.setLastModified(removeThis.lastModified() - 2000));
long modTime = removeThis.lastModified(); long modTime = removeThis.lastModified();
assertNotEquals(0, modTime); assertNotEquals(0, modTime);



FILE_UTILS.setFileLastModified(removeThis, -1);
getFileUtils().setFileLastModified(removeThis, -1);
long secondModTime = removeThis.lastModified(); long secondModTime = removeThis.lastModified();
assertTrue(secondModTime > modTime); assertTrue(secondModTime > modTime);


@@ -105,7 +100,7 @@ public class FileUtilsTest {
// in a previous version, the date of the file was set to 123456 // in a previous version, the date of the file was set to 123456
// milliseconds since 01.01.1970 // milliseconds since 01.01.1970
// it did not work on a computer running JDK 1.4.1_02 + Windows 2000 // it did not work on a computer running JDK 1.4.1_02 + Windows 2000
FILE_UTILS.setFileLastModified(removeThis, secondModTime + millisperday);
getFileUtils().setFileLastModified(removeThis, secondModTime + millisperday);
long thirdModTime = removeThis.lastModified(); long thirdModTime = removeThis.lastModified();
/* /*
* I would love to compare this with 123456, but depending on * I would love to compare this with 123456, but depending on
@@ -122,37 +117,37 @@ public class FileUtilsTest {
/* /*
* Start with simple absolute file names. * Start with simple absolute file names.
*/ */
assertEquals(File.separator, FILE_UTILS.resolveFile(null, "/").getPath());
assertEquals(File.separator, FILE_UTILS.resolveFile(null, "\\").getPath());
assertEquals(File.separator, getFileUtils().resolveFile(null, "/").getPath());
assertEquals(File.separator, getFileUtils().resolveFile(null, "\\").getPath());
} }


@Test @Test
public void testResolveFileDosOrNetware() { public void testResolveFileDosOrNetware() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware")); assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
assertEqualsIgnoreDriveCase(localize(File.separator), assertEqualsIgnoreDriveCase(localize(File.separator),
FILE_UTILS.resolveFile(null, "/").getPath());
getFileUtils().resolveFile(null, "/").getPath());
assertEqualsIgnoreDriveCase(localize(File.separator), assertEqualsIgnoreDriveCase(localize(File.separator),
FILE_UTILS.resolveFile(null, "\\").getPath());
getFileUtils().resolveFile(null, "\\").getPath());
/* /*
* throw in drive letters * throw in drive letters
*/ */
String driveSpec = "C:"; String driveSpec = "C:";
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
getFileUtils().resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
getFileUtils().resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:"; String driveSpecLower = "c:";
assertEquals(driveSpecLower + "\\", assertEquals(driveSpecLower + "\\",
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
getFileUtils().resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpecLower + "\\", assertEquals(driveSpecLower + "\\",
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
getFileUtils().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());
getFileUtils().resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
getFileUtils().resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());


if (Os.isFamily("netware")) { if (Os.isFamily("netware")) {
/* /*
@@ -160,21 +155,21 @@ public class FileUtilsTest {
*/ */
driveSpec = "SYS:"; driveSpec = "SYS:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
getFileUtils().resolveFile(null, driveSpec + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
getFileUtils().resolveFile(null, driveSpec + "\\").getPath());
driveSpecLower = "sys:"; driveSpecLower = "sys:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
getFileUtils().resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
getFileUtils().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());
getFileUtils().resolveFile(null, driveSpec + "/////").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
getFileUtils().resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
} }
} }
@Test @Test
@@ -186,14 +181,14 @@ public class FileUtilsTest {
String driveSpec = "C:"; String driveSpec = "C:";
String udir = System.getProperty("user.dir"); String udir = System.getProperty("user.dir");
assertEquals(udir + File.separator + driveSpec, assertEquals(udir + File.separator + driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath());
getFileUtils().resolveFile(null, driveSpec + "/").getPath());
assertEquals(udir + File.separator + driveSpec, assertEquals(udir + File.separator + driveSpec,
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath());
getFileUtils().resolveFile(null, driveSpec + "\\").getPath());
String driveSpecLower = "c:"; String driveSpecLower = "c:";
assertEquals(udir + File.separator + driveSpecLower, assertEquals(udir + File.separator + driveSpecLower,
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath());
getFileUtils().resolveFile(null, driveSpecLower + "/").getPath());
assertEquals(udir + File.separator + driveSpecLower, assertEquals(udir + File.separator + driveSpecLower,
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath());
getFileUtils().resolveFile(null, driveSpecLower + "\\").getPath());
} }


/* /*
@@ -202,25 +197,25 @@ public class FileUtilsTest {
@Test @Test
public void testResolveRelativeFile() { 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());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "./4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), ".\\4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), ".\\4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../3/4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "../3/4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath());
getFileUtils().resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath());


assertEquals("meaningless result but no exception", assertEquals("meaningless result but no exception",
new File(localize("/1/../../b")), new File(localize("/1/../../b")),
FILE_UTILS.resolveFile(new File(localize("/1")), "../../b"));
getFileUtils().resolveFile(new File(localize("/1")), "../../b"));


} }


@@ -230,27 +225,27 @@ public class FileUtilsTest {
/* /*
* Start with simple absolute file names. * Start with simple absolute file names.
*/ */
assertEquals(File.separator, FILE_UTILS.normalize("/").getPath());
assertEquals(File.separator, FILE_UTILS.normalize("\\").getPath());
assertEquals(File.separator, getFileUtils().normalize("/").getPath());
assertEquals(File.separator, getFileUtils().normalize("\\").getPath());


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


@Test @Test
public void testNormalizeSlashDosOrNetware() { public void testNormalizeSlashDosOrNetware() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware")); assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
FILE_UTILS.normalize("/").getPath();
getFileUtils().normalize("/").getPath();
} }


@Test @Test
public void testNormalizeBackSlashDosOrNetware() { public void testNormalizeBackSlashDosOrNetware() {
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware")); assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware"));
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
FILE_UTILS.normalize("\\").getPath();
getFileUtils().normalize("\\").getPath();
} }


@Test @Test
@@ -262,52 +257,52 @@ public class FileUtilsTest {
*/ */
String driveSpec = "C:"; String driveSpec = "C:";
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "/").getPath());
getFileUtils().normalize(driveSpec + "/").getPath());
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "\\").getPath());
getFileUtils().normalize(driveSpec + "\\").getPath());
String driveSpecLower = "c:"; String driveSpecLower = "c:";
assertEquals(driveSpecLower + "\\", assertEquals(driveSpecLower + "\\",
FILE_UTILS.normalize(driveSpecLower + "/").getPath());
getFileUtils().normalize(driveSpecLower + "/").getPath());
assertEquals(driveSpecLower + "\\", assertEquals(driveSpecLower + "\\",
FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
getFileUtils().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());
getFileUtils().normalize(driveSpec + "/////").getPath());
assertEquals(driveSpec + "\\", assertEquals(driveSpec + "\\",
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
getFileUtils().normalize(driveSpec + "\\\\\\\\\\\\").getPath());


// Expected exception caught // Expected exception caught
thrown.expect(BuildException.class); thrown.expect(BuildException.class);
FILE_UTILS.normalize(driveSpec).getPath();
getFileUtils().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());
getFileUtils().normalize(driveSpec).getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "/").getPath());
getFileUtils().normalize(driveSpec + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "\\").getPath());
getFileUtils().normalize(driveSpec + "\\").getPath());
String driveSpecLower = "sys:"; String driveSpecLower = "sys:";
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpecLower).getPath());
getFileUtils().normalize(driveSpecLower).getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpecLower + "/").getPath());
getFileUtils().normalize(driveSpecLower + "/").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpecLower + "\\").getPath());
getFileUtils().normalize(driveSpecLower + "\\").getPath());
assertEquals(driveSpec + "\\junk", assertEquals(driveSpec + "\\junk",
FILE_UTILS.normalize(driveSpecLower + "\\junk").getPath());
getFileUtils().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());
getFileUtils().normalize(driveSpec + "/////").getPath());
assertEquals(driveSpec, assertEquals(driveSpec,
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
getFileUtils().normalize(driveSpec + "\\\\\\\\\\\\").getPath());
} }
} }


@@ -317,29 +312,29 @@ public class FileUtilsTest {
@Test @Test
public void testNormalizeRelativeFile() { public void testNormalizeRelativeFile() {
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/4")).getPath());
getFileUtils().normalize(localize("/1/2/3/4")).getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/./4")).getPath());
getFileUtils().normalize(localize("/1/2/3/./4")).getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/.\\4")).getPath());
getFileUtils().normalize(localize("/1/2/3/.\\4")).getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/./.\\4")).getPath());
getFileUtils().normalize(localize("/1/2/3/./.\\4")).getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/../3/4")).getPath());
getFileUtils().normalize(localize("/1/2/3/../3/4")).getPath());
assertEquals(localize("/1/2/3/4"), assertEquals(localize("/1/2/3/4"),
FILE_UTILS.normalize(localize("/1/2/3/..\\3\\4")).getPath());
getFileUtils().normalize(localize("/1/2/3/..\\3\\4")).getPath());
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());
getFileUtils().normalize(localize("/1/2/3/../../5/.././2/./3/6/../4")).getPath());
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());
getFileUtils().normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath());


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")));
getFileUtils().normalize(localize("/1/../../b")));


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


/** /**
@@ -347,22 +342,21 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void testNullArgs() { public void testNullArgs() {
File f = FILE_UTILS.resolveFile(null, "a");
File f = getFileUtils().resolveFile(null, "a");
assertEquals(f, new File("a").getAbsoluteFile()); assertEquals(f, new File("a").getAbsoluteFile());


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



/** /**
* Test createTempFile * Test createTempFile
*/ */
@Test @Test
public void testCreateTempFile() {
public void testCreateTempFile() throws IOException {
// null parent dir // null parent dir
File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, true);
File tmp1 = getFileUtils().createTempFile("pre", ".suf", null, false, true);
String tmploc = System.getProperty("java.io.tmpdir"); String tmploc = System.getProperty("java.io.tmpdir");
String name = tmp1.getName(); String name = tmp1.getName();
assertThat("starts with pre", name, startsWith("pre")); assertThat("starts with pre", name, startsWith("pre"));
@@ -372,11 +366,9 @@ public class FileUtilsTest {
tmp1.getAbsolutePath()); tmp1.getAbsolutePath());
tmp1.delete(); tmp1.delete();


File dir2 = new File(tmploc + "/ant-test");
dir2.mkdir();
removeThis = dir2;
File dir2 = folder.newFolder("ant-test");


File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true, true);
File tmp2 = getFileUtils().createTempFile("pre", ".suf", dir2, true, true);
String name2 = tmp2.getName(); String name2 = tmp2.getName();
assertThat("starts with pre", name2, startsWith("pre")); assertThat("starts with pre", name2, startsWith("pre"));
assertThat("ends with .suf", name2, endsWith(".suf")); assertThat("ends with .suf", name2, endsWith(".suf"));
@@ -384,10 +376,9 @@ public class FileUtilsTest {
assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(),
tmp2.getAbsolutePath()); tmp2.getAbsolutePath());
tmp2.delete(); tmp2.delete();
dir2.delete();


File parent = new File((new File("/tmp")).getAbsolutePath()); File parent = new File((new File("/tmp")).getAbsolutePath());
tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent, false);
tmp1 = getFileUtils().createTempFile("pre", ".suf", parent, false);
assertFalse("new file", tmp1.exists()); assertFalse("new file", tmp1.exists());


name = tmp1.getName(); name = tmp1.getName();
@@ -396,11 +387,11 @@ public class FileUtilsTest {
assertEquals("is inside parent dir", parent.getAbsolutePath(), tmp1 assertEquals("is inside parent dir", parent.getAbsolutePath(), tmp1
.getParent()); .getParent());


tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false);
tmp2 = getFileUtils().createTempFile("pre", ".suf", parent, false);
assertNotEquals("files are different", tmp1.getAbsolutePath(), tmp2.getAbsolutePath()); assertNotEquals("files are different", tmp1.getAbsolutePath(), tmp2.getAbsolutePath());


// null parent dir // null parent dir
File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null, false);
File tmp3 = getFileUtils().createTempFile("pre", ".suf", null, false);
tmploc = System.getProperty("java.io.tmpdir"); tmploc = System.getProperty("java.io.tmpdir");
assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(),
tmp3.getAbsolutePath()); tmp3.getAbsolutePath());
@@ -412,19 +403,19 @@ public class FileUtilsTest {
@Test @Test
public void testContentEquals() throws IOException { public void testContentEquals() throws IOException {
assertTrue("Non existing files", assertTrue("Non existing files",
FILE_UTILS.contentEquals(new File(ROOT, "foo"),
getFileUtils().contentEquals(new File(ROOT, "foo"),
new File(ROOT, "bar"))); new File(ROOT, "bar")));
assertFalse("One exists, the other one doesn\'t", assertFalse("One exists, the other one doesn\'t",
FILE_UTILS.contentEquals(new File(ROOT, "foo"),
getFileUtils().contentEquals(new File(ROOT, "foo"),
new File(ROOT, "build.xml"))); new File(ROOT, "build.xml")));
assertFalse("Don\'t compare directories", assertFalse("Don\'t compare directories",
FILE_UTILS.contentEquals(new File(ROOT, "src"),
getFileUtils().contentEquals(new File(ROOT, "src"),
new File(ROOT, "src"))); new File(ROOT, "src")));
assertTrue("File equals itself", assertTrue("File equals itself",
FILE_UTILS.contentEquals(new File(ROOT, "build.xml"),
getFileUtils().contentEquals(new File(ROOT, "build.xml"),
new File(ROOT, "build.xml"))); new File(ROOT, "build.xml")));
assertFalse("Files are different", assertFalse("Files are different",
FILE_UTILS.contentEquals(new File(ROOT, "build.xml"),
getFileUtils().contentEquals(new File(ROOT, "build.xml"),
new File(ROOT, "docs.xml"))); new File(ROOT, "docs.xml")));
} }


@@ -433,9 +424,10 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void testCreateNewFile() throws IOException { public void testCreateNewFile() throws IOException {
removeThis = new File("dummy");
File removeThis = new File("dummy");
removeThis.deleteOnExit();
assertFalse(removeThis.exists()); assertFalse(removeThis.exists());
FILE_UTILS.createNewFile(removeThis);
getFileUtils().createNewFile(removeThis);
assertTrue(removeThis.exists()); assertTrue(removeThis.exists());
} }


@@ -444,45 +436,45 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void testRemoveLeadingPath() { public void testRemoveLeadingPath() {
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("/foo"),
new File("/foo/bar"))); new File("/foo/bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo/"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("/foo/"),
new File("/foo/bar"))); new File("/foo/bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("\\foo"),
new File("\\foo\\bar"))); new File("\\foo\\bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo\\"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("\\foo\\"),
new File("\\foo\\bar"))); new File("\\foo\\bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:/foo"),
new File("c:/foo/bar"))); new File("c:/foo/bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo/"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:/foo/"),
new File("c:/foo/bar"))); new File("c:/foo/bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:\\foo"),
new File("c:\\foo\\bar"))); new File("c:\\foo\\bar")));
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"),
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:\\foo\\"),
new File("c:\\foo\\bar"))); new File("c:\\foo\\bar")));
if (!Os.isFamily("dos") && !Os.isFamily("netware")) { if (!Os.isFamily("dos") && !Os.isFamily("netware")) {
assertEquals(FILE_UTILS.normalize("/bar").getAbsolutePath(),
FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar")));
assertEquals(FILE_UTILS.normalize("/foobar").getAbsolutePath(),
FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar")));
assertEquals(getFileUtils().normalize("/bar").getAbsolutePath(),
getFileUtils().removeLeadingPath(new File("/foo"), new File("/bar")));
assertEquals(getFileUtils().normalize("/foobar").getAbsolutePath(),
getFileUtils().removeLeadingPath(new File("/foo"), new File("/foobar")));
} }
// bugzilla report 19979 // bugzilla report 19979
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"),
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar"),
new File("/foo/bar"))); new File("/foo/bar")));
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"),
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar"),
new File("/foo/bar/"))); new File("/foo/bar/")));
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"),
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar/"),
new File("/foo/bar/"))); new File("/foo/bar/")));
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"),
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar/"),
new File("/foo/bar"))); new File("/foo/bar")));


String expected = "foo/bar".replace('\\', File.separatorChar) String expected = "foo/bar".replace('\\', File.separatorChar)
.replace('/', File.separatorChar); .replace('/', File.separatorChar);
assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("/"),
assertEquals(expected, getFileUtils().removeLeadingPath(new File("/"),
new File("/foo/bar"))); new File("/foo/bar")));
assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:/"),
assertEquals(expected, getFileUtils().removeLeadingPath(new File("c:/"),
new File("c:/foo/bar"))); new File("c:/foo/bar")));
assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:\\"),
assertEquals(expected, getFileUtils().removeLeadingPath(new File("c:\\"),
new File("c:\\foo\\bar"))); new File("c:\\foo\\bar")));
} }


@@ -499,28 +491,28 @@ public class FileUtilsTest {
dosRoot = ""; dosRoot = "";
} }
if (Os.isFamily("dos")) { if (Os.isFamily("dos")) {
assertEquals("file:/c:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("c:\\foo")));
assertEquals("file:/c:/foo", removeExtraneousAuthority(getFileUtils().toURI("c:\\foo")));
} }
if (Os.isFamily("netware")) { if (Os.isFamily("netware")) {
assertEquals("file:/SYS:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("sys:\\foo")));
assertEquals("file:/SYS:/foo", removeExtraneousAuthority(getFileUtils().toURI("sys:\\foo")));
} }
if (File.pathSeparatorChar == '/') { if (File.pathSeparatorChar == '/') {
assertEquals("file:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("/foo")));
assertThat("file: URIs must name absolute paths", FILE_UTILS.toURI("./foo"), startsWith("file:/"));
assertThat(FILE_UTILS.toURI("./foo"), endsWith("/foo"));
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(FILE_UTILS.toURI("/foo bar")));
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(FILE_UTILS.toURI("/foo#bar")));
assertEquals("file:/foo", removeExtraneousAuthority(getFileUtils().toURI("/foo")));
assertThat("file: URIs must name absolute paths", getFileUtils().toURI("./foo"), startsWith("file:/"));
assertThat(getFileUtils().toURI("./foo"), endsWith("/foo"));
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(getFileUtils().toURI("/foo bar")));
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(getFileUtils().toURI("/foo#bar")));
} else if (File.pathSeparatorChar == '\\') { } else if (File.pathSeparatorChar == '\\') {
assertEquals("file:/" + dosRoot + "foo", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo")));
assertThat("file: URIs must name absolute paths", FILE_UTILS.toURI(".\\foo"), startsWith("file:/"));
assertThat(FILE_UTILS.toURI(".\\foo"), endsWith("/foo"));
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo bar")));
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo#bar")));
assertEquals("file:/" + dosRoot + "foo", removeExtraneousAuthority(getFileUtils().toURI("\\foo")));
assertThat("file: URIs must name absolute paths", getFileUtils().toURI(".\\foo"), startsWith("file:/"));
assertThat(getFileUtils().toURI(".\\foo"), endsWith("/foo"));
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(getFileUtils().toURI("\\foo bar")));
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(getFileUtils().toURI("\\foo#bar")));
} }
// a test with ant for germans // a test with ant for germans
// the escaped character used for the test is the "a umlaut" // the escaped character used for the test is the "a umlaut"
// this is the fix for the bug 37348 // this is the fix for the bug 37348
assertEquals("file:/" + dosRoot + "%C3%A4nt", removeExtraneousAuthority(FILE_UTILS.toURI("/\u00E4nt")));
assertEquals("file:/" + dosRoot + "%C3%A4nt", removeExtraneousAuthority(getFileUtils().toURI("/\u00E4nt")));
} }


/** /**
@@ -539,8 +531,8 @@ public class FileUtilsTest {
@Test @Test
public void testIsContextRelativePath() { public void testIsContextRelativePath() {
assumeTrue("Test only runs on DOS", Os.isFamily("dos")); assumeTrue("Test only runs on DOS", Os.isFamily("dos"));
assertTrue(FileUtils.isContextRelativePath("/\u00E4nt"));
assertTrue(FileUtils.isContextRelativePath("\\foo"));
assertTrue(isContextRelativePath("/\u00E4nt"));
assertTrue(isContextRelativePath("\\foo"));
} }


/** /**
@@ -555,16 +547,16 @@ public class FileUtilsTest {
dosRoot = ""; dosRoot = "";
} }
if (Os.isFamily("netware")) { if (Os.isFamily("netware")) {
assertEqualsIgnoreDriveCase("SYS:\\foo", FILE_UTILS.fromURI("file:///sys:/foo"));
assertEqualsIgnoreDriveCase("SYS:\\foo", getFileUtils().fromURI("file:///sys:/foo"));
} }
if (Os.isFamily("dos")) { if (Os.isFamily("dos")) {
assertEqualsIgnoreDriveCase("C:\\foo", FILE_UTILS.fromURI("file:///c:/foo"));
assertEqualsIgnoreDriveCase("C:\\foo", getFileUtils().fromURI("file:///c:/foo"));
} }
assertEqualsIgnoreDriveCase(dosRoot + File.separator + "foo", FILE_UTILS.fromURI("file:///foo"));
assertEqualsIgnoreDriveCase(dosRoot + File.separator + "foo", getFileUtils().fromURI("file:///foo"));
assertEquals("." + File.separator + "foo", assertEquals("." + File.separator + "foo",
FILE_UTILS.fromURI("file:./foo"));
assertEquals(dosRoot + File.separator + "foo bar", FILE_UTILS.fromURI("file:///foo%20bar"));
assertEquals(dosRoot + File.separator + "foo#bar", FILE_UTILS.fromURI("file:///foo%23bar"));
getFileUtils().fromURI("file:./foo"));
assertEquals(dosRoot + File.separator + "foo bar", getFileUtils().fromURI("file:///foo%20bar"));
assertEquals(dosRoot + File.separator + "foo#bar", getFileUtils().fromURI("file:///foo%23bar"));
} }


@Test @Test
@@ -581,30 +573,30 @@ public class FileUtilsTest {


//check that older is up to date with a newer dest //check that older is up to date with a newer dest
assertTrue("older source files are up to date", assertTrue("older source files are up to date",
FILE_UTILS.isUpToDate(firstTime,secondTime));
getFileUtils().isUpToDate(firstTime,secondTime));
//check that older is up to date with a newer dest //check that older is up to date with a newer dest
assertFalse("newer source files are no up to date", assertFalse("newer source files are no up to date",
FILE_UTILS.isUpToDate(secondTime, firstTime));
getFileUtils().isUpToDate(secondTime, firstTime));


assertFalse("-1 dest timestamp implies nonexistence", assertFalse("-1 dest timestamp implies nonexistence",
FILE_UTILS.isUpToDate(firstTime, -1L));
getFileUtils().isUpToDate(firstTime, -1L));
} }


@Test @Test
public void testHasErrorInCase() { public void testHasErrorInCase() {
File tempFolder = new File(System.getProperty("java.io.tmpdir")); File tempFolder = new File(System.getProperty("java.io.tmpdir"));
File wellcased = FILE_UTILS.createTempFile("alpha", "beta", tempFolder,
File wellcased = getFileUtils().createTempFile("alpha", "beta", tempFolder,
true, true); true, true);
String s = wellcased.getName().toUpperCase(); String s = wellcased.getName().toUpperCase();
File wrongcased = new File(tempFolder, s); File wrongcased = new File(tempFolder, s);
if (Os.isFamily("mac") && Os.isFamily("unix")) { if (Os.isFamily("mac") && Os.isFamily("unix")) {
//no guarantees on filesystem case-sensitivity //no guarantees on filesystem case-sensitivity
} else if (Os.isFamily("dos")) { } else if (Os.isFamily("dos")) {
assertTrue(FILE_UTILS.hasErrorInCase(wrongcased));
assertFalse(FILE_UTILS.hasErrorInCase(wellcased));
assertTrue(getFileUtils().hasErrorInCase(wrongcased));
assertFalse(getFileUtils().hasErrorInCase(wellcased));
} else { } else {
assertFalse(FILE_UTILS.hasErrorInCase(wrongcased));
assertFalse(FILE_UTILS.hasErrorInCase(wellcased));
assertFalse(getFileUtils().hasErrorInCase(wrongcased));
assertFalse(getFileUtils().hasErrorInCase(wellcased));
} }


} }
@@ -612,7 +604,7 @@ public class FileUtilsTest {
@Test @Test
public void testGetDefaultEncoding() { public void testGetDefaultEncoding() {
// This just tests that the function does not blow up // This just tests that the function does not blow up
FILE_UTILS.getDefaultEncoding();
getFileUtils().getDefaultEncoding();
} }


/** /**
@@ -620,9 +612,9 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void isLeadingPathCannotBeFooledByTooManyDoubleDots() { public void isLeadingPathCannotBeFooledByTooManyDoubleDots() {
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../../bar")));
assertFalse(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar")));
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../..")));
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../../bar")));
assertFalse(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar")));
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../..")));
} }


/** /**
@@ -630,61 +622,61 @@ public class FileUtilsTest {
*/ */
@Test @Test
public void isLeadingPathCanonicalVersionCannotBeFooledByTooManyDoubleDots() throws IOException { public void isLeadingPathCanonicalVersionCannotBeFooledByTooManyDoubleDots() throws IOException {
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../../bar"), true));
assertFalse(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar"), true));
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../.."), true));
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../../bar"), true));
assertFalse(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar"), true));
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../.."), true));
} }


@Test @Test
public void isLeadingPathCanonicalVersionWorksAsExpectedOnUnix() throws IOException { public void isLeadingPathCanonicalVersionWorksAsExpectedOnUnix() throws IOException {
assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); assumeFalse("Test doesn't run on DOS", Os.isFamily("dos"));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/bar"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/baz/../bar"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../foo/bar"), true));
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foobar"), true));
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/baz/../bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../foo/bar"), true));
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foobar"), true));
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/bar"), true));
} }


@Test @Test
public void isLeadingPathAndTrailingSlashesOnUnix() throws IOException { public void isLeadingPathAndTrailingSlashesOnUnix() throws IOException {
assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); assumeFalse("Test doesn't run on DOS", Os.isFamily("dos"));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar/"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar/"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo"), true));
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/"), true));


assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar/"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/"), false));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar"), false));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar/"), false));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/"), false));
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo"), false));
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/"), false));
} }


@Test @Test
public void isLeadingPathCanonicalVersionWorksAsExpectedOnDos() throws IOException { public void isLeadingPathCanonicalVersionWorksAsExpectedOnDos() throws IOException {
assumeTrue("Test only runs on DOS", Os.isFamily("dos")); assumeTrue("Test only runs on DOS", Os.isFamily("dos"));
assertTrue(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\bar"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\baz\\..\\bar"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\..\\foo\\bar"), true));
assertFalse(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foobar"), true));
assertFalse(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\baz\\..\\bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\..\\foo\\bar"), true));
assertFalse(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foobar"), true));
assertFalse(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\bar"), true));
} }


@Test @Test
public void isLeadingPathAndTrailingSlashesOnDos() throws IOException { public void isLeadingPathAndTrailingSlashesOnDos() throws IOException {
assumeTrue("Test only runs on DOS", Os.isFamily("dos")); assumeTrue("Test only runs on DOS", Os.isFamily("dos"));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), true));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), true));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), true));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), true));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), true));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), true));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), true));


assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), false));
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), false));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), false));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), false));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), false));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), false));
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), false));
} }


/** /**
@@ -707,17 +699,18 @@ public class FileUtilsTest {
final Boolean expectedCaseSensitivity = !existsAsLowerCase || !existsAsUpperCase; final Boolean expectedCaseSensitivity = !existsAsLowerCase || !existsAsUpperCase;


// call the method and pass it a directory // call the method and pass it a directory
Optional<Boolean> actualCaseSensitivity = FileUtils.isCaseSensitiveFileSystem(tmpDir);
Assert.assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent());
Assert.assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity
Optional<Boolean> actualCaseSensitivity = isCaseSensitiveFileSystem(tmpDir);
assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent());
assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity
? "sensitive" : "insensitive"), expectedCaseSensitivity, actualCaseSensitivity.get()); ? "sensitive" : "insensitive"), expectedCaseSensitivity, actualCaseSensitivity.get());


// now test it out by passing it a file // now test it out by passing it a file
actualCaseSensitivity = FileUtils.isCaseSensitiveFileSystem(tmpFile);
Assert.assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent());
Assert.assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity
actualCaseSensitivity = isCaseSensitiveFileSystem(tmpFile);
assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent());
assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity
? "sensitive" : "insensitive"), expectedCaseSensitivity, actualCaseSensitivity.get()); ? "sensitive" : "insensitive"), expectedCaseSensitivity, actualCaseSensitivity.get());
} }

/** /**
* adapt file separators to local conventions * adapt file separators to local conventions
*/ */


+ 21
- 34
src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java View File

@@ -26,8 +26,11 @@ import java.util.Properties;


import org.apache.tools.ant.MagicTestNames; import org.apache.tools.ant.MagicTestNames;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;


import static org.apache.tools.ant.util.FileUtils.readFully;
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.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
@@ -36,13 +39,19 @@ import static org.junit.Assert.assertThat;


public class LayoutPreservingPropertiesTest { public class LayoutPreservingPropertiesTest {


@Rule
public TemporaryFolder folder = new TemporaryFolder();

private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY); private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY);


private LayoutPreservingProperties lpf; private LayoutPreservingProperties lpf;


private File tmp;

@Before @Before
public void setUp() {
public void setUp() throws IOException {
lpf = new LayoutPreservingProperties(); lpf = new LayoutPreservingProperties();
tmp = folder.newFile("tmp.properties");
} }
/** /**
* Tests that a properties file read by the * Tests that a properties file read by the
@@ -55,8 +64,6 @@ public class LayoutPreservingPropertiesTest {
FileInputStream fis = new FileInputStream(simple); FileInputStream fis = new FileInputStream(simple);
lpf.load(fis); lpf.load(fis);


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// now compare original and tmp for property equivalence // now compare original and tmp for property equivalence
@@ -91,8 +98,6 @@ public class LayoutPreservingPropertiesTest {
lpf.setProperty("prop#nine", "contains#hash"); lpf.setProperty("prop#nine", "contains#hash");
lpf.setProperty("prop!ten", "contains!exclamation"); lpf.setProperty("prop!ten", "contains!exclamation");


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// and check that the resulting file looks okay // and check that the resulting file looks okay
@@ -124,8 +129,6 @@ public class LayoutPreservingPropertiesTest {
lpf.setProperty("prop\ttwo", "new two"); lpf.setProperty("prop\ttwo", "new two");
lpf.setProperty("prop\nthree", "new three"); lpf.setProperty("prop\nthree", "new three");


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// and check that the resulting file looks okay // and check that the resulting file looks okay
@@ -145,11 +148,9 @@ public class LayoutPreservingPropertiesTest {
FileInputStream fis = new FileInputStream(simple); FileInputStream fis = new FileInputStream(simple);
lpf.load(fis); lpf.load(fis);


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tmp);
lpf.store(fos, "file-header");
fos.close();
try (FileOutputStream fos = new FileOutputStream(tmp)) {
lpf.store(fos, "file-header");
}


// and check that the resulting file looks okay // and check that the resulting file looks okay
assertThat("should have had header ", readFile(tmp), startsWith("#file-header")); assertThat("should have had header ", readFile(tmp), startsWith("#file-header"));
@@ -163,8 +164,6 @@ public class LayoutPreservingPropertiesTest {


lpf.clear(); lpf.clear();


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// and check that the resulting file looks okay // and check that the resulting file looks okay
@@ -187,8 +186,6 @@ public class LayoutPreservingPropertiesTest {


lpf.remove("prop.beta"); lpf.remove("prop.beta");


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// and check that the resulting file looks okay // and check that the resulting file looks okay
@@ -208,8 +205,6 @@ public class LayoutPreservingPropertiesTest {


lpf.remove("prop.beta"); lpf.remove("prop.beta");


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// and check that the resulting file looks okay // and check that the resulting file looks okay
@@ -233,15 +228,12 @@ public class LayoutPreservingPropertiesTest {
assertEquals("size of original is wrong", 3, lpf.size()); assertEquals("size of original is wrong", 3, lpf.size());
assertEquals("size of clone is wrong", 4, lpfClone.size()); assertEquals("size of clone is wrong", 4, lpfClone.size());


File tmp1 = File.createTempFile("tmp", "props");
tmp1.deleteOnExit();
lpf.saveAs(tmp1);
String s1 = readFile(tmp1);
lpf.saveAs(tmp);
String s1 = readFile(tmp);


File tmp2 = File.createTempFile("tmp", "props");
tmp2.deleteOnExit();
lpfClone.saveAs(tmp2);
String s2 = readFile(tmp2);
File tmpClone = folder.newFile("tmp-clone.properties");
lpfClone.saveAs(tmpClone);
String s2 = readFile(tmpClone);


// check original is untouched // check original is untouched
assertThat("should have had 'simple'", s1, containsString(("simple"))); assertThat("should have had 'simple'", s1, containsString(("simple")));
@@ -265,8 +257,6 @@ public class LayoutPreservingPropertiesTest {
lpf.setProperty("alpha", "new value for alpha"); lpf.setProperty("alpha", "new value for alpha");
lpf.setProperty("beta", "new value for beta"); lpf.setProperty("beta", "new value for beta");


File tmp = File.createTempFile("tmp", "props");
tmp.deleteOnExit();
lpf.saveAs(tmp); lpf.saveAs(tmp);


// and check that the resulting file looks okay // and check that the resulting file looks okay
@@ -285,11 +275,8 @@ public class LayoutPreservingPropertiesTest {
} }


private static String readFile(File f) throws IOException { 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;
try (InputStreamReader isr = new InputStreamReader(new FileInputStream(f))) {
return readFully(isr);
}
} }
} }

+ 12
- 22
src/tests/junit/org/apache/tools/ant/util/PermissionUtilsTest.java View File

@@ -37,10 +37,15 @@ import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarOutputStream; import org.apache.tools.tar.TarOutputStream;
import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream; import org.apache.tools.zip.ZipOutputStream;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;


public class PermissionUtilsTest { public class PermissionUtilsTest {


@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Test @Test
public void modeFromPermissionsReturnsExpectedResult() { public void modeFromPermissionsReturnsExpectedResult() {
int mode = PermissionUtils.modeFromPermissions(EnumSet.of(PosixFilePermission.OWNER_READ, int mode = PermissionUtils.modeFromPermissions(EnumSet.of(PosixFilePermission.OWNER_READ,
@@ -65,44 +70,31 @@ public class PermissionUtilsTest {


@Test @Test
public void detectsFileTypeOfRegularFileFromPath() throws IOException { public void detectsFileTypeOfRegularFileFromPath() throws IOException {
File f = File.createTempFile("ant", ".tst");
f.deleteOnExit();
assertEquals(PermissionUtils.FileType.REGULAR_FILE, assertEquals(PermissionUtils.FileType.REGULAR_FILE,
PermissionUtils.FileType.of(f.toPath()));
PermissionUtils.FileType.of(folder.newFile("ant.tst").toPath()));
} }


@Test @Test
public void detectsFileTypeOfRegularFileFromResource() throws IOException { public void detectsFileTypeOfRegularFileFromResource() throws IOException {
File f = File.createTempFile("ant", ".tst");
f.deleteOnExit();
assertEquals(PermissionUtils.FileType.REGULAR_FILE, assertEquals(PermissionUtils.FileType.REGULAR_FILE,
PermissionUtils.FileType.of(new FileResource(f)));
PermissionUtils.FileType.of(new FileResource(folder.newFile("ant.tst"))));
} }


@Test @Test
public void detectsFileTypeOfDirectoryFromPath() throws IOException { public void detectsFileTypeOfDirectoryFromPath() throws IOException {
File f = File.createTempFile("ant", ".dir");
f.delete();
f.mkdirs();
f.deleteOnExit();
assertEquals(PermissionUtils.FileType.DIR, assertEquals(PermissionUtils.FileType.DIR,
PermissionUtils.FileType.of(f.toPath()));
PermissionUtils.FileType.of(folder.newFolder("ant.tst").toPath()));
} }


@Test @Test
public void detectsFileTypeOfDirectoryFromResource() throws IOException { public void detectsFileTypeOfDirectoryFromResource() throws IOException {
File f = File.createTempFile("ant", ".tst");
f.delete();
f.mkdirs();
f.deleteOnExit();
assertEquals(PermissionUtils.FileType.DIR, assertEquals(PermissionUtils.FileType.DIR,
PermissionUtils.FileType.of(new FileResource(f)));
PermissionUtils.FileType.of(new FileResource(folder.newFolder("ant.tst"))));
} }


@Test @Test
public void getSetPermissionsWorksForFiles() throws IOException { public void getSetPermissionsWorksForFiles() throws IOException {
File f = File.createTempFile("ant", ".tst");
f.deleteOnExit();
File f = folder.newFile("ant.tst");
assumeNotNull(Files.getFileAttributeView(f.toPath(), assumeNotNull(Files.getFileAttributeView(f.toPath(),
PosixFileAttributeView.class)); PosixFileAttributeView.class));
Set<PosixFilePermission> s = Set<PosixFilePermission> s =
@@ -116,8 +108,7 @@ public class PermissionUtilsTest {


@Test @Test
public void getSetPermissionsWorksForZipResources() throws IOException { public void getSetPermissionsWorksForZipResources() throws IOException {
File f = File.createTempFile("ant", ".zip");
f.deleteOnExit();
File f = folder.newFile("ant.zip");
try (ZipOutputStream os = new ZipOutputStream(f)) { try (ZipOutputStream os = new ZipOutputStream(f)) {
ZipEntry e = new ZipEntry("foo"); ZipEntry e = new ZipEntry("foo");
os.putNextEntry(e); os.putNextEntry(e);
@@ -138,8 +129,7 @@ public class PermissionUtilsTest {


@Test @Test
public void getSetPermissionsWorksForTarResources() throws IOException { public void getSetPermissionsWorksForTarResources() throws IOException {
File f = File.createTempFile("ant", ".zip");
f.deleteOnExit();
File f = folder.newFile("ant.tar");
try (TarOutputStream os = new TarOutputStream(new FileOutputStream(f))) { try (TarOutputStream os = new TarOutputStream(new FileOutputStream(f))) {
TarEntry e = new TarEntry("foo"); TarEntry e = new TarEntry("foo");
os.putNextEntry(e); os.putNextEntry(e);


Loading…
Cancel
Save