1 26 27 package net.sourceforge.groboutils.codecoverage.v2.logger; 28 29 import java.io.File ; 30 import java.io.FileWriter ; 31 import java.io.IOException ; 32 33 import junit.framework.Test; 34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 35 import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil; 36 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogReaderUTestI; 37 import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReader; 38 import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReaderUTestI; 39 import net.sourceforge.groboutils.junit.v1.SubTestTestCase; 40 import net.sourceforge.groboutils.junit.v1.iftc.CxFactory; 41 import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite; 42 43 44 51 public class DirectoryChannelLogReaderUTest extends SubTestTestCase 52 { 53 56 private static final Class THIS_CLASS = DirectoryChannelLogReaderUTest.class; 57 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 58 59 public DirectoryChannelLogReaderUTest( String name ) 60 { 61 super( name ); 62 } 63 64 65 68 69 public void testConstructor1() throws Exception 70 { 71 Thread.sleep( 100 ); 72 File base = new File ( ".", 73 Long.toString( System.currentTimeMillis() ) ); 74 try 75 { 76 new DirectoryChannelLogReader( base, (short)0 ); 77 fail( "Didn't throw IllegalArgumentException." ); 78 } 79 catch (IllegalArgumentException ex) 80 { 81 } 83 } 84 85 86 public void testConstructor2() throws Exception 87 { 88 Thread.sleep( 100 ); 89 File base = CCCreatorUtil.createNewDirectory(); 90 try 91 { 92 new DirectoryChannelLogReader( base, (short)0 ); 93 fail( "Didn't throw IllegalArgumentException." ); 94 } 95 catch (IllegalArgumentException ex) 96 { 97 } 99 } 100 101 102 public void testGetReaderForClassSignature1() throws IOException 103 { 104 String classSig = "a.MyClass-1"; 105 File outdir = CCCreatorUtil.createNewDirectory(); 106 File fd1 = new File ( outdir, "0" ); 107 fd1.mkdirs(); 108 File cd1 = new File ( fd1, classSig + 109 DirectoryChannelLogger.CLASS_LOG_EXTENTION ); 110 FileWriter fw = new FileWriter ( cd1 ); 111 fw.write( "0001 0002\n" ); 112 fw.close(); 113 DirectoryChannelLogReader dclr = new DirectoryChannelLogReader( 114 outdir, (short)0 ); 115 final IClassChannelLogReader cclr = dclr. 116 getReaderForClassSignature( classSig ); 117 assertNotNull( 118 "Returned null class channel log reader.", 119 cclr ); 120 assertTrue( 121 "Not correct type (was "+cclr.getClass().getName()+").", 122 cclr instanceof DirectoryClassChannelLogReader ); 123 124 InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite(); 125 suite.addFactory( new CxFactory( "GetReader1" ) { 126 public Object createImplObject() throws IOException { 127 return cclr; 128 } 129 } ); 130 addSubTest( suite ); 131 } 132 133 134 public void testGetReaderForClassSignature2() throws IOException 135 { 136 String classSig = "a.MyClass-1"; 137 File outdir = CCCreatorUtil.createNewDirectory(); 138 File fd1 = new File ( outdir, "0" ); 139 fd1.mkdirs(); 140 DirectoryChannelLogReader dclr = new DirectoryChannelLogReader( 141 outdir, (short)0 ); 142 final IClassChannelLogReader cclr = dclr. 143 getReaderForClassSignature( classSig ); 144 assertNotNull( 145 "Returned null class channel log reader.", 146 cclr ); 147 assertTrue( 148 "Not correct type (was "+cclr.getClass().getName()+").", 149 cclr instanceof EmptyClassChannelLogReader ); 150 151 InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite(); 152 suite.addFactory( new CxFactory( "GetReader2" ) { 153 public Object createImplObject() throws IOException { 154 return cclr; 155 } 156 } ); 157 addSubTest( suite ); 158 } 159 160 161 164 165 166 169 170 public static Test suite() 171 { 172 InterfaceTestSuite suite = IChannelLogReaderUTestI.suite(); 173 suite.addTestSuite( THIS_CLASS ); 174 suite.addFactory( new CxFactory( "A" ) { 175 public Object createImplObject() throws IOException { 176 File base = CCCreatorUtil.createNewDirectory(); 177 File zero = new File ( base, "0" ); 178 zero.mkdirs(); 179 return new DirectoryChannelLogReader( base, (short)0 ); 180 } 181 } ); 182 183 return suite; 184 } 185 186 public static void main( String [] args ) 187 { 188 String [] name = { THIS_CLASS.getName() }; 189 190 193 junit.textui.TestRunner.main( name ); 194 } 195 196 197 201 protected void setUp() throws Exception 202 { 203 super.setUp(); 204 205 206 } 208 209 210 214 protected void tearDown() throws Exception 215 { 216 218 219 super.tearDown(); 220 } 221 } 222 223 | Popular Tags |