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 TestBug758304 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 testBug1() {
34: String failure = testToString(BugTest1.suite());
35: assertTrue(failure
36: .indexOf("Condition 'a >= b' is not fulfilled.") > 0);
37: }
38:
39: /**
40: * Try to reproduce the bug.
41: */
42: public void testBug2() {
43: String failure = testToString(BugTest2.suite());
44: assertTrue(failure
45: .indexOf("Condition 'a < b' is not fulfilled.") > 0);
46: }
47:
48: public static class BugTest1 extends TestCase {
49: public static Test suite() {
50: return new CoverageDecorator(BugTest1.class,
51: new Class[] { BugExample.class });
52: }
53:
54: /** The test will fail, if no tests are provided. */
55: public void testSomething() {
56: assertEquals(1, new BugExample().cmp(1, 2));
57: }
58: }
59:
60: public static class BugTest2 extends TestCase {
61: public static Test suite() {
62: return new CoverageDecorator(BugTest2.class,
63: new Class[] { BugExample.class });
64: }
65:
66: /** The test will fail, if no tests are provided. */
67: public void testSomething() {
68: assertEquals(0, new BugExample().cmp(2, 1));
69: }
70: }
71:
72: /** Example class to be covered. */
73: public static class BugExample {
74: public int cmp(int a, int b) {
75: if (a < b) {
76: return 1;
77: } else {
78: return 0;
79: }
80: }
81: }
82: }
|