KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestBug747017


1 package org.hanseltest;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.io.StringWriter JavaDoc;
5
6 import junit.framework.Test;
7 import junit.framework.TestCase;
8 import junit.framework.TestFailure;
9 import junit.framework.TestResult;
10
11 import org.hansel.CoverageDecorator;
12
13 /**
14  * Test for Bug 747017. For inner classes the *.java file is called
15  * MainClass.java not MainClass$InnerClass.java.
16  *
17  * @author Niklas Mehner
18  */

19 public class TestBug747017 extends TestCase {
20     /**
21      * Try to reproduce the bug.
22      */

23     public void testBug() {
24         Test test = BugTest.suite();
25         TestResult result = new TestResult();
26         test.run(result);
27
28         assertEquals(1, result.failureCount());
29
30         TestFailure failure = (TestFailure) result.failures().nextElement();
31
32         StringWriter JavaDoc sw = new StringWriter JavaDoc();
33         failure.thrownException().printStackTrace(new PrintWriter JavaDoc(sw));
34
35         assertEquals(sw.toString().indexOf("$BugExample.java"), -1);
36     }
37
38     public static class BugTest extends TestCase {
39         public static Test suite() {
40             return new CoverageDecorator(BugTest.class,
41                                          new Class JavaDoc[] {BugExample.class});
42         }
43         
44         /** The test will fail, if no tests are provided. */
45         public void testSomething() {
46         }
47     }
48
49     /** Example class to be covered. */
50     public static class BugExample {
51         public BugExample(String JavaDoc someString) {
52         }
53     }
54 }
55
Popular Tags