1 package org.codehaus.classworlds;
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
37
38
39
40
41
42
43
44
45
46
47
48
49 import junit.framework.TestCase;
50
51 public class ClassWorldTest extends TestCase
52 {
53 private ClassWorld world;
54
55 public ClassWorldTest( String name )
56 {
57 super( name );
58 }
59
60 public void setUp()
61 {
62 this.world = new ClassWorld();
63 }
64
65 public void tearDown()
66 {
67 this.world = null;
68 }
69
70 public void testEmpty()
71 {
72 assertTrue( this.world.getRealms().isEmpty() );
73 }
74
75 public void testNewRealm() throws Exception
76 {
77 ClassRealm realm = this.world.newRealm( "foo" );
78
79 assertNotNull( realm );
80 }
81
82 public void testGetRealm() throws Exception
83 {
84 ClassRealm realm = this.world.newRealm( "foo" );
85
86 assertSame( realm,
87 this.world.getRealm( "foo" ) );
88 }
89
90 public void testNewRealm_Duplicate() throws Exception
91 {
92 try
93 {
94 this.world.newRealm( "foo" );
95 this.world.newRealm( "foo" );
96
97 fail( "throw DuplicateRealmException" );
98 }
99 catch ( DuplicateRealmException e )
100 {
101
102
103 assertSame( this.world,
104 e.getWorld() );
105
106 assertEquals( "foo",
107 e.getId() );
108 }
109 }
110
111 public void testGetRealm_NoSuch() throws Exception
112 {
113 try
114 {
115 this.world.getRealm( "foo" );
116 fail( "throw NoSuchRealmException" );
117 }
118 catch ( NoSuchRealmException e )
119 {
120
121
122 assertSame( this.world,
123 e.getWorld() );
124
125 assertEquals( "foo",
126 e.getId() );
127 }
128 }
129
130 public void testGetRealms() throws Exception
131 {
132 assertTrue( this.world.getRealms().isEmpty() );
133
134 ClassRealm foo = this.world.newRealm( "foo" );
135
136 assertEquals( 1,
137 this.world.getRealms().size() );
138
139 assertTrue( this.world.getRealms().contains( foo ) );
140
141 ClassRealm bar = this.world.newRealm( "bar" );
142
143 assertEquals( 2,
144 this.world.getRealms().size() );
145
146 assertTrue( this.world.getRealms().contains( bar ) );
147 }
148 }