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.modlet.test;
32
33 import org.jomc.modlet.Service;
34 import org.jomc.modlet.Services;
35 import org.junit.Test;
36 import static org.junit.Assert.assertEquals;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.fail;
39
40
41
42
43
44
45
46 public class ServicesTest
47 {
48
49
50 public ServicesTest()
51 {
52 super();
53 }
54
55 @Test
56 public final void testGetServices() throws Exception
57 {
58 final Services services = new Services();
59
60 try
61 {
62 services.getServices( (String) null );
63 fail( "Expected NullPointerException not thrown." );
64 }
65 catch ( final NullPointerException e )
66 {
67 assertNotNull( e.getMessage() );
68 System.out.println( e );
69 }
70
71 try
72 {
73 services.getServices( (Class) null );
74 fail( "Expected NullPointerException not thrown." );
75 }
76 catch ( final NullPointerException e )
77 {
78 assertNotNull( e.getMessage() );
79 System.out.println( e );
80 }
81
82 final Service s1 = new Service();
83 s1.setOrdinal( 1000 );
84 s1.setIdentifier( this.getClass().getName() );
85 s1.setClazz( "Service 1" );
86
87 final Service s2 = new Service();
88 s2.setOrdinal( 500 );
89 s2.setIdentifier( this.getClass().getName() );
90 s2.setClazz( "Service 2" );
91
92 services.getService().add( s1 );
93 services.getService().add( s2 );
94
95 assertNotNull( services.getServices( this.getClass() ) );
96 assertEquals( 2, services.getServices( this.getClass() ).size() );
97 assertEquals( "Service 2", services.getServices( this.getClass() ).get( 0 ).getClazz() );
98 assertEquals( "Service 1", services.getServices( this.getClass() ).get( 1 ).getClazz() );
99
100 assertNotNull( services.getServices( this.getClass().getName() ) );
101 assertEquals( 2, services.getServices( this.getClass().getName() ).size() );
102 assertEquals( "Service 2", services.getServices( this.getClass().getName() ).get( 0 ).getClazz() );
103 assertEquals( "Service 1", services.getServices( this.getClass().getName() ).get( 1 ).getClazz() );
104 }
105
106 }