diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-07-23 19:31:58 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-07-23 19:31:58 +0200 |
commit | f3ce19d1c5be34575adeaed0cf991a609ac8a10f (patch) | |
tree | 9c6d7b768de815986591b2efd47eb62ebc8fb0fd /test/eu/equalparts/cardbase/testutils | |
parent | f3b507240930f721571c9da1b4985a02e0a17b6b (diff) |
Reorganised the test folder a bit more, started working on CLI tests, a bit tricky, will require refactoring
Diffstat (limited to 'test/eu/equalparts/cardbase/testutils')
-rw-r--r-- | test/eu/equalparts/cardbase/testutils/TestFile.java | 23 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/testutils/TestUtils.java | 24 |
2 files changed, 47 insertions, 0 deletions
diff --git a/test/eu/equalparts/cardbase/testutils/TestFile.java b/test/eu/equalparts/cardbase/testutils/TestFile.java new file mode 100644 index 0000000..ac666a9 --- /dev/null +++ b/test/eu/equalparts/cardbase/testutils/TestFile.java @@ -0,0 +1,23 @@ +package eu.equalparts.cardbase.testutils; + +import java.io.File; + +public class TestFile extends File implements AutoCloseable { + + /** + * + */ + private static final long serialVersionUID = 3716372675161543906L; + + public TestFile(String pathname) { + super(pathname); + } + + @Override + public void close() throws Exception { + delete(); + } + + + +} diff --git a/test/eu/equalparts/cardbase/testutils/TestUtils.java b/test/eu/equalparts/cardbase/testutils/TestUtils.java new file mode 100644 index 0000000..ba590c8 --- /dev/null +++ b/test/eu/equalparts/cardbase/testutils/TestUtils.java @@ -0,0 +1,24 @@ +package eu.equalparts.cardbase.testutils; + +public class TestUtils { + + public static TestFile createValidTestFile(String fileName) throws Exception { + TestFile testFile = new TestFile(fileName); + if (!testFile.exists()) { + if (testFile.createNewFile()) { + if (testFile.canWrite()) { + return testFile; + } else { + throw new IllegalArgumentException("Cannot write to " + testFile.getAbsolutePath() + ", aborting..."); + } + } else { + throw new IllegalArgumentException(testFile.getAbsolutePath() + " could not be created, aborting..."); + } + } else { + throw new IllegalArgumentException(testFile.getAbsolutePath() + " already exists, aborting..."); + } + } + + + +} |