1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.jomc.tools.test;
32
33 import java.io.File;
34 import java.io.IOException;
35 import org.jomc.model.Implementation;
36 import org.jomc.model.Module;
37 import org.jomc.model.Specification;
38 import org.jomc.tools.ResourceFileProcessor;
39 import org.junit.Test;
40 import static org.junit.Assert.assertNotNull;
41 import static org.junit.Assert.assertTrue;
42 import static org.junit.Assert.fail;
43
44
45
46
47
48
49
50 public class ResourceFileProcessorTest extends JomcToolTest
51 {
52
53
54 public ResourceFileProcessorTest()
55 {
56 super();
57 }
58
59
60 @Override
61 public ResourceFileProcessor getJomcTool()
62 {
63 return (ResourceFileProcessor) super.getJomcTool();
64 }
65
66
67 @Override
68 protected ResourceFileProcessor newJomcTool()
69 {
70 return new ResourceFileProcessor();
71 }
72
73 @Test
74 public final void testResourceFileProcessorNullPointerException() throws Exception
75 {
76 try
77 {
78 this.getJomcTool().getResourceBundleResources( (Specification) null );
79 fail( "Expected NullPointerException not thrown." );
80 }
81 catch ( final NullPointerException e )
82 {
83 assertNullPointerException( e );
84 }
85
86 try
87 {
88 this.getJomcTool().getResourceBundleResources( (Implementation) null );
89 fail( "Expected NullPointerException not thrown." );
90 }
91 catch ( final NullPointerException e )
92 {
93 assertNullPointerException( e );
94 }
95
96 try
97 {
98 this.getJomcTool().writeResourceBundleResourceFiles( null );
99 fail( "Expected NullPointerException not thrown." );
100 }
101 catch ( final NullPointerException e )
102 {
103 assertNullPointerException( e );
104 }
105
106 try
107 {
108 this.getJomcTool().writeResourceBundleResourceFiles( (Module) null, new File( "/" ) );
109 fail( "Expected NullPointerException not thrown." );
110 }
111 catch ( final NullPointerException e )
112 {
113 assertNullPointerException( e );
114 }
115
116 try
117 {
118 this.getJomcTool().writeResourceBundleResourceFiles( new Module(), null );
119 fail( "Expected NullPointerException not thrown." );
120 }
121 catch ( final NullPointerException e )
122 {
123 assertNullPointerException( e );
124 }
125
126 try
127 {
128 this.getJomcTool().writeResourceBundleResourceFiles( (Specification) null, new File( "/" ) );
129 fail( "Expected NullPointerException not thrown." );
130 }
131 catch ( final NullPointerException e )
132 {
133 assertNullPointerException( e );
134 }
135
136 try
137 {
138 this.getJomcTool().writeResourceBundleResourceFiles( new Specification(), null );
139 fail( "Expected NullPointerException not thrown." );
140 }
141 catch ( final NullPointerException e )
142 {
143 assertNullPointerException( e );
144 }
145
146 try
147 {
148 this.getJomcTool().writeResourceBundleResourceFiles( (Implementation) null, new File( "/" ) );
149 fail( "Expected NullPointerException not thrown." );
150 }
151 catch ( final NullPointerException e )
152 {
153 assertNullPointerException( e );
154 }
155
156 try
157 {
158 this.getJomcTool().writeResourceBundleResourceFiles( new Implementation(), null );
159 fail( "Expected NullPointerException not thrown." );
160 }
161 catch ( final NullPointerException e )
162 {
163 assertNullPointerException( e );
164 }
165 }
166
167 @Test
168 public final void testResourceFileProcessorNotNull() throws Exception
169 {
170 assertNotNull( this.getJomcTool().getResourceBundleDefaultLocale() );
171 assertNotNull( this.getJomcTool().getResourceBundleResources(
172 this.getJomcTool().getModules().getSpecification( "Specification" ) ) );
173
174 assertNotNull( this.getJomcTool().getResourceBundleResources(
175 this.getJomcTool().getModules().getImplementation( "Implementation" ) ) );
176
177 }
178
179 @Test
180 public final void testResourceBundleDefaultLocale() throws Exception
181 {
182 this.getJomcTool().setResourceBundleDefaultLocale( null );
183 assertNotNull( this.getJomcTool().getResourceBundleDefaultLocale() );
184 this.getJomcTool().setResourceBundleDefaultLocale( null );
185 }
186
187 @Test
188 public final void testWriteResourceBundleResourceFiles() throws Exception
189 {
190 final File nonExistentDirectory = this.getNextOutputDirectory();
191
192 try
193 {
194 this.getJomcTool().writeResourceBundleResourceFiles( nonExistentDirectory );
195 fail( "Expected IOException not thrown." );
196 }
197 catch ( final IOException e )
198 {
199 assertNotNull( e.getMessage() );
200 System.out.println( e );
201 }
202
203 try
204 {
205 this.getJomcTool().writeResourceBundleResourceFiles(
206 this.getJomcTool().getModules().getModule( "Module" ), nonExistentDirectory );
207
208 fail( "Expected IOException not thrown." );
209 }
210 catch ( final IOException e )
211 {
212 assertNotNull( e.getMessage() );
213 System.out.println( e );
214 }
215
216 try
217 {
218 this.getJomcTool().writeResourceBundleResourceFiles(
219 this.getJomcTool().getModules().getSpecification( "Specification" ), nonExistentDirectory );
220
221 fail( "Expected IOException not thrown." );
222 }
223 catch ( final IOException e )
224 {
225 assertNotNull( e.getMessage() );
226 System.out.println( e );
227 }
228
229 try
230 {
231 this.getJomcTool().writeResourceBundleResourceFiles(
232 this.getJomcTool().getModules().getImplementation( "Implementation" ), nonExistentDirectory );
233
234 fail( "Expected IOException not thrown." );
235 }
236 catch ( final IOException e )
237 {
238 assertNotNull( e.getMessage() );
239 System.out.println( e );
240 }
241
242 File resourcesDirectory = this.getNextOutputDirectory();
243 assertTrue( resourcesDirectory.mkdirs() );
244 this.getJomcTool().writeResourceBundleResourceFiles( resourcesDirectory );
245
246 resourcesDirectory = this.getNextOutputDirectory();
247 assertTrue( resourcesDirectory.mkdirs() );
248 this.getJomcTool().writeResourceBundleResourceFiles(
249 this.getJomcTool().getModules().getModule( "Module" ), resourcesDirectory );
250
251 resourcesDirectory = this.getNextOutputDirectory();
252 assertTrue( resourcesDirectory.mkdirs() );
253 this.getJomcTool().writeResourceBundleResourceFiles(
254 this.getJomcTool().getModules().getSpecification( "Specification" ), resourcesDirectory );
255
256 resourcesDirectory = this.getNextOutputDirectory();
257 assertTrue( resourcesDirectory.mkdirs() );
258 this.getJomcTool().writeResourceBundleResourceFiles(
259 this.getJomcTool().getModules().getImplementation( "Implementation" ), resourcesDirectory );
260
261 }
262
263 @Test
264 public final void testCopyConstructor() throws Exception
265 {
266 try
267 {
268 new ResourceFileProcessor( null );
269 fail( "Expected NullPointerException not thrown." );
270 }
271 catch ( final NullPointerException e )
272 {
273 assertNotNull( e.getMessage() );
274 System.out.println( e.toString() );
275 }
276
277 new ResourceFileProcessor( this.getJomcTool() );
278 }
279
280 }