1 /*
2 * Copyright (C) Christian Schulte, 2005-206
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * o Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * o Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $JOMC: ServicesTest.java 3851 2011-10-10 16:25:09Z schulte2005 $
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 * Test cases for class {@code org.jomc.modlet.Services}.
42 *
43 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
44 * @version $JOMC: ServicesTest.java 3851 2011-10-10 16:25:09Z schulte2005 $
45 */
46 public class ServicesTest
47 {
48
49 /** Creates a new {@code ServicesTest} instance. */
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 }