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 TestRequireFilesDontExist
35 extends TestCase
36 {
37 RequireFilesDontExist rule = new RequireFilesDontExist();
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 try
48 {
49 rule.execute( EnforcerTestUtils.getHelper() );
50 fail( "Expected an Exception." );
51 }
52 catch ( EnforcerRuleException e )
53 {
54 assertTrue( true );
55 }
56 f.delete();
57 }
58
59 public void testEmptyFile()
60 throws EnforcerRuleException, IOException
61 {
62 rule.files = new File[] { null };
63 try
64 {
65 rule.execute( EnforcerTestUtils.getHelper() );
66 fail( "Should get exception" );
67 }
68 catch ( EnforcerRuleException e )
69 {
70 assertTrue( true );
71 }
72 }
73
74 public void testEmptyFileAllowNull()
75 throws EnforcerRuleException, IOException
76 {
77 rule.files = new File[] { null };
78 rule.allowNulls = true;
79 try
80 {
81 rule.execute( EnforcerTestUtils.getHelper() );
82 }
83 catch ( EnforcerRuleException e )
84 {
85 fail( "Unexpected Exception:" + e.getLocalizedMessage() );
86 }
87 }
88
89 public void testEmptyFileList()
90 throws EnforcerRuleException, IOException
91 {
92 rule.files = new File[] {};
93 assertEquals( 0, rule.files.length );
94 try
95 {
96 rule.execute( EnforcerTestUtils.getHelper() );
97 fail( "Should get exception" );
98 }
99 catch ( EnforcerRuleException e )
100 {
101 assertTrue( true );
102 }
103 }
104
105 public void testEmptyFileListAllowNull()
106 throws EnforcerRuleException, IOException
107 {
108 rule.files = new File[] {};
109 assertEquals( 0, rule.files.length );
110 rule.allowNulls = true;
111 try
112 {
113 rule.execute( EnforcerTestUtils.getHelper() );
114 }
115 catch ( EnforcerRuleException e )
116 {
117 fail( "Unexpected Exception:" + e.getLocalizedMessage() );
118 }
119 }
120
121 public void testFileDoesNotExist()
122 throws EnforcerRuleException, IOException
123 {
124 File f = File.createTempFile( "enforcer", "tmp" );
125 f.delete();
126
127 assertTrue( !f.exists() );
128
129 rule.files = new File[] { f };
130
131 rule.execute( EnforcerTestUtils.getHelper() );
132 }
133
134
135
136
137 public void testId()
138 {
139 rule.getCacheId();
140 }
141
142 }