KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > classes > v1 > SingletonStoreUTest


1 /*
2  * @(#)SingletonStoreUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.util.classes.v1;
28
29 import org.easymock.EasyMock;
30 import org.easymock.MockControl;
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34
35
36 /**
37  * Tests the SingletonStore class.
38  *
39  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
40  * @version $Date: 2003/02/10 22:52:39 $
41  * @since March 1, 2002
42  */

43 public class SingletonStoreUTest extends TestCase
44 {
45     //-------------------------------------------------------------------------
46
// Standard JUnit Class-specific declarations
47

48     private static final Class JavaDoc THIS_CLASS = SingletonStoreUTest.class;
49     
50     public SingletonStoreUTest( String JavaDoc name )
51     {
52         super( name );
53     }
54
55     
56     //-------------------------------------------------------------------------
57
// setup
58

59     /**
60      *
61      * @exception Exception thrown under any exceptional condition.
62      */

63     protected void setUp() throws Exception JavaDoc
64     {
65         super.setUp();
66         
67         // set ourself up
68
}
69
70
71     //-------------------------------------------------------------------------
72
// Tests
73

74     
75     public void testConstructor1()
76     {
77         new SingletonStore( null, null, null );
78     }
79     
80     
81     public void testConstructor2()
82     {
83         new SingletonStore( this.getClass(), null, null );
84     }
85     
86     
87     public void testConstructor3()
88     {
89         new SingletonStore( null, this.getClass(), null );
90     }
91     
92     
93     public void testConstructor4()
94     {
95         new SingletonStore( null, null, "a" );
96     }
97     
98     
99     public void testConstructor5()
100     {
101         new SingletonStore( this.getClass(), this.getClass(), null );
102     }
103     
104     
105     public void testConstructor6()
106     {
107         new SingletonStore( this.getClass(), null, "a" );
108     }
109     
110     
111     public void testConstructor7()
112     {
113         new SingletonStore( null, this.getClass(), "a" );
114     }
115     
116     
117     public void testConstructor8()
118     {
119         new SingletonStore( this.getClass(), this.getClass(), "a" );
120     }
121     
122     
123     public void testSetSingleton1()
124     {
125         SingletonStore ss = new SingletonStore( null, null, null );
126         Object JavaDoc o = "a";
127         ss.setSingleton( o );
128         assertEquals(
129             "did not return the same set singleton",
130             o,
131             ss.getSingleton() );
132     }
133     
134     
135     public void testSetSingleton2()
136     {
137         SingletonStore ss = new SingletonStore( String JavaDoc.class, null, null );
138         Object JavaDoc o = "a";
139         ss.setSingleton( o );
140         assertEquals(
141             "did not return the same set singleton",
142             o,
143             ss.getSingleton() );
144     }
145     
146     
147     public void testSetSingleton3()
148     {
149         SingletonStore ss = new SingletonStore( String JavaDoc.class, null, null );
150         try
151         {
152             ss.setSingleton( null );
153         }
154         catch (IllegalArgumentException JavaDoc iae)
155         {
156             // test exception?
157
}
158     }
159     
160     
161     public void testSetSingleton4()
162     {
163         SingletonStore ss = new SingletonStore( String JavaDoc.class, null, null );
164         Object JavaDoc o = new Object JavaDoc();
165         try
166         {
167             ss.setSingleton( o );
168         }
169         catch (IllegalArgumentException JavaDoc iae)
170         {
171             // test exception?
172
}
173     }
174     
175     
176     public void testGetSingleton1()
177     {
178         SingletonStore ss = new SingletonStore( null, null, null );
179         try
180         {
181             ss.getSingleton();
182         }
183         catch (IllegalArgumentException JavaDoc iae)
184         {
185             // test exception?
186
}
187     }
188     
189     
190     public void testGetSingleton2()
191     {
192         // create a non-existent property name.
193
String JavaDoc propertyName = "-";
194         while (System.getProperty( propertyName ) != null)
195         {
196             propertyName += "-";
197         }
198         SingletonStore ss = new SingletonStore( null, null, propertyName );
199         try
200         {
201             ss.getSingleton();
202         }
203         catch (IllegalArgumentException JavaDoc iae)
204         {
205             // test exception?
206
}
207     }
208     
209     
210     public void testGetSingleton3()
211     {
212         // create a non-existent property name.
213
String JavaDoc propertyName = "-";
214         while (System.getProperty( propertyName ) != null)
215         {
216             propertyName += "-";
217         }
218         SingletonStore ss = new SingletonStore( null, Object JavaDoc.class, propertyName );
219         Object JavaDoc o = ss.getSingleton();
220         assertEquals(
221             "Did not create a singleton of the correct type.",
222             Object JavaDoc.class,
223             o.getClass() );
224     }
225     
226     
227     
228     //-------------------------------------------------------------------------
229
// Helpers
230

231     
232     
233     
234     //-------------------------------------------------------------------------
235
// Standard JUnit declarations
236

237     
238     public static Test suite()
239     {
240         TestSuite suite = new TestSuite( THIS_CLASS );
241         
242         // Test the implementation's interface conformity.
243
/*
244         suite.addTest( IxUTestI.suite(
245             new ImplementationCreator[] {
246                 new ImplementationCreator() {
247                     public Object createImplementedObject() {
248                         // XXXXXXXXXXXXXXXXXXXXXXXX
249                     }
250                 },
251             } ) );
252         */

253         
254         return suite;
255     }
256     
257     public static void main( String JavaDoc[] args )
258     {
259         String JavaDoc[] name = { THIS_CLASS.getName() };
260         
261         // junit.textui.TestRunner.main( name );
262
// junit.swingui.TestRunner.main( name );
263

264         junit.textui.TestRunner.main( name );
265     }
266     
267     
268     /**
269      *
270      * @exception Exception thrown under any exceptional condition.
271      */

272     protected void tearDown() throws Exception JavaDoc
273     {
274         // tear ourself down
275

276         
277         super.tearDown();
278     }
279 }
280
281
Popular Tags