1 package org.hanseltest; 2 3 import junit.framework.TestCase; 4 import junit.framework.TestResult; 5 6 import org.hansel.AssertionCoverageDecorator; 7 import org.hansel.Util; 8 9 16 public class TestAssertions extends TestCase { 17 18 private static final Class [] COVERED = {CoverAssertion.class}; 19 20 24 public TestAssertions(String name) { 25 super(name); 26 } 27 28 32 private static boolean assertionsEnabled() { 33 boolean enabled = false; 34 assert enabled = true; 35 return enabled; 36 } 37 38 41 public void testNoCoverage() { 42 AssertionCoverageDecorator cd = 43 new AssertionCoverageDecorator(NoCoverage.class, 44 COVERED); 45 46 TestResult result = new TestResult(); 47 cd.run(result); 48 49 assertEquals(2, result.failureCount()); 52 53 assertEquals(0, result.errorCount()); 55 } 56 57 60 public void testFullCoverage() { 61 AssertionCoverageDecorator cd = 62 new AssertionCoverageDecorator(FullCoverage.class, 63 COVERED); 64 65 TestResult result = new TestResult(); 66 cd.run(result); 67 68 69 Util.dumpResult(result); 70 71 assertEquals(0, result.failureCount()); 73 74 assertEquals(0, result.errorCount()); 76 } 77 78 81 public static class NoCoverage extends TestCase { 82 86 public NoCoverage(String name) { 87 super(name); 88 } 89 90 91 public void testNothing() { 92 } 93 } 94 95 98 public static class FullCoverage extends TestCase { 99 103 public FullCoverage(String name) { 104 super(name); 105 } 106 107 108 public void testAll() { 109 CoverAssertion ca = new CoverAssertion(); 110 assertEquals(2, ca.coverAssertion(2)); 111 112 if (assertionsEnabled()) { 113 try { 114 ca.coverAssertion(-1); 115 } catch (AssertionError e) { 116 } 118 } else { 119 assertEquals(-1, ca.coverAssertion(-1)); 120 } 121 } 122 } 123 } 124 | Popular Tags |