1 package be
.nikiroo
.utils
.test_code
;
4 import java
.io
.IOException
;
6 import be
.nikiroo
.utils
.TempFiles
;
7 import be
.nikiroo
.utils
.test
.TestCase
;
8 import be
.nikiroo
.utils
.test
.TestLauncher
;
10 class TempFilesTest
extends TestLauncher
{
11 public TempFilesTest(String
[] args
) {
12 super("TempFiles", args
);
14 addTest(new TestCase("Name is correct") {
16 public void test() throws Exception
{
17 RootTempFiles files
= new RootTempFiles("testy");
19 assertEquals("The root was not created", true, files
22 "The root is not prefixed with the expected name",
23 true, files
.getRoot().getName().startsWith("testy"));
31 addTest(new TestCase("Clean after itself no use") {
33 public void test() throws Exception
{
34 RootTempFiles files
= new RootTempFiles("testy2");
36 assertEquals("The root was not created", true, files
40 assertEquals("The root was not deleted", false, files
46 addTest(new TestCase("Clean after itself after usage") {
48 public void test() throws Exception
{
49 RootTempFiles files
= new RootTempFiles("testy3");
51 assertEquals("The root was not created", true, files
53 files
.createTempFile("test");
56 assertEquals("The root was not deleted", false, files
58 assertEquals("The main root in /tmp was not deleted",
59 false, files
.getRoot().getParentFile().exists());
64 addTest(new TestCase("Temporary directories") {
66 public void test() throws Exception
{
67 RootTempFiles files
= new RootTempFiles("testy4");
70 File dir
= files
.createTempDir("test");
71 file
= new File(dir
, "fanfan");
74 "Cannot create a file in a temporary directory",
80 "A file created in a temporary directory should be deleted on close",
81 false, file
.exists());
83 assertEquals("The root was not deleted", false, files
90 private class RootTempFiles
extends TempFiles
{
91 private File root
= null;
93 public RootTempFiles(String name
) throws IOException
{
97 public File
getRoot() {
104 public synchronized void close() throws IOException
{