1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 import java.util.Vector ; 31 32 import junit.framework.Test; 33 import junit.framework.TestCase; 34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 35 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil; 36 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 37 import net.sourceforge.groboutils.codecoverage.v2.compiler.ModifiedClass; 38 import net.sourceforge.groboutils.junit.v1.iftc.CxFactory; 39 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite; 40 41 42 49 public class DirClassMetaDataReaderUTest extends TestCase 50 { 51 54 private static final Class THIS_CLASS = DirClassMetaDataReaderUTest.class; 55 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 56 57 public DirClassMetaDataReaderUTest( String name ) 58 { 59 super( name ); 60 } 61 62 63 66 67 public void testConstructor1() throws Exception 68 { 69 try 70 { 71 new DirClassMetaDataReader( null, null ); 72 fail( "Did not throw IllegalArgumentException." ); 73 } 74 catch (IllegalArgumentException ex) 75 { 76 } 78 } 79 80 81 public void testConstructor2() throws Exception 82 { 83 try 84 { 85 new DirClassMetaDataReader( 86 createIAnalysisModule( "A", "B", "C" ), null ); 87 fail( "Did not throw IllegalArgumentException." ); 88 } 89 catch (IllegalArgumentException ex) 90 { 91 } 93 } 94 95 96 public void testConstructor3() throws Exception 97 { 98 try 99 { 100 new DirClassMetaDataReader( null, 101 createDirMetaDataIO( createIAnalysisModule( "A", "B", "C" ) ) ); 102 fail( "Did not throw IllegalArgumentException." ); 103 } 104 catch (IllegalArgumentException ex) 105 { 106 } 108 } 109 110 111 public void testGetClassSignatures1() throws Exception 112 { 113 IAnalysisModule am = createIAnalysisModule( "A", "B", "C" ); 114 DirMetaDataIO dmdio = createDirMetaDataIO( am ); 115 String sig1 = addClassRecord( dmdio, THIS_CLASS, am ); 116 117 DirClassMetaDataReader dcmdr = new DirClassMetaDataReader( 118 am, dmdio ); 119 String [] sigs = dcmdr.getClassSignatures(); 120 assertNotNull( 121 "Returned null signatures.", 122 sigs ); 123 assertEquals( 124 "Returned incorrect number of signatures.", 125 1, 126 sigs.length ); 127 assertEquals( 128 "Did not return the correct sig.", 129 sig1, 130 sigs[0] ); 131 } 132 133 134 public void testReadClass1() throws Exception 135 { 136 IAnalysisModule am = createIAnalysisModule( "A", "B", "C" ); 137 DirMetaDataIO dmdio = createDirMetaDataIO( am ); 138 String sig1 = addClassRecord( dmdio, THIS_CLASS, am ); 139 140 DirClassMetaDataReader dcmdr = new DirClassMetaDataReader( 141 am, dmdio ); 142 ClassRecord cr = dcmdr.readClass( sig1 ); 143 assertNotNull( 144 "Returned null class record.", 145 cr ); 146 assertEquals( 147 "Returned incorrect class record.", 148 sig1, 149 cr.getClassSignature() ); 150 } 151 152 153 public void testClose1() throws Exception 154 { 155 IAnalysisModule am = createIAnalysisModule( "A", "B", "C" ); 156 DirMetaDataIO dmdio = createDirMetaDataIO( am ); 157 DirClassMetaDataReader dcmdr = new DirClassMetaDataReader( 158 am, dmdio ); 159 160 dcmdr.close(); 161 162 assertFalse( 163 "Reader closed the underlying IO object.", 164 dmdio.isClosed() ); 165 } 166 167 168 171 protected static IAnalysisModule createIAnalysisModule( String name, 172 String unit, String mime ) 173 { 174 return CCCreatorUtil.createIAnalysisModule( name, unit, mime ); 175 } 176 177 protected static DirMetaDataIO createDirMetaDataIO( IAnalysisModule am ) 178 throws IOException 179 { 180 DirMetaDataIO dmd = new DirMetaDataIO( 181 CCCreatorUtil.createNewDirectory() ); 182 dmd.putAnalysisModuleSet( 183 new AnalysisModuleSet( new IAnalysisModule[] { am } ) ); 184 return dmd; 185 } 186 187 protected String addClassRecord( DirMetaDataIO dmd, Class c, 188 IAnalysisModule am ) 189 throws IOException 190 { 191 ModifiedClass mc = CCCreatorUtil.createModifiedClass( c ); 192 ClassRecord cr = mc.createClassRecord( new AnalysisModuleSet( 193 new IAnalysisModule[] { am } ) ); 194 dmd.putClassRecord( am, cr ); 195 return cr.getClassSignature(); 196 } 197 198 199 200 201 204 205 public static Test suite() 206 { 207 InterfaceTestSuite suite = IClassMetaDataReaderUTestI.suite(); 208 suite.addTestSuite( THIS_CLASS ); 209 suite.addFactory( new CxFactory( "A" ) { 210 Vector v = new Vector (); 211 public Object createImplObject() throws IOException { 212 IAnalysisModule am = createIAnalysisModule( "a", "u", 213 "text/plain" ); 214 DirMetaDataIO dmd = createDirMetaDataIO( am ); 215 v.addElement( dmd ); 216 return new DirClassMetaDataReader( am, dmd ); 217 } 218 } ); 219 suite.addFactory( new CxFactory( "B" ) { 220 Vector v = new Vector (); 221 public Object createImplObject() throws IOException { 222 IAnalysisModule am = createIAnalysisModule( "a", "u", 223 "text/plain" ); 224 DirMetaDataReader dmdr = CCCreatorUtil.createDirMetaDataReader( 225 CCCreatorUtil.createNewDirectory(), 226 new Class [0], 227 new IAnalysisModule[] { am } ); 228 DirClassMetaDataReader dcmdr = (DirClassMetaDataReader) 229 dmdr.getClassReader( am ); 230 v.addElement( dmdr ); 232 return dcmdr; 233 } 234 } ); 235 suite.addFactory( new CxFactory( "C" ) { 236 Vector v = new Vector (); 237 public Object createImplObject() throws IOException { 238 IAnalysisModule am = createIAnalysisModule( "a", "u", 239 "text/plain" ); 240 DirMetaDataReader dmdr = CCCreatorUtil.createDirMetaDataReader( 241 CCCreatorUtil.createNewDirectory(), 242 new Class [] { THIS_CLASS, String .class, Short .class }, 243 new IAnalysisModule[] { am } ); 244 DirClassMetaDataReader dcmdr = (DirClassMetaDataReader) 245 dmdr.getClassReader( am ); 246 v.addElement( dmdr ); 248 return dcmdr; 249 } 250 } ); 251 return suite; 252 } 253 254 public static void main( String [] args ) 255 { 256 String [] name = { THIS_CLASS.getName() }; 257 258 261 junit.textui.TestRunner.main( name ); 262 } 263 264 265 269 protected void setUp() throws Exception 270 { 271 super.setUp(); 272 273 274 } 276 277 278 282 protected void tearDown() throws Exception 283 { 284 286 287 super.tearDown(); 288 } 289 } 290 291 | Popular Tags |