1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 31 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 32 import net.sourceforge.groboutils.junit.v1.iftc.ImplFactory; 33 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase; 34 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite; 35 36 37 44 public class IClassMetaDataReaderUTestI extends InterfaceTestCase 45 { 46 49 private static final Class THIS_CLASS = IClassMetaDataReaderUTestI.class; 50 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 51 52 public IClassMetaDataReaderUTestI( String name, ImplFactory f ) 53 { 54 super( name, IClassMetaDataReader.class, f ); 55 } 56 57 58 public IClassMetaDataReader createIClassMetaDataReader() 59 { 60 return (IClassMetaDataReader)createImplObject(); 61 } 62 63 64 67 68 public void testGetClassSignatures1() throws Exception 69 { 70 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 71 String sigs1[] = cmdr.getClassSignatures(); 72 assertNotNull( 73 "Returned null sigs.", 74 sigs1 ); 75 String sigs2[] = cmdr.getClassSignatures(); 76 assertNotNull( 77 "Returned null sigs on second attempt.", 78 sigs2 ); 79 assertEquals( 80 "Two consecutive calls returned different class signatures.", 81 sigs1.length, 82 sigs2.length ); 83 } 84 85 86 public void testGetClassSignatures2() throws Exception 87 { 88 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 89 cmdr.close(); 90 try 91 { 92 cmdr.getClassSignatures(); 93 fail( "Did not throw IOException." ); 94 } 95 catch (IOException ioe) 96 { 97 assertNotNull( "Null exception message.", ioe.getMessage() ); 98 } 99 } 100 101 102 public void testGetClassSignatures3() throws Exception 103 { 104 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 105 String sigs1[] = cmdr.getClassSignatures(); 106 cmdr.close(); 107 try 108 { 109 cmdr.getClassSignatures(); 110 fail( "Did not throw IOException." ); 111 } 112 catch (IOException ioe) 113 { 114 assertNotNull( "Null exception message.", ioe.getMessage() ); 115 } 116 } 117 118 119 public void testGetClassSignatures4() throws Exception 120 { 121 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 122 String sigs[] = cmdr.getClassSignatures(); 123 for (int i = 0; i < sigs.length; ++i) 124 { 125 assertNotNull( 126 "Returned null signature at index "+i+".", 127 sigs[i] ); 128 } 129 } 130 131 132 public void testReadClass1() throws Exception 133 { 134 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 135 cmdr.close(); 136 try 137 { 138 cmdr.readClass( "a" ); 139 fail( "Did not throw IOException." ); 140 } 141 catch (IOException ioe) 142 { 143 assertNotNull( "Null exception message.", ioe.getMessage() ); 144 } 145 } 146 147 148 public void testReadClass2() throws Exception 149 { 150 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 151 cmdr.close(); 152 try 153 { 154 cmdr.readClass( null ); 155 fail( "Did not throw IllegalArgumentException." ); 156 } 157 catch (IllegalArgumentException ex) 158 { 159 assertNotNull( "Null exception message.", ex.getMessage() ); 160 } 161 } 162 163 164 public void testReadClass3() throws Exception 165 { 166 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 167 String nonExistClassName = "a"; 168 String sigs[] = cmdr.getClassSignatures(); 169 boolean inSigs = true; 170 while (inSigs) 171 { 172 nonExistClassName += "1"; 173 inSigs = false; 174 for (int i = 0; i < sigs.length; ++i) 175 { 176 if (sigs[i].equals( nonExistClassName )) 177 { 178 inSigs = true; 179 break; 180 } 181 } 182 } 183 184 ClassRecord cr = cmdr.readClass( nonExistClassName ); 185 assertNull( 186 "Incorrectly returned a class for a non-existent class "+ 187 "signature '"+nonExistClassName+"'.", 188 cr ); 189 } 190 191 192 public void testReadAllClasses1() throws Exception 193 { 194 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 195 String sigs[] = cmdr.getClassSignatures(); 196 assertNotNull( 197 "Returned null sigs.", 198 sigs ); 199 for (int i = 0; i < sigs.length; ++i) 200 { 201 ClassRecord cr = cmdr.readClass( sigs[i] ); 202 assertNotNull( 203 "Read null class from returned class signature.", 204 cr ); 205 } 206 } 207 208 209 public void testClose1() throws Exception 210 { 211 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 212 cmdr.close(); 213 } 214 215 216 public void testClose2() throws Exception 217 { 218 IClassMetaDataReader cmdr = createIClassMetaDataReader(); 219 cmdr.close(); 220 try 221 { 222 cmdr.close(); 223 fail( "Did not throw IOException." ); 224 } 225 catch (IOException ex) 226 { 227 assertNotNull( "Null exception message.", ex.getMessage() ); 228 } 229 } 230 231 232 233 236 237 public static InterfaceTestSuite suite() 238 { 239 InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS ); 240 241 return suite; 242 } 243 244 public static void main( String [] args ) 245 { 246 String [] name = { THIS_CLASS.getName() }; 247 248 251 junit.textui.TestRunner.main( name ); 252 } 253 254 255 259 protected void setUp() throws Exception 260 { 261 super.setUp(); 262 263 } 265 266 267 271 protected void tearDown() throws Exception 272 { 273 275 276 super.tearDown(); 277 } 278 } 279 280 | Popular Tags |