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.modlet.Model;
39 import org.jomc.tools.ResourceFileProcessor;
40 import org.junit.Test;
41 import static org.junit.Assert.assertNotNull;
42 import static org.junit.Assert.assertNull;
43 import static org.junit.Assert.assertTrue;
44 import static org.junit.Assert.fail;
45
46
47
48
49
50
51
52 public class ResourceFileProcessorTest extends JomcToolTest
53 {
54
55
56 public ResourceFileProcessorTest()
57 {
58 super();
59 }
60
61
62 @Override
63 public ResourceFileProcessor getJomcTool()
64 {
65 return (ResourceFileProcessor) super.getJomcTool();
66 }
67
68
69 @Override
70 protected ResourceFileProcessor newJomcTool()
71 {
72 return new ResourceFileProcessor();
73 }
74
75 @Test
76 public final void testResourceFileProcessorNullPointerException() throws Exception
77 {
78 try
79 {
80 this.getJomcTool().getResourceBundleResources( (Specification) null );
81 fail( "Expected NullPointerException not thrown." );
82 }
83 catch ( final NullPointerException e )
84 {
85 assertNullPointerException( e );
86 }
87
88 try
89 {
90 this.getJomcTool().getResourceBundleResources( (Implementation) null );
91 fail( "Expected NullPointerException not thrown." );
92 }
93 catch ( final NullPointerException e )
94 {
95 assertNullPointerException( e );
96 }
97
98 try
99 {
100 this.getJomcTool().writeResourceBundleResourceFiles( null );
101 fail( "Expected NullPointerException not thrown." );
102 }
103 catch ( final NullPointerException e )
104 {
105 assertNullPointerException( e );
106 }
107
108 try
109 {
110 this.getJomcTool().writeResourceBundleResourceFiles( (Module) null, new File( "/" ) );
111 fail( "Expected NullPointerException not thrown." );
112 }
113 catch ( final NullPointerException e )
114 {
115 assertNullPointerException( e );
116 }
117
118 try
119 {
120 this.getJomcTool().writeResourceBundleResourceFiles( new Module(), null );
121 fail( "Expected NullPointerException not thrown." );
122 }
123 catch ( final NullPointerException e )
124 {
125 assertNullPointerException( e );
126 }
127
128 try
129 {
130 this.getJomcTool().writeResourceBundleResourceFiles( (Specification) null, new File( "/" ) );
131 fail( "Expected NullPointerException not thrown." );
132 }
133 catch ( final NullPointerException e )
134 {
135 assertNullPointerException( e );
136 }
137
138 try
139 {
140 this.getJomcTool().writeResourceBundleResourceFiles( new Specification(), null );
141 fail( "Expected NullPointerException not thrown." );
142 }
143 catch ( final NullPointerException e )
144 {
145 assertNullPointerException( e );
146 }
147
148 try
149 {
150 this.getJomcTool().writeResourceBundleResourceFiles( (Implementation) null, new File( "/" ) );
151 fail( "Expected NullPointerException not thrown." );
152 }
153 catch ( final NullPointerException e )
154 {
155 assertNullPointerException( e );
156 }
157
158 try
159 {
160 this.getJomcTool().writeResourceBundleResourceFiles( new Implementation(), null );
161 fail( "Expected NullPointerException not thrown." );
162 }
163 catch ( final NullPointerException e )
164 {
165 assertNullPointerException( e );
166 }
167 }
168
169 @Test
170 public final void testResourceFileProcessorNotNull() throws Exception
171 {
172 assertNotNull( this.getJomcTool().getResourceBundleDefaultLocale() );
173 assertNotNull( this.getJomcTool().getResourceBundleResources(
174 this.getJomcTool().getModules().getSpecification( "Specification" ) ) );
175
176 assertNotNull( this.getJomcTool().getResourceBundleResources(
177 this.getJomcTool().getModules().getImplementation( "Implementation" ) ) );
178
179 }
180
181 @Test
182 public final void testResourceBundleDefaultLocale() throws Exception
183 {
184 this.getJomcTool().setResourceBundleDefaultLocale( null );
185 assertNotNull( this.getJomcTool().getResourceBundleDefaultLocale() );
186 this.getJomcTool().setResourceBundleDefaultLocale( null );
187 }
188
189 @Test
190 public final void testWriteResourceBundleResourceFiles() throws Exception
191 {
192 final File nonExistentDirectory = this.getNextOutputDirectory();
193
194 try
195 {
196 this.getJomcTool().writeResourceBundleResourceFiles( nonExistentDirectory );
197 fail( "Expected IOException not thrown." );
198 }
199 catch ( final IOException e )
200 {
201 assertNotNull( e.getMessage() );
202 System.out.println( e );
203 }
204
205 try
206 {
207 this.getJomcTool().writeResourceBundleResourceFiles(
208 this.getJomcTool().getModules().getModule( "Module" ), nonExistentDirectory );
209
210 fail( "Expected IOException not thrown." );
211 }
212 catch ( final IOException e )
213 {
214 assertNotNull( e.getMessage() );
215 System.out.println( e );
216 }
217
218 try
219 {
220 this.getJomcTool().writeResourceBundleResourceFiles(
221 this.getJomcTool().getModules().getSpecification( "Specification" ), nonExistentDirectory );
222
223 fail( "Expected IOException not thrown." );
224 }
225 catch ( final IOException e )
226 {
227 assertNotNull( e.getMessage() );
228 System.out.println( e );
229 }
230
231 try
232 {
233 this.getJomcTool().writeResourceBundleResourceFiles(
234 this.getJomcTool().getModules().getImplementation( "Implementation" ), nonExistentDirectory );
235
236 fail( "Expected IOException not thrown." );
237 }
238 catch ( final IOException e )
239 {
240 assertNotNull( e.getMessage() );
241 System.out.println( e );
242 }
243
244 File resourcesDirectory = this.getNextOutputDirectory();
245 assertTrue( resourcesDirectory.mkdirs() );
246 this.getJomcTool().writeResourceBundleResourceFiles( resourcesDirectory );
247
248 resourcesDirectory = this.getNextOutputDirectory();
249 assertTrue( resourcesDirectory.mkdirs() );
250 this.getJomcTool().writeResourceBundleResourceFiles(
251 this.getJomcTool().getModules().getModule( "Module" ), resourcesDirectory );
252
253 resourcesDirectory = this.getNextOutputDirectory();
254 assertTrue( resourcesDirectory.mkdirs() );
255 this.getJomcTool().writeResourceBundleResourceFiles(
256 this.getJomcTool().getModules().getSpecification( "Specification" ), resourcesDirectory );
257
258 resourcesDirectory = this.getNextOutputDirectory();
259 assertTrue( resourcesDirectory.mkdirs() );
260 this.getJomcTool().writeResourceBundleResourceFiles(
261 this.getJomcTool().getModules().getImplementation( "Implementation" ), resourcesDirectory );
262
263 }
264
265 @Test
266 public final void testCopyConstructor() throws Exception
267 {
268 try
269 {
270 new ResourceFileProcessor( null );
271 fail( "Expected NullPointerException not thrown." );
272 }
273 catch ( final NullPointerException e )
274 {
275 assertNotNull( e.getMessage() );
276 System.out.println( e.toString() );
277 }
278
279 new ResourceFileProcessor( this.getJomcTool() );
280 }
281
282 @Test
283 public final void testResourceFileProcessorModelObjectsNotFound() throws Exception
284 {
285 final File tmpDir = new File( System.getProperty( "java.io.tmpdir", "/tmp" ) );
286 final Module m = new Module();
287 m.setName( "DOES_NOT_EXIST" );
288
289 final Specification s = new Specification();
290 s.setIdentifier( "DOES_NOT_EXIST)" );
291
292 final Implementation i = new Implementation();
293 i.setIdentifier( "DOES_NOT_EXIST" );
294
295 final Model oldModel = this.getJomcTool().getModel();
296 this.getJomcTool().setModel( null );
297
298 assertNull( this.getJomcTool().getResourceBundleResources( i ) );
299 assertNull( this.getJomcTool().getResourceBundleResources( s ) );
300
301 this.getJomcTool().writeResourceBundleResourceFiles( tmpDir );
302 this.getJomcTool().writeResourceBundleResourceFiles( m, tmpDir );
303 this.getJomcTool().writeResourceBundleResourceFiles( s, tmpDir );
304 this.getJomcTool().writeResourceBundleResourceFiles( i, tmpDir );
305
306 this.getJomcTool().setModel( oldModel );
307 }
308
309 }