001: /*
002: * @(#)CoveragePostCompilerTaskUTest.java
003: *
004: * Copyright (C) 2004 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.ant;
028:
029: import java.io.File;
030: import java.io.IOException;
031: import java.util.Properties;
032:
033: import junit.framework.Test;
034: import junit.framework.TestSuite;
035: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
036:
037: /**
038: * Tests the CoveragePostCompilerTask class.
039: *
040: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
041: * @version $Date: 2004/04/15 05:48:27 $
042: * @since February 25, 2004
043: */
044: public class CoveragePostCompilerTaskUTest extends AntTestA {
045: //-------------------------------------------------------------------------
046: // Standard JUnit Class-specific declarations
047:
048: private static final Class THIS_CLASS = CoveragePostCompilerTaskUTest.class;
049: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
050:
051: public CoveragePostCompilerTaskUTest(String name) {
052: super (name);
053: }
054:
055: //-------------------------------------------------------------------------
056: // Tests
057:
058: private static final Properties EXPECTED_1 = new Properties();
059: static {
060: EXPECTED_1
061: .setProperty(
062: "factory",
063: "net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLoggerFactory");
064: EXPECTED_1.setProperty("channel-count", "16");
065: }
066:
067: public void testConfiguration1() throws IOException {
068: CoveragePostCompilerTask.Configuration c = new CoveragePostCompilerTask.Configuration();
069: addTempFile(new File("./grobocoverage.properties"));
070: c.generatePropertyFile(new File("."), 16);
071: Properties actual = loadGroboProperties();
072: assertEquals("default values weren't set right", EXPECTED_1,
073: actual);
074: }
075:
076: private static final Properties EXPECTED_2 = new Properties();
077: static {
078: EXPECTED_2
079: .setProperty(
080: "factory",
081: "net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLoggerFactory");
082: EXPECTED_2.setProperty("channel-count", "17");
083: EXPECTED_2.setProperty("logger.cache-size", "333");
084: }
085:
086: public void testConfiguration2() throws IOException {
087: DOC.getIT().testsIssue(903797);
088:
089: CoveragePostCompilerTask.Configuration c = new CoveragePostCompilerTask.Configuration();
090: c.setCacheSize(333);
091:
092: addTempFile(new File("./grobocoverage.properties"));
093: c.generatePropertyFile(new File("."), 17);
094: Properties actual = loadGroboProperties();
095: assertEquals("cache-size set values weren't set right",
096: EXPECTED_2, actual);
097: }
098:
099: //-------------------------------------------------------------------------
100: // Helpers
101:
102: protected void assertEquals(String text, Properties expected,
103: Properties actual) {
104: PropertyCheckUtil.assertEquals(text, expected, actual);
105: }
106:
107: protected Properties loadGroboProperties() throws IOException {
108: return PropertyCheckUtil.loadGroboProperties();
109: }
110:
111: protected Properties loadProperties(String file) throws IOException {
112: return PropertyCheckUtil.loadProperties(file);
113: }
114:
115: //-------------------------------------------------------------------------
116: // Standard JUnit declarations
117:
118: public static Test suite() {
119: TestSuite suite = new TestSuite(THIS_CLASS);
120:
121: return suite;
122: }
123:
124: public static void main(String[] args) {
125: String[] name = { THIS_CLASS.getName() };
126:
127: // junit.textui.TestRunner.main( name );
128: // junit.swingui.TestRunner.main( name );
129:
130: junit.textui.TestRunner.main(name);
131: }
132:
133: /**
134: *
135: * @exception Exception thrown under any exceptional condition.
136: */
137: protected void setUp() throws Exception {
138: super .setUp();
139:
140: // set ourself up
141: configureProject("postcompiler.xml");
142: }
143:
144: /**
145: *
146: * @exception Exception thrown under any exceptional condition.
147: */
148: protected void tearDown() throws Exception {
149: // tear ourself down
150:
151: super.tearDown();
152: }
153: }
|