1 package org.hanseltest; 2 3 import java.io.PrintWriter ; 4 import java.io.StringWriter ; 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 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().nextElement(); 22 23 StringWriter sw = new StringWriter (); 24 failure.thrownException().printStackTrace(new PrintWriter (sw)); 25 26 return sw.toString(); 27 } 28 29 32 public void testBug1() { 33 String failure = testToString(BugTest1.suite()); 34 assertTrue(failure.indexOf("Condition 'a >= b' is not fulfilled.") > 0); 35 } 36 37 40 public void testBug2() { 41 String failure = testToString(BugTest2.suite()); 42 assertTrue(failure.indexOf("Condition 'a < b' is not fulfilled.") > 0); 43 } 44 45 public static class BugTest1 extends TestCase { 46 public static Test suite() { 47 return new CoverageDecorator(BugTest1.class, 48 new Class [] {BugExample.class}); 49 } 50 51 52 public void testSomething() { 53 assertEquals(1, new BugExample().cmp(1, 2)); 54 } 55 } 56 57 public static class BugTest2 extends TestCase { 58 public static Test suite() { 59 return new CoverageDecorator(BugTest2.class, 60 new Class [] {BugExample.class}); 61 } 62 63 64 public void testSomething() { 65 assertEquals(0, new BugExample().cmp(2, 1)); 66 } 67 } 68 69 70 public static class BugExample { 71 public int cmp(int a, int b) { 72 if (a < b) { 73 return 1; 74 } else { 75 return 0; 76 } 77 } 78 } 79 } 80 | Popular Tags |