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