1 package org.hanseltest; 2 3 import junit.framework.TestCase; 4 import junit.framework.TestResult; 5 6 import org.hansel.CoverageDecorator; 7 import org.hansel.Util; 8 9 13 public class TestSimple extends TestCase { 14 15 private static final Class [] COVERED = {CoverSimple.class}; 16 17 21 public TestSimple(String name) { 22 super(name); 23 } 24 25 28 public void testNoCoverage() { 29 CoverageDecorator cd = new CoverageDecorator(NoCoverage.class, 30 COVERED); 31 32 TestResult result = new TestResult(); 33 cd.run(result); 34 35 assertEquals(2, result.failureCount()); 37 38 assertEquals(0, result.errorCount()); 40 } 41 42 46 public void testErrorNoCoverage() { 47 CoverageDecorator cd = new CoverageDecorator(ErrorNoCoverage.class, 48 COVERED); 49 50 TestResult result = new TestResult(); 51 cd.run(result); 52 53 assertEquals(1, result.failureCount()); 55 56 assertEquals(1, result.errorCount()); 58 } 59 60 63 public void testConstructorCoverage() { 64 CoverageDecorator cd = 65 new CoverageDecorator(ConstructorCoverage.class, 66 COVERED); 67 68 TestResult result = new TestResult(); 69 cd.run(result); 70 71 assertEquals(1, result.failureCount()); 72 73 assertEquals(0, result.errorCount()); 75 } 76 77 80 public void testFullCoverage() throws Exception { 81 CoverageDecorator cd = 82 new CoverageDecorator(FullCoverage.class, 83 COVERED); 84 85 TestResult result = new TestResult(); 86 cd.run(result); 87 88 Util.dumpResult(result); 89 assertEquals(0, result.failureCount()); 90 91 assertEquals(0, result.errorCount()); 93 } 94 95 98 public static class NoCoverage extends TestCase { 99 103 public NoCoverage(String name) { 104 super(name); 105 } 106 107 108 public void testNothing() { 109 } 110 } 111 112 116 public static class ErrorNoCoverage extends TestCase { 117 121 public ErrorNoCoverage(String name) { 122 super(name); 123 } 124 125 128 public void testNothing() { 129 throw new UnsupportedOperationException ("Unsupported."); 130 } 131 } 132 133 136 public static class ConstructorCoverage extends TestCase { 137 141 public ConstructorCoverage(String name) { 142 super(name); 143 } 144 145 146 public void testConstructor() { 147 new CoverSimple(); 148 } 149 } 150 151 152 public static class FullCoverage extends TestCase { 153 154 155 public void testFullCoverage() { 156 CoverSimple cs = new CoverSimple(); 157 assertEquals(5, cs.coverSimple()); 158 } 159 } 160 161 } 162 | Popular Tags |