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
32
33
34
35
36 package org.jomc.ri.test;
37
38 import java.net.URI;
39 import java.util.Locale;
40 import org.jomc.ObjectManager;
41 import org.jomc.model.Instance;
42 import org.jomc.model.Modules;
43 import org.jomc.ri.DefaultObjectManager;
44 import org.jomc.ri.test.support.TestScopeSpecification;
45 import org.jomc.ri.test.support.TestSpecification;
46 import org.jomc.ri.test.support.TestSpecificationMany;
47 import org.jomc.ri.test.support.TestSpecificationOne;
48 import org.jomc.ri.test.support.TestSpecificationOneMore;
49 import org.jomc.spi.Scope;
50 import org.junit.Test;
51 import static org.junit.Assert.assertNotNull;
52 import static org.junit.Assert.assertNull;
53 import static org.junit.Assert.assertTrue;
54 import static org.junit.Assert.fail;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" )
77
78
79 public class DefaultObjectManagerTest
80 {
81
82
83
84 private DefaultObjectManager objectManager;
85
86
87
88
89
90
91
92
93 public DefaultObjectManager getObjectManager()
94 {
95 if ( this.objectManager == null )
96 {
97 this.objectManager = this.newObjectManager();
98 }
99
100 return this.objectManager;
101 }
102
103
104
105
106
107
108
109
110 protected DefaultObjectManager newObjectManager()
111 {
112 return new DefaultObjectManager();
113 }
114
115 @Test
116 @SuppressWarnings( "deprecation" )
117 public final void testNullPointerException() throws Exception
118 {
119 try
120 {
121 DefaultObjectManager.getClassLoader( (Class) null );
122 fail( "Expected NullPointerException not thrown." );
123 }
124 catch ( final NullPointerException e )
125 {
126 assertNullPointerException( e );
127 }
128
129 try
130 {
131 this.getObjectManager().getDefaultClassLoader( (Class<?>) null );
132 fail( "Expected NullPointerException not thrown." );
133 }
134 catch ( final NullPointerException e )
135 {
136 assertNullPointerException( e );
137 }
138
139 try
140 {
141 this.getObjectManager().getDefaultLocator( null );
142 fail( "Expected NullPointerException not thrown." );
143 }
144 catch ( final NullPointerException e )
145 {
146 assertNullPointerException( e );
147 }
148 try
149 {
150 this.getObjectManager().getDefaultLocator( null, new URI( "file:///tmp" ) );
151 fail( "Expected NullPointerException not thrown." );
152 }
153 catch ( final NullPointerException e )
154 {
155 assertNullPointerException( e );
156 }
157
158 try
159 {
160 this.getObjectManager().getDefaultScope( null );
161 fail( "Expected NullPointerException not thrown." );
162 }
163 catch ( final NullPointerException e )
164 {
165 assertNullPointerException( e );
166 }
167 try
168 {
169 this.getObjectManager().getDefaultScope( new Modules(), null );
170 fail( "Expected NullPointerException not thrown." );
171 }
172 catch ( final NullPointerException e )
173 {
174 assertNullPointerException( e );
175 }
176 try
177 {
178 this.getObjectManager().getDefaultScope( null, "Singleton" );
179 fail( "Expected NullPointerException not thrown." );
180 }
181 catch ( final NullPointerException e )
182 {
183 assertNullPointerException( e );
184 }
185
186 try
187 {
188 this.getObjectManager().getDependency( null, null );
189 fail( "Expected NullPointerException not thrown." );
190 }
191 catch ( final NullPointerException e )
192 {
193 assertNullPointerException( e );
194 }
195
196 try
197 {
198 this.getObjectManager().getDependency( this, null );
199 fail( "Expected NullPointerException not thrown." );
200 }
201 catch ( final NullPointerException e )
202 {
203 assertNullPointerException( e );
204 }
205
206 try
207 {
208 this.getObjectManager().getLocator( null, null );
209 fail( "Expected NullPointerException not thrown." );
210 }
211 catch ( final NullPointerException e )
212 {
213 assertNullPointerException( e );
214 }
215
216 try
217 {
218 this.getObjectManager().getLocator( new URI( "TEST" ), null );
219 fail( "Expected NullPointerException not thrown." );
220 }
221 catch ( final NullPointerException e )
222 {
223 assertNullPointerException( e );
224 }
225
226 try
227 {
228 this.getObjectManager().getLocator( null, this.getClass().getClassLoader() );
229 fail( "Expected NullPointerException not thrown." );
230 }
231 catch ( final NullPointerException e )
232 {
233 assertNullPointerException( e );
234 }
235
236 try
237 {
238 this.getObjectManager().getMessage( null, null, null );
239 fail( "Expected NullPointerException not thrown." );
240 }
241 catch ( final NullPointerException e )
242 {
243 assertNullPointerException( e );
244 }
245
246 try
247 {
248 this.getObjectManager().getMessage( this, null, null );
249 fail( "Expected NullPointerException not thrown." );
250 }
251 catch ( final NullPointerException e )
252 {
253 assertNullPointerException( e );
254 }
255
256 try
257 {
258 this.getObjectManager().getMessage( this, "", null );
259 fail( "Expected NullPointerException not thrown." );
260 }
261 catch ( final NullPointerException e )
262 {
263 assertNullPointerException( e );
264 }
265
266 try
267 {
268 this.getObjectManager().getObject( null );
269 fail( "Expected NullPointerException not thrown." );
270 }
271 catch ( final NullPointerException e )
272 {
273 assertNullPointerException( e );
274 }
275
276 try
277 {
278 this.getObjectManager().getObject( (Scope) null, (Instance) null, null );
279 fail( "Expected NullPointerException not thrown." );
280 }
281 catch ( final NullPointerException e )
282 {
283 assertNullPointerException( e );
284 }
285
286 try
287 {
288 this.getObjectManager().getObject( (Scope) null, new Instance(), null );
289 fail( "Expected NullPointerException not thrown." );
290 }
291 catch ( final NullPointerException e )
292 {
293 assertNullPointerException( e );
294 }
295
296 try
297 {
298 this.getObjectManager().getObject( (Class<?>) null, null, null );
299 fail( "Expected NullPointerException not thrown." );
300 }
301 catch ( final NullPointerException e )
302 {
303 assertNullPointerException( e );
304 }
305
306 try
307 {
308 this.getObjectManager().getObject( this.getClass(), null, null );
309 fail( "Expected NullPointerException not thrown." );
310 }
311 catch ( final NullPointerException e )
312 {
313 assertNullPointerException( e );
314 }
315
316 try
317 {
318 this.getObjectManager().getObject( this.getClass(), new URI( "/" ), null );
319 fail( "Expected NullPointerException not thrown." );
320 }
321 catch ( final NullPointerException e )
322 {
323 assertNullPointerException( e );
324 }
325
326 try
327 {
328 this.getObjectManager().getProperty( null, null );
329 fail( "Expected NullPointerException not thrown." );
330 }
331 catch ( final NullPointerException e )
332 {
333 assertNullPointerException( e );
334 }
335
336 try
337 {
338 this.getObjectManager().getProperty( this, null );
339 fail( "Expected NullPointerException not thrown." );
340 }
341 catch ( final NullPointerException e )
342 {
343 assertNullPointerException( e );
344 }
345
346 try
347 {
348 this.getObjectManager().getScope( null, null );
349 fail( "Expected NullPointerException not thrown." );
350 }
351 catch ( final NullPointerException e )
352 {
353 assertNullPointerException( e );
354 }
355
356 try
357 {
358 this.getObjectManager().getScope( "TEST", null );
359 fail( "Expected NullPointerException not thrown." );
360 }
361 catch ( final NullPointerException e )
362 {
363 assertNullPointerException( e );
364 }
365
366 try
367 {
368 this.getObjectManager().getScope( null, this.getClass().getClassLoader() );
369 fail( "Expected NullPointerException not thrown." );
370 }
371 catch ( final NullPointerException e )
372 {
373 assertNullPointerException( e );
374 }
375
376 try
377 {
378 this.getObjectManager().log( null, null, null );
379 fail( "Expected NullPointerException not thrown." );
380 }
381 catch ( final NullPointerException e )
382 {
383 assertNullPointerException( e );
384 }
385
386 try
387 {
388 this.getObjectManager().log( null, null, null, null );
389 fail( "Expected NullPointerException not thrown." );
390 }
391 catch ( final NullPointerException e )
392 {
393 assertNullPointerException( e );
394 }
395
396 try
397 {
398 this.getObjectManager().log( this.getClass().getClassLoader(), null, null, null );
399 fail( "Expected NullPointerException not thrown." );
400 }
401 catch ( final NullPointerException e )
402 {
403 assertNullPointerException( e );
404 }
405 }
406
407 @Test
408 public final void testNotNull() throws Exception
409 {
410 assertNotNull( this.getObjectManager().getListeners() );
411 assertNotNull( this.getObjectManager().getModules( this.getClass().getClassLoader() ) );
412 assertNotNull( this.getObjectManager().getObject( TestSpecificationOne.class ) );
413 assertNotNull( this.getObjectManager().getObject( TestSpecificationOne.class,
414 "JOMC :: RI :: Tests :: Implementation Test" ) );
415
416 assertNotNull( this.getObjectManager().getObject( TestSpecificationMany[].class ) );
417 assertNotNull( this.getObjectManager().getObject( TestSpecificationMany.class,
418 "JOMC :: RI :: Tests :: Implementation Test" ) );
419
420 assertNotNull( this.getObjectManager().getObject( TestScopeSpecification[].class ) );
421 assertNotNull( this.getObjectManager().getObject( TestScopeSpecification.class,
422 "JOMC :: RI :: Tests :: Implementation Test" ) );
423
424 }
425
426 @Test
427 public final void testNull() throws Exception
428 {
429 assertNull( this.getObjectManager().getObject( Object.class ) );
430 assertNull( this.getObjectManager().getObject( TestSpecification.class ) );
431 assertNull( this.getObjectManager().getObject( TestSpecificationOne[].class ) );
432 assertNull( this.getObjectManager().getObject( TestSpecificationOneMore.class ) );
433 assertNull( this.getObjectManager().getObject( TestSpecificationMany.class ) );
434 assertNull( this.getObjectManager().getObject( ObjectManager.class, "DOES NOT EXIST" ) );
435 assertNull( this.getObjectManager().getObject( TestSpecification.class, "DOES NOT EXIST" ) );
436 assertNull( this.getObjectManager().getDependency( this, "DOES NOT EXIST" ) );
437 assertNull( this.getObjectManager().getProperty( this, "DOES NOT EXIST" ) );
438 assertNull( this.getObjectManager().getMessage( this, "DOES NOT EXIST", Locale.getDefault() ) );
439 assertNull( this.getObjectManager().getObject( TestSpecificationOneMore.class,
440 "JOMC :: RI :: Tests :: Illegal Location Implementation" ) );
441
442 assertNull( this.getObjectManager().getObject( TestScopeSpecification.class,
443 "JOMC :: RI :: Tests :: Illegal Location Implementation" ) );
444
445 }
446
447 @Test
448 public final void testGetObjectManager() throws Exception
449 {
450 final ObjectManager first = DefaultObjectManager.getObjectManager( this.getClass().getClassLoader() );
451 final ObjectManager second = DefaultObjectManager.getObjectManager( this.getClass().getClassLoader() );
452 final ObjectManager third = DefaultObjectManager.getObjectManager( this.getClass().getClassLoader() );
453
454 assertTrue( first == second );
455 assertTrue( first == third );
456 assertTrue( second == third );
457 }
458
459 public static void assertNullPointerException( final NullPointerException e )
460 {
461 assertNotNull( e.getMessage() );
462 System.out.println( e.toString() );
463 }
464
465
466
467
468
469 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" )
470 public DefaultObjectManagerTest()
471 {
472
473 super();
474
475 }
476
477
478
479
480
481
482
483
484 }