1 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 43 public class SingletonStoreUTest extends TestCase 44 { 45 48 private static final Class THIS_CLASS = SingletonStoreUTest.class; 49 50 public SingletonStoreUTest( String name ) 51 { 52 super( name ); 53 } 54 55 56 59 63 protected void setUp() throws Exception 64 { 65 super.setUp(); 66 67 } 69 70 71 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 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 .class, null, null ); 138 Object 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 .class, null, null ); 150 try 151 { 152 ss.setSingleton( null ); 153 } 154 catch (IllegalArgumentException iae) 155 { 156 } 158 } 159 160 161 public void testSetSingleton4() 162 { 163 SingletonStore ss = new SingletonStore( String .class, null, null ); 164 Object o = new Object (); 165 try 166 { 167 ss.setSingleton( o ); 168 } 169 catch (IllegalArgumentException iae) 170 { 171 } 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 iae) 184 { 185 } 187 } 188 189 190 public void testGetSingleton2() 191 { 192 String 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 iae) 204 { 205 } 207 } 208 209 210 public void testGetSingleton3() 211 { 212 String propertyName = "-"; 214 while (System.getProperty( propertyName ) != null) 215 { 216 propertyName += "-"; 217 } 218 SingletonStore ss = new SingletonStore( null, Object .class, propertyName ); 219 Object o = ss.getSingleton(); 220 assertEquals( 221 "Did not create a singleton of the correct type.", 222 Object .class, 223 o.getClass() ); 224 } 225 226 227 228 231 232 233 234 237 238 public static Test suite() 239 { 240 TestSuite suite = new TestSuite( THIS_CLASS ); 241 242 253 254 return suite; 255 } 256 257 public static void main( String [] args ) 258 { 259 String [] name = { THIS_CLASS.getName() }; 260 261 264 junit.textui.TestRunner.main( name ); 265 } 266 267 268 272 protected void tearDown() throws Exception 273 { 274 276 277 super.tearDown(); 278 } 279 } 280 281 | Popular Tags |