01: package org.hanseltest;
02:
03: import java.io.PrintWriter;
04: import java.io.StringWriter;
05:
06: import junit.framework.Test;
07: import junit.framework.TestCase;
08: import junit.framework.TestFailure;
09: import junit.framework.TestResult;
10:
11: import org.hansel.CoverageDecorator;
12:
13: public class TestBug755797 extends TestCase {
14:
15: private String testToString(Test test) {
16: TestResult result = new TestResult();
17: test.run(result);
18:
19: assertEquals(1, result.failureCount());
20:
21: TestFailure failure = (TestFailure) result.failures()
22: .nextElement();
23:
24: StringWriter sw = new StringWriter();
25: failure.thrownException().printStackTrace(new PrintWriter(sw));
26:
27: return sw.toString();
28: }
29:
30: /**
31: * Try to reproduce the bug.
32: */
33: public void testBug() {
34: String failure = testToString(BugTest.suite());
35: assertTrue(failure
36: .indexOf("Condition '!(obj1 instanceof java.lang.String)' is not fulfilled.") > 0);
37: }
38:
39: public static class BugTest extends TestCase {
40: public static Test suite() {
41: return new CoverageDecorator(BugTest.class,
42: new Class[] { BugExample.class });
43: }
44:
45: /** The test will fail, if no tests are provided. */
46: public void testSomething() {
47: assertEquals(1, new BugExample().instanceOf("test"));
48: }
49: }
50:
51: /** Example class to be covered. */
52: public static class BugExample {
53: public int instanceOf(Object obj1) {
54: if (obj1 instanceof java.lang.String) {
55: return 1;
56: } else {
57: return 0;
58: }
59: }
60: }
61: }
|