|
50 | 50 | import static org.junit.Assert.assertEquals; |
51 | 51 | import static org.junit.Assert.assertFalse; |
52 | 52 | import static org.junit.Assert.assertNotEquals; |
| 53 | +import static org.junit.Assert.assertNotNull; |
| 54 | +import static org.junit.Assert.assertNull; |
53 | 55 | import static org.junit.Assert.assertThat; |
54 | 56 | import static org.junit.Assert.assertTrue; |
55 | 57 | import static org.junit.Assume.assumeFalse; |
@@ -450,6 +452,68 @@ public void testCreateTempFile() throws IOException { |
450 | 452 | tmp2.getAbsolutePath())); |
451 | 453 | } |
452 | 454 |
|
| 455 | + @Test |
| 456 | + public void createTempFileUsesAntTmpDirIfSetAndDeleteOnExitIsTrue() throws IOException { |
| 457 | + final Project project = new Project(); |
| 458 | + final File projectTmpDir = folder.newFolder("subdir"); |
| 459 | + project.setProperty("ant.tmpdir", projectTmpDir.getAbsolutePath()); |
| 460 | + final File tmpFile = getFileUtils().createTempFile(project, null, null, null, true, true); |
| 461 | + assertTrue(tmpFile + " must be child of " + projectTmpDir, |
| 462 | + tmpFile.getAbsolutePath().startsWith(projectTmpDir.getAbsolutePath())); |
| 463 | + } |
| 464 | + |
| 465 | + @Test |
| 466 | + public void createTempFileUsesAntTmpDirIfSetAndDeleteOnExitIsFalse() throws IOException { |
| 467 | + final Project project = new Project(); |
| 468 | + final File projectTmpDir = folder.newFolder("subdir"); |
| 469 | + project.setProperty("ant.tmpdir", projectTmpDir.getAbsolutePath()); |
| 470 | + final File tmpFile = getFileUtils().createTempFile(project, null, null, null, false, true); |
| 471 | + assertTrue(tmpFile + " must be child of " + projectTmpDir, |
| 472 | + tmpFile.getAbsolutePath().startsWith(projectTmpDir.getAbsolutePath())); |
| 473 | + } |
| 474 | + |
| 475 | + @Test |
| 476 | + public void createTempFileCreatesAutoTmpDirIfDeleteOnExitIsTrueOnUnix() throws IOException { |
| 477 | + assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); |
| 478 | + final Project project = new Project(); |
| 479 | + final File tmpFile = getFileUtils().createTempFile(project, null, null, null, true, true); |
| 480 | + final String autoTempDir = project.getProperty("ant.auto.tmpdir"); |
| 481 | + assertNotNull(autoTempDir); |
| 482 | + assertTrue(tmpFile + " must be child of " + autoTempDir, |
| 483 | + tmpFile.getAbsolutePath().startsWith(autoTempDir)); |
| 484 | + } |
| 485 | + |
| 486 | + @Test |
| 487 | + public void createTempFileDoesntCreateAutoTmpDirIfDeleteOnExitIsFalse() throws IOException { |
| 488 | + final Project project = new Project(); |
| 489 | + final File tmpFile = getFileUtils().createTempFile(project, null, null, null, false, true); |
| 490 | + assertNull(project.getProperty("ant.auto.tmpdir")); |
| 491 | + } |
| 492 | + |
| 493 | + @Test |
| 494 | + public void createTempFileReusesAutoTmpDirIfDeleteOnExitIsTrueOnUnix() throws IOException { |
| 495 | + assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); |
| 496 | + final Project project = new Project(); |
| 497 | + final File tmpFile = getFileUtils().createTempFile(project, null, null, null, true, true); |
| 498 | + final String autoTempDir = project.getProperty("ant.auto.tmpdir"); |
| 499 | + assertNotNull(autoTempDir); |
| 500 | + final File tmpFile2 = getFileUtils().createTempFile(project, null, null, null, true, true); |
| 501 | + assertTrue(tmpFile2 + " must be child of " + autoTempDir, |
| 502 | + tmpFile2.getAbsolutePath().startsWith(autoTempDir)); |
| 503 | + } |
| 504 | + |
| 505 | + @Test |
| 506 | + public void createTempFileDoesntReusesAutoTmpDirIfDeleteOnExitIsFalse() throws IOException { |
| 507 | + assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); |
| 508 | + final Project project = new Project(); |
| 509 | + final File tmpFile = getFileUtils().createTempFile(project, null, null, null, true, true); |
| 510 | + final String autoTempDir = project.getProperty("ant.auto.tmpdir"); |
| 511 | + assertNotNull(autoTempDir); |
| 512 | + final File tmpFile2 = getFileUtils().createTempFile(project, null, null, null, false, true); |
| 513 | + assertFalse(tmpFile2 + " must not be child of " + autoTempDir, |
| 514 | + tmpFile2.getAbsolutePath().startsWith(autoTempDir)); |
| 515 | + } |
| 516 | + |
453 | 517 | /** |
454 | 518 | * Test contentEquals |
455 | 519 | */ |
|
0 commit comments