1 package org.apache.maven.plugins.enforcer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
26
27 import junit.framework.TestCase;
28
29
30
31
32
33
34 public class TestRequireFilesExist
35 extends TestCase
36 {
37 RequireFilesExist rule = new RequireFilesExist();
38
39 public void testFileExists()
40 throws EnforcerRuleException, IOException
41 {
42 File f = File.createTempFile( "enforcer", "tmp" );
43 f.deleteOnExit();
44
45 rule.files = new File[] { f };
46
47 rule.execute( EnforcerTestUtils.getHelper() );
48
49 f.delete();
50 }
51
52 public void testEmptyFile()
53 throws EnforcerRuleException, IOException
54 {
55 rule.files = new File[] { null };
56 try
57 {
58 rule.execute( EnforcerTestUtils.getHelper() );
59 fail( "Should get exception" );
60 }
61 catch ( EnforcerRuleException e )
62 {
63 assertTrue( true );
64 }
65 }
66
67 public void testEmptyFileAllowNull()
68 throws EnforcerRuleException, IOException
69 {
70 rule.files = new File[] { null };
71 rule.allowNulls = true;
72 try
73 {
74 rule.execute( EnforcerTestUtils.getHelper() );
75 }
76 catch ( EnforcerRuleException e )
77 {
78 fail( "Unexpected Exception:" + e.getLocalizedMessage() );
79 }
80 }
81
82 public void testEmptyFileList()
83 throws EnforcerRuleException, IOException
84 {
85 rule.files = new File[] {};
86 assertEquals(0,rule.files.length);
87 try
88 {
89 rule.execute( EnforcerTestUtils.getHelper() );
90 fail( "Should get exception" );
91 }
92 catch ( EnforcerRuleException e )
93 {
94 assertTrue( true );
95 }
96 }
97
98 public void testEmptyFileListAllowNull()
99 throws EnforcerRuleException, IOException
100 {
101 rule.files = new File[] {};
102 assertEquals(0,rule.files.length);
103 rule.allowNulls = true;
104 try
105 {
106 rule.execute( EnforcerTestUtils.getHelper() );
107 }
108 catch ( EnforcerRuleException e )
109 {
110 fail( "Unexpected Exception:" + e.getLocalizedMessage() );
111 }
112 }
113
114 public void testFileDoesNotExist()
115 throws EnforcerRuleException, IOException
116 {
117 File f = File.createTempFile( "enforcer", "tmp" );
118 f.delete();
119 assertTrue(!f.exists());
120 rule.files = new File[] { f };
121
122 try
123 {
124 rule.execute( EnforcerTestUtils.getHelper() );
125 fail( "Should get exception" );
126 }
127 catch ( EnforcerRuleException e )
128 {
129 assertTrue( true );
130 }
131 }
132
133
134
135
136 public void testId()
137 {
138 rule.getCacheId();
139 }
140
141 }