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 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().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 testBug() { 33 String failure = testToString(BugTest.suite()); 34 assertTrue(failure.indexOf("Condition '!(obj1 instanceof java.lang.String)' is not fulfilled.") > 0); 35 } 36 37 public static class BugTest extends TestCase { 38 public static Test suite() { 39 return new CoverageDecorator(BugTest.class, 40 new Class [] {BugExample.class}); 41 } 42 43 44 public void testSomething() { 45 assertEquals(1, new BugExample().instanceOf("test")); 46 } 47 } 48 49 50 public static class BugExample { 51 public int instanceOf(Object obj1) { 52 if (obj1 instanceof java.lang.String ) { 53 return 1; 54 } else { 55 return 0; 56 } 57 } 58 } 59 } 60 | Popular Tags |