KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > util > ValidationHelperTest


1 package net.sourceforge.cruisecontrol.util;
2
3 import junit.framework.TestCase;
4 import net.sourceforge.cruisecontrol.CruiseControlException;
5 import net.sourceforge.cruisecontrol.testutil.UnreadableMockFile;
6 import java.io.File JavaDoc;
7 import java.io.IOException JavaDoc;
8
9 public class ValidationHelperTest extends TestCase {
10     public void testExists() throws IOException JavaDoc, CruiseControlException {
11         try {
12             ValidationHelper.assertExists(new File("THISFILEDOESNTEXIST" + System.currentTimeMillis()), "file",
13                     this.getClass());
14             fail("Exception expected");
15         } catch (CruiseControlException expected) {
16         }
17
18         final File tempFile = File.createTempFile(ValidationHelperTest.class.getName(), "temp");
19         tempFile.deleteOnExit();
20         ValidationHelper.assertExists(tempFile, "file", this.getClass());
21     }
22
23     public void testExistsWithInvalidArguments() throws CruiseControlException {
24         try {
25             ValidationHelper
26                     .assertExists(new File("THISFILEDOESNTEXIST" + System.currentTimeMillis()), null, this.getClass());
27             fail("Expected an exception");
28         } catch (IllegalArgumentException JavaDoc expected) {
29         }
30
31
32         try {
33             ValidationHelper.assertExists(new File("THISFILEDOESNTEXIST" + System.currentTimeMillis()), "foo", null);
34             fail("Expected an exception");
35         } catch (IllegalArgumentException JavaDoc expected) {
36         }
37
38         try {
39             ValidationHelper.assertExists(new File("THISFILEDOESNTEXIST" + System.currentTimeMillis()), null, null);
40             fail("Expected an exception");
41         } catch (IllegalArgumentException JavaDoc expected) {
42         }
43
44         try {
45             ValidationHelper.assertExists(null, "foo", this.getClass());
46             fail("Expected an exception");
47         } catch (IllegalArgumentException JavaDoc expected) {
48         }
49
50         try {
51             ValidationHelper.assertExists(null, null, null);
52             fail("Expected an exception");
53         } catch (IllegalArgumentException JavaDoc expected) {
54         }
55     }
56
57     public void testIsNotDirectory() throws CruiseControlException {
58         try {
59             ValidationHelper
60                     .assertIsNotDirectory(new File(System.getProperty("java.io.tmpdir")), "foo", this.getClass());
61             fail("Expected an exception");
62         } catch (CruiseControlException expected) {
63         }
64
65         ValidationHelper.assertIsNotDirectory(new File("foo"), "bar", this.getClass());
66     }
67
68     public void testIsReadable() throws CruiseControlException, IOException JavaDoc {
69         try {
70             //A file that exists, but isn't readable
71
UnreadableMockFile unreadableFile = new UnreadableMockFile();
72             ValidationHelper.assertIsReadable(unreadableFile, "foo", this.getClass());
73             fail("Expected an exception");
74         } catch (CruiseControlException expected) {
75         }
76
77         final File tempFile = File.createTempFile(ValidationHelperTest.class.getName(), "temp");
78         tempFile.deleteOnExit();
79         ValidationHelper.assertIsReadable(tempFile, "bar", this.getClass());
80     }
81 }
82
Popular Tags