001: package org.hanseltest;
002:
003: import junit.framework.TestCase;
004: import junit.framework.TestResult;
005:
006: import org.hansel.CoverageDecorator;
007:
008: /**
009: * Test coverage of expressions.
010: *
011: * @author Niklas Mehner
012: */
013: public class TestExpression extends TestCase {
014: /** Class that should be covered by the tests. */
015: private static final Class[] COVERED = { CoverExpression.class };
016:
017: /**
018: * Creates a new TestCase.
019: * @param name Name of the test.
020: */
021: public TestExpression(String name) {
022: super (name);
023: }
024:
025: /**
026: * No code is covered.
027: */
028: public void testNoCoverage() {
029: CoverageDecorator cd = new CoverageDecorator(NoCoverage.class,
030: COVERED);
031:
032: TestResult result = new TestResult();
033:
034: cd.run(result);
035:
036: // 5 Failures: 4 Methods and 1 Constructor
037: assertEquals(5, result.failureCount());
038:
039: // No errors
040: assertEquals(0, result.errorCount());
041: }
042:
043: /**
044: * Validate that a test covering all of the code, does not cause
045: * any coverage failures or errors.
046: */
047: public void testFullCoverage() {
048: CoverageDecorator cd = new CoverageDecorator(
049: FullCoverage.class, COVERED);
050:
051: TestResult result = new TestResult();
052:
053: cd.run(result);
054:
055: assertEquals(0, result.failureCount());
056:
057: // No errors
058: assertEquals(0, result.errorCount());
059: }
060:
061: /** Does not cover any code. */
062: public static class NoCoverage extends TestCase {
063:
064: /**
065: * Creates a new test.
066: * @param name Name of the test.
067: */
068: public NoCoverage(String name) {
069: super (name);
070: }
071:
072: /**
073: * Tests nothing.
074: */
075: public void testNothing() {
076: }
077: }
078:
079: /**
080: * Test for full coverage.
081: */
082: public static class FullCoverage extends TestCase {
083:
084: /**
085: * Creates a new test.
086: * @param name Name of the test.
087: */
088: public FullCoverage(String name) {
089: super (name);
090: }
091:
092: /**
093: * tests everything.
094: */
095: public void testAll() {
096: CoverExpression ce = new CoverExpression();
097: assertTrue(ce.coverNot(false));
098: assertTrue(!ce.coverNot(true));
099:
100: assertTrue(ce.coverAnd(true, true));
101: assertTrue(!ce.coverAnd(false, true));
102: assertTrue(!ce.coverAnd(true, false));
103:
104: assertTrue(ce.coverOr(true, false));
105: assertTrue(!ce.coverOr(false, false));
106: assertTrue(ce.coverOr(false, true));
107:
108: assertTrue(ce.coverComplex(true, true, true, true));
109: assertTrue(!ce.coverComplex(false, false, false, false));
110: assertTrue(ce.coverComplex(true, false, true, true));
111: assertTrue(!ce.coverComplex(true, false, true, false));
112: }
113: }
114:
115: }
|