001: /*
002: * @(#)SingletonStoreUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.util.classes.v1;
028:
029: import org.easymock.EasyMock;
030: import org.easymock.MockControl;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034:
035: /**
036: * Tests the SingletonStore class.
037: *
038: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
039: * @version $Date: 2003/02/10 22:52:39 $
040: * @since March 1, 2002
041: */
042: public class SingletonStoreUTest extends TestCase {
043: //-------------------------------------------------------------------------
044: // Standard JUnit Class-specific declarations
045:
046: private static final Class THIS_CLASS = SingletonStoreUTest.class;
047:
048: public SingletonStoreUTest(String name) {
049: super (name);
050: }
051:
052: //-------------------------------------------------------------------------
053: // setup
054:
055: /**
056: *
057: * @exception Exception thrown under any exceptional condition.
058: */
059: protected void setUp() throws Exception {
060: super .setUp();
061:
062: // set ourself up
063: }
064:
065: //-------------------------------------------------------------------------
066: // Tests
067:
068: public void testConstructor1() {
069: new SingletonStore(null, null, null);
070: }
071:
072: public void testConstructor2() {
073: new SingletonStore(this .getClass(), null, null);
074: }
075:
076: public void testConstructor3() {
077: new SingletonStore(null, this .getClass(), null);
078: }
079:
080: public void testConstructor4() {
081: new SingletonStore(null, null, "a");
082: }
083:
084: public void testConstructor5() {
085: new SingletonStore(this .getClass(), this .getClass(), null);
086: }
087:
088: public void testConstructor6() {
089: new SingletonStore(this .getClass(), null, "a");
090: }
091:
092: public void testConstructor7() {
093: new SingletonStore(null, this .getClass(), "a");
094: }
095:
096: public void testConstructor8() {
097: new SingletonStore(this .getClass(), this .getClass(), "a");
098: }
099:
100: public void testSetSingleton1() {
101: SingletonStore ss = new SingletonStore(null, null, null);
102: Object o = "a";
103: ss.setSingleton(o);
104: assertEquals("did not return the same set singleton", o, ss
105: .getSingleton());
106: }
107:
108: public void testSetSingleton2() {
109: SingletonStore ss = new SingletonStore(String.class, null, null);
110: Object o = "a";
111: ss.setSingleton(o);
112: assertEquals("did not return the same set singleton", o, ss
113: .getSingleton());
114: }
115:
116: public void testSetSingleton3() {
117: SingletonStore ss = new SingletonStore(String.class, null, null);
118: try {
119: ss.setSingleton(null);
120: } catch (IllegalArgumentException iae) {
121: // test exception?
122: }
123: }
124:
125: public void testSetSingleton4() {
126: SingletonStore ss = new SingletonStore(String.class, null, null);
127: Object o = new Object();
128: try {
129: ss.setSingleton(o);
130: } catch (IllegalArgumentException iae) {
131: // test exception?
132: }
133: }
134:
135: public void testGetSingleton1() {
136: SingletonStore ss = new SingletonStore(null, null, null);
137: try {
138: ss.getSingleton();
139: } catch (IllegalArgumentException iae) {
140: // test exception?
141: }
142: }
143:
144: public void testGetSingleton2() {
145: // create a non-existent property name.
146: String propertyName = "-";
147: while (System.getProperty(propertyName) != null) {
148: propertyName += "-";
149: }
150: SingletonStore ss = new SingletonStore(null, null, propertyName);
151: try {
152: ss.getSingleton();
153: } catch (IllegalArgumentException iae) {
154: // test exception?
155: }
156: }
157:
158: public void testGetSingleton3() {
159: // create a non-existent property name.
160: String propertyName = "-";
161: while (System.getProperty(propertyName) != null) {
162: propertyName += "-";
163: }
164: SingletonStore ss = new SingletonStore(null, Object.class,
165: propertyName);
166: Object o = ss.getSingleton();
167: assertEquals("Did not create a singleton of the correct type.",
168: Object.class, o.getClass());
169: }
170:
171: //-------------------------------------------------------------------------
172: // Helpers
173:
174: //-------------------------------------------------------------------------
175: // Standard JUnit declarations
176:
177: public static Test suite() {
178: TestSuite suite = new TestSuite(THIS_CLASS);
179:
180: // Test the implementation's interface conformity.
181: /*
182: suite.addTest( IxUTestI.suite(
183: new ImplementationCreator[] {
184: new ImplementationCreator() {
185: public Object createImplementedObject() {
186: // XXXXXXXXXXXXXXXXXXXXXXXX
187: }
188: },
189: } ) );
190: */
191:
192: return suite;
193: }
194:
195: public static void main(String[] args) {
196: String[] name = { THIS_CLASS.getName() };
197:
198: // junit.textui.TestRunner.main( name );
199: // junit.swingui.TestRunner.main( name );
200:
201: junit.textui.TestRunner.main(name);
202: }
203:
204: /**
205: *
206: * @exception Exception thrown under any exceptional condition.
207: */
208: protected void tearDown() throws Exception {
209: // tear ourself down
210:
211: super.tearDown();
212: }
213: }
|