1 26 27 package net.sourceforge.groboutils.junit.v1.parser; 28 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 import java.io.IOException ; 34 import java.lang.reflect.Method ; 35 import java.util.Vector ; 36 37 38 45 public class TestClassParserUTest extends TestCase 46 { 47 50 private static final Class THIS_CLASS = TestClassParserUTest.class; 51 53 public TestClassParserUTest( String name ) 54 { 55 super( name ); 56 } 57 58 59 60 61 64 65 public void testConstructor1() 66 { 67 try 68 { 69 new TestClassParser( null ); 70 } 71 catch (IllegalArgumentException e) 72 { 73 } 75 } 76 77 78 public void testConstructor2() 79 { 80 new TestClassParser( getClass() ); 81 } 82 83 84 public static class TesterNoTestMethods implements Test 85 { 86 public int countTestCases() { return 0; } 87 public void run( junit.framework.TestResult tr ) {} 88 } 89 90 91 public static class TesterOneTestMethod implements Test 92 { 93 public int countTestCases() { return 0; } 94 public void run( junit.framework.TestResult tr ) {} 95 96 public void testMyTest() {} 97 } 98 99 100 101 102 public static class TesterBadMethod implements Test 103 { 104 public int countTestCases() { return 0; } 105 public void run( junit.framework.TestResult tr ) {} 106 107 public void usedForTesting() 108 { 109 } 110 111 protected void testUsedForTesting() 112 {} 113 } 114 115 116 117 private class StaticClass {} 118 public class InnerClass {} 119 120 public void testGetTestMethods1() 121 { 122 TestClassParser tcp = new TestClassParser( String .class ); 123 Method m[] = tcp.getTestMethods(); 124 assertNotNull( 125 "Must never return null.", 126 m ); 127 assertEquals( 128 "String should have no test methods.", 129 0, 130 m.length ); 131 assertTrue( 132 "Must never return the same array, but rather a copy.", 133 m != tcp.getTestMethods() ); 134 } 135 136 public void testGetTestMethods2() 137 { 138 TestClassParser tcp = new TestClassParser( Runnable .class ); 139 Method m[] = tcp.getTestMethods(); 140 assertNotNull( 141 "Must never return null.", 142 m ); 143 assertEquals( 144 "Runnable should have no test methods.", 145 0, 146 m.length ); 147 assertTrue( 148 "Must never return the same array, but rather a copy.", 149 m != tcp.getTestMethods() ); 150 } 151 152 public void testGetTestMethods3() 153 { 154 TestClassParser tcp = new TestClassParser( StaticClass.class ); 155 Method m[] = tcp.getTestMethods(); 156 assertNotNull( 157 "Must never return null.", 158 m ); 159 assertEquals( 160 "Runnable should have no test methods.", 161 0, 162 m.length ); 163 assertTrue( 164 "Must never return the same array, but rather a copy.", 165 m != tcp.getTestMethods() ); 166 } 167 168 public void testGetTestMethods4() 169 { 170 TestClassParser tcp = new TestClassParser( InnerClass.class ); 171 Method m[] = tcp.getTestMethods(); 172 assertNotNull( 173 "Must never return null.", 174 m ); 175 assertEquals( 176 "Runnable should have no test methods.", 177 0, 178 m.length ); 179 assertTrue( 180 "Must never return the same array, but rather a copy.", 181 m != tcp.getTestMethods() ); 182 } 183 184 public void testGetTestMethods5() 185 { 186 TestClassParser tcp = new TestClassParser( TesterNoTestMethods.class ); 187 Method m[] = tcp.getTestMethods(); 188 assertNotNull( 189 "Must never return null.", 190 m ); 191 assertEquals( 192 "Runnable should have no test methods.", 193 0, 194 m.length ); 195 assertTrue( 196 "Must never return the same array, but rather a copy.", 197 m != tcp.getTestMethods() ); 198 } 199 200 public void testGetTestMethods6() 201 { 202 TestClassParser tcp = new TestClassParser( TesterOneTestMethod.class ); 203 Method m[] = tcp.getTestMethods(); 204 assertNotNull( 205 "Must never return null.", 206 m ); 207 assertEquals( 208 "Runnable should have one test method.", 209 1, 210 m.length ); 211 assertTrue( 212 "Must never return the same array, but rather a copy.", 213 m != tcp.getTestMethods() ); 214 } 215 216 public void testClearWarnings1() 217 { 218 TestClassParser tcp = new TestClassParser( TesterOneTestMethod.class ); 219 tcp.clearWarnings(); 220 } 221 222 public void testClearWarnings2() 223 { 224 TestClassParser tcp = new TestClassParser( Object .class ); 225 tcp.clearWarnings(); 226 } 227 228 public void testGetName1() 229 { 230 TestClassParser tcp = new TestClassParser( TesterOneTestMethod.class ); 231 String name = tcp.getName(); 232 assertEquals( 233 "Returned invalid test name.", 234 TesterOneTestMethod.class.getName(), 235 name ); 236 } 237 238 public void testGetName2() 239 { 240 TestClassParser tcp = new TestClassParser( Object .class ); 241 String name = tcp.getName(); 242 assertEquals( 243 "Returned invalid test name.", 244 Object .class.getName(), 245 name ); 246 } 247 248 public void testAddTestMethod1() throws Exception 249 { 250 TestClassParser tcp = new TestClassParser( TesterOneTestMethod.class ); 251 int warningCount = tcp.getWarnings().length; 252 Vector v = new Vector (); 253 Method m = THIS_CLASS.getMethod( "testAddTestMethod1", new Class [0] ); 254 v.addElement( "testAddTestMethod1" ); 255 tcp.addTestMethod( m, v ); 256 257 assertEquals( 259 "Incorrectly changed the warnings.", 260 warningCount, 261 tcp.getWarnings().length ); 262 } 263 264 public void testAddTestMethod2() throws Exception 265 { 266 TestClassParser tcp = new TestClassParser( TesterBadMethod.class ); 267 int warningCount = tcp.getWarnings().length; 268 Vector v = new Vector (); 269 Method m = TesterBadMethod.class.getMethod( "usedForTesting", new Class [0] ); 270 tcp.addTestMethod( m, v ); 271 272 assertEquals( 274 "Incorrectly changed the warnings.", 275 warningCount, 276 tcp.getWarnings().length ); 277 } 278 279 323 protected void setUp() throws Exception 324 { 325 super.setUp(); 326 327 } 329 330 331 335 protected void tearDown() throws Exception 336 { 337 339 340 super.tearDown(); 341 } 342 } 343 344 | Popular Tags |