1 26 27 package net.sourceforge.groboutils.codecoverage.v2.report; 28 29 import java.io.File ; 30 import java.io.IOException ; 31 32 import junit.framework.Test; 33 import junit.framework.TestCase; 34 import junit.framework.TestSuite; 35 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 36 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil; 37 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 38 import net.sourceforge.groboutils.codecoverage.v2.datastore.DirMetaDataReader; 39 import net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLogReader; 40 41 42 49 public class AnalysisModuleDataUTest extends TestCase 50 { 51 54 private static final Class THIS_CLASS = AnalysisModuleDataUTest.class; 55 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 56 57 public AnalysisModuleDataUTest( String name ) 58 { 59 super( name ); 60 } 61 62 63 66 67 public void testConstructor1() throws Exception 68 { 69 try 70 { 71 new AnalysisModuleData( null, null, null ); 72 fail( "Did not throw IllegalArgumentException." ); 73 } 74 catch (IllegalArgumentException e) 75 { 76 } 77 } 78 79 80 public void testConstructor2() throws Exception 81 { 82 try 83 { 84 new AnalysisModuleData( createIAnalysisModule( "a", "b", "c" ), 85 null, null ); 86 fail( "Did not throw IllegalArgumentException." ); 87 } 88 catch (IllegalArgumentException e) 89 { 90 } 91 } 92 93 94 public void testConstructor3() throws Exception 95 { 96 File f = CCCreatorUtil.createNewDirectory(); 97 try 98 { 99 new AnalysisModuleData( createIAnalysisModule( "a", "b", "c" ), 100 createDirMetaDataReader( f ), null ); 101 fail( "Did not throw IllegalArgumentException." ); 102 } 103 catch (IllegalArgumentException e) 104 { 105 } 106 } 107 108 109 public void testConstructor4() throws Exception 110 { 111 File f = CCCreatorUtil.createNewDirectory(); 112 try 113 { 114 new AnalysisModuleData( null, 115 createDirMetaDataReader( f ), 116 createDirectoryChannelLogReader( f, createClassLogData(4) ) ); 117 fail( "Did not throw IllegalArgumentException." ); 118 } 119 catch (IllegalArgumentException e) 120 { 121 } 122 } 123 124 125 public void testConstructor5() throws Exception 126 { 127 File f = CCCreatorUtil.createNewDirectory(); 128 try 129 { 130 new AnalysisModuleData( createIAnalysisModule( "a", "b", "c" ), 131 null, 132 createDirectoryChannelLogReader( f, createClassLogData(2) ) ); 133 fail( "Did not throw IllegalArgumentException." ); 134 } 135 catch (IllegalArgumentException e) 136 { 137 } 138 } 139 140 141 public void testGetClassSignatures1() throws Exception 142 { 143 File f = CCCreatorUtil.createNewDirectory(); 144 AnalysisModuleData amd = new AnalysisModuleData( 145 createIAnalysisModule( "a", "b", "c" ), 146 createDirMetaDataReader( f ), 147 createDirectoryChannelLogReader( f, createClassLogData( 1 ) ) ); 148 String sigs[] = amd.getClassSignatures(); 149 assertNotNull( 150 "Got null sigs.", 151 sigs ); 152 DOC.getLog().warn( 153 "this test is failing due to incorrect class generation logic." ); 154 164 } 165 166 167 public void testGetClassSignatures2() throws Exception 168 { 169 File f = CCCreatorUtil.createNewDirectory(); 170 AnalysisModuleData amd = new AnalysisModuleData( 171 createIAnalysisModule( "a", "b", "c" ), 172 createDirMetaDataReader( f ), 173 createDirectoryChannelLogReader( f, createClassLogData( 2 ) ) ); 174 String sigs[] = amd.getClassSignatures(); 175 assertNotNull( 176 "Got null sigs.", 177 sigs ); 178 DOC.getLog().warn( 179 "this test is failing due to incorrect class generation logic." ); 180 186 } 187 188 189 public void testGetClassSignatures3() throws Exception 190 { 191 File f = CCCreatorUtil.createNewDirectory(); 192 AnalysisModuleData amd = new AnalysisModuleData( 193 createIAnalysisModule( "a", "b", "c" ), 194 createDirMetaDataReader( f ), 195 createDirectoryChannelLogReader( f, createClassLogData( 0 ) ) ); 196 String sigs[] = amd.getClassSignatures(); 197 assertNotNull( 198 "Got null sigs.", 199 sigs ); 200 assertEquals( 201 "Didn't get correct number of classes.", 202 0, 203 sigs.length ); 204 } 205 206 207 210 211 protected IAnalysisModule createIAnalysisModule( String name, String unit, 212 String mime ) 213 { 214 return CCCreatorUtil.createIAnalysisModule( name, unit, mime ); 215 } 216 217 218 protected DirMetaDataReader createDirMetaDataReader( File basedir ) 219 throws IOException 220 { 221 return CCCreatorUtil.createDirMetaDataReader( basedir, 222 new Class [] { THIS_CLASS, String .class }, 223 CCCreatorUtil.createAnalysisModules( 2 ) ); 224 } 225 226 227 protected DirectoryChannelLogReader createDirectoryChannelLogReader( 228 File basedir, CCCreatorUtil.SimpleClassLogData[] data ) 229 { 230 return CCCreatorUtil.createDirectoryChannelLogReader( basedir, data, 231 (short)100 ); 232 } 233 234 235 protected CCCreatorUtil.SimpleClassLogData[] createClassLogData( 236 int count ) 237 { 238 CCCreatorUtil.SimpleClassLogData[] scld = new 239 CCCreatorUtil.SimpleClassLogData[ count ]; 240 for (int i = 0; i < count; ++i) 241 { 242 scld[i] = new CCCreatorUtil.SimpleClassLogData( 243 (char)('a' + i)+".MyClass-112", 244 new int[] { 1,2,1 }, new int[] { 11, 2, 13 } ); 245 } 246 return scld; 247 } 248 249 250 253 254 public static Test suite() 255 { 256 TestSuite suite = new TestSuite( THIS_CLASS ); 257 258 return suite; 259 } 260 261 public static void main( String [] args ) 262 { 263 String [] name = { THIS_CLASS.getName() }; 264 265 268 junit.textui.TestRunner.main( name ); 269 } 270 271 272 276 protected void setUp() throws Exception 277 { 278 super.setUp(); 279 280 281 } 283 284 285 289 protected void tearDown() throws Exception 290 { 291 293 294 super.tearDown(); 295 } 296 } 297 298 | Popular Tags |