1 package org.hanseltest; 2 3 import junit.framework.TestCase; 4 import junit.framework.TestResult; 5 6 import org.hansel.CoverageDecorator; 7 8 13 public class TestFor extends TestCase { 14 15 private static final Class [] COVERED = {CoverFor.class}; 16 17 21 public TestFor(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 34 cd.run(result); 35 36 assertEquals(3, result.failureCount()); 38 39 assertEquals(0, result.errorCount()); 41 } 42 43 47 public void testPartCoverage1() { 48 CoverageDecorator cd = new CoverageDecorator(PartCoverage1.class, 49 COVERED); 50 51 TestResult result = new TestResult(); 52 53 cd.run(result); 54 55 assertEquals(1, result.failureCount()); 57 58 assertEquals(0, result.errorCount()); 60 } 61 62 66 public void testPartCoverage2() { 67 CoverageDecorator cd = new CoverageDecorator(PartCoverage2.class, 68 COVERED); 69 70 TestResult result = new TestResult(); 71 72 cd.run(result); 73 74 assertEquals(1, result.failureCount()); 77 78 assertEquals(0, result.errorCount()); 80 } 81 82 85 public void testFullCoverage() { 86 CoverageDecorator cd = new CoverageDecorator(FullCoverage.class, 87 COVERED); 88 89 TestResult result = new TestResult(); 90 91 cd.run(result); 92 93 assertEquals(0, result.failureCount()); 95 96 assertEquals(0, result.errorCount()); 98 } 99 100 103 public static class NoCoverage extends TestCase { 104 108 public NoCoverage(String name) { 109 super(name); 110 } 111 112 113 public void testNothing() { 114 } 115 } 116 117 120 public static class PartCoverage1 extends TestCase { 121 125 public PartCoverage1(String name) { 126 super(name); 127 } 128 129 130 public void testAll() { 131 CoverFor ci = new CoverFor(); 132 133 assertEquals(9, ci.simpleFor(4)); 134 } 135 136 } 137 138 142 public static class PartCoverage2 extends TestCase { 143 147 public PartCoverage2(String name) { 148 super(name); 149 } 150 151 152 public void testAll() { 153 CoverFor ci = new CoverFor(); 154 155 assertEquals(5, ci.simpleFor(0)); 156 assertEquals(9, ci.simpleFor(4)); 157 158 assertEquals(5, ci.expressionFor(0, 0)); 159 assertEquals(9, ci.expressionFor(4, 8)); 160 } 161 162 } 163 164 167 public static class FullCoverage extends TestCase { 168 172 public FullCoverage(String name) { 173 super(name); 174 } 175 176 177 public void testAll() { 178 CoverFor ci = new CoverFor(); 179 180 assertEquals(5, ci.simpleFor(0)); 181 assertEquals(9, ci.simpleFor(4)); 182 183 assertEquals(5, ci.expressionFor(0, 0)); 184 assertEquals(9, ci.expressionFor(4, 8)); 185 assertEquals(10, ci.expressionFor(8, 5)); 186 } 187 } 188 189 190 191 } 192 | Popular Tags |