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 14 public class TestIf extends TestCase { 15 16 private static final Class [] COVERED = {CoverIf.class}; 17 18 22 public TestIf(String name) { 23 super(name); 24 } 25 26 29 public void testNoCoverage() { 30 CoverageDecorator cd = new CoverageDecorator(NoCoverage.class, 31 COVERED); 32 33 TestResult result = new TestResult(); 34 35 cd.run(result); 36 37 assertEquals(5, result.failureCount()); 39 40 assertEquals(0, result.errorCount()); 42 } 43 44 48 public void testPartCoverage1() { 49 CoverageDecorator cd = new CoverageDecorator(PartCoverage1.class, 50 COVERED); 51 52 TestResult result = new TestResult(); 53 54 cd.run(result); 55 56 assertEquals(3, result.failureCount()); 58 59 assertEquals(0, result.errorCount()); 61 } 62 63 67 public void testPartCoverage2() { 68 CoverageDecorator cd = new CoverageDecorator(PartCoverage2.class, 69 COVERED); 70 71 TestResult result = new TestResult(); 72 73 cd.run(result); 74 75 org.hansel.Util.dumpResult(result); 76 assertEquals(3, result.failureCount()); 82 83 assertEquals(0, result.errorCount()); 85 } 86 87 90 public void testFullCoverage() { 91 CoverageDecorator cd = new CoverageDecorator(FullCoverage.class, 92 COVERED); 93 94 TestResult result = new TestResult(); 95 96 cd.run(result); 97 98 Util.dumpResult(result); 99 assertEquals(0, result.failureCount()); 101 102 assertEquals(0, result.errorCount()); 104 } 105 106 109 public static class NoCoverage extends TestCase { 110 114 public NoCoverage(String name) { 115 super(name); 116 } 117 118 119 public void testNothing() { 120 } 121 } 122 123 126 public static class PartCoverage1 extends TestCase { 127 131 public PartCoverage1(String name) { 132 super(name); 133 } 134 135 136 public void testAll() { 137 System.out.println("Probetable class: " + org.hansel.ProbeTable.class); 138 CoverIf ci = new CoverIf(); 139 140 assertEquals(0, ci.simpleIf(false)); 141 assertEquals(4, ci.ifElse(false)); 142 143 assertEquals(1, ci.nestedIf(true, true)); 144 assertEquals(2, ci.nestedIf(true, false)); 145 assertEquals(3, ci.nestedIf(false, true)); 146 assertEquals(4, ci.nestedIf(false, false)); 147 } 148 149 } 150 151 155 public static class PartCoverage2 extends TestCase { 156 160 public PartCoverage2(String name) { 161 super(name); 162 } 163 164 165 public void testAll() { 166 CoverIf ci = new CoverIf(); 167 168 assertEquals(0, ci.simpleIf(false)); 170 assertEquals(1, ci.simpleIf(true)); 171 assertEquals(4, ci.ifElse(false)); 172 assertEquals(3, ci.ifElse(true)); 173 174 assertEquals(1, ci.nestedIf(true, true)); 176 } 177 178 } 179 180 183 public static class FullCoverage extends TestCase { 184 188 public FullCoverage(String name) { 189 super(name); 190 } 191 192 193 public void testAll() { 194 CoverIf ci = new CoverIf(); 195 196 assertEquals(0, ci.simpleIf(false)); 197 assertEquals(1, ci.simpleIf(true)); 198 199 assertEquals(4, ci.ifElse(false)); 200 assertEquals(3, ci.ifElse(true)); 201 202 assertEquals(1, ci.nestedIf(true, true)); 203 assertEquals(2, ci.nestedIf(true, false)); 204 assertEquals(3, ci.nestedIf(false, true)); 205 assertEquals(4, ci.nestedIf(false, false)); 206 207 assertEquals(0, ci.ifPointer(null, null)); 208 assertEquals(1, ci.ifPointer(new Object (), null)); 209 } 210 } 211 212 213 214 } 215 | Popular Tags |