001: package org.hanseltest;
002:
003: import junit.framework.TestCase;
004: import junit.framework.TestResult;
005:
006: import org.hansel.CoverageDecorator;
007:
008: /**
009: * Tests coverage of exception handlers.
010: * @author Niklas Mehner
011: */
012: public class TestException extends TestCase {
013: /** Class to be covered. */
014: private static final Class[] COVERED = { CoverException.class };
015:
016: /**
017: * Creates a new test.
018: * @param name Name of the test.
019: */
020: public TestException(String name) {
021: super (name);
022: }
023:
024: /**
025: * No code is covered.
026: */
027: public void testNoCoverage() {
028: CoverageDecorator cd = new CoverageDecorator(NoCoverage.class,
029: COVERED);
030:
031: TestResult result = new TestResult();
032:
033: cd.run(result);
034: //org.hansel.Util.dumpResult(result);
035: assertEquals(4, result.failureCount());
036: assertEquals(0, result.errorCount());
037: }
038:
039: /** Tests only a part of the handlers. */
040: public void testPartCoverage1() {
041: CoverageDecorator cd = new CoverageDecorator(
042: PartCoverage1.class, COVERED);
043:
044: TestResult result = new TestResult();
045:
046: cd.run(result);
047:
048: //org.hansel.Util.dumpResult(result);
049: assertEquals(4, result.failureCount());
050: assertEquals(0, result.errorCount());
051: }
052:
053: /** Tests only a part of the handlers. */
054: public void testPartCoverage2() {
055: CoverageDecorator cd = new CoverageDecorator(
056: PartCoverage2.class, COVERED);
057:
058: TestResult result = new TestResult();
059:
060: cd.run(result);
061:
062: //org.hansel.Util.dumpResult(result);
063: assertEquals(3, result.failureCount());
064: assertEquals(0, result.errorCount());
065: }
066:
067: /** Does not cover any code. */
068: public static class NoCoverage extends TestCase {
069: /**
070: * Creates a new test.
071: * @param name Name of the test.
072: */
073: public NoCoverage(String name) {
074: super (name);
075: }
076:
077: /** Empty method. */
078: public void testNothing() {
079: }
080: }
081:
082: /** Only partly covers the code. */
083: public static class PartCoverage1 extends TestCase {
084: /**
085: * Creates a new test.
086: * @param name Name of the test.
087: */
088: public PartCoverage1(String name) {
089: super (name);
090: }
091:
092: /** Tests a part of the CoverException class. */
093: public void testPart() {
094: assertEquals(0, new CoverException().coverFinally(3, false));
095: }
096: }
097:
098: /** Only partly covers the code. */
099: public static class PartCoverage2 extends TestCase {
100: /**
101: * Creates a new test.
102: * @param name Name of the test.
103: */
104: public PartCoverage2(String name) {
105: super (name);
106: }
107:
108: /** Tests a part of the CoverException class. */
109: public void testPart() {
110: assertEquals(1, new CoverException().coverHandler(3));
111: }
112: }
113:
114: }
|