001: /*
002: * @(#)DirectoryChannelLogReaderUTest.java
003: *
004: * Copyright (C) 2003-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.logger;
028:
029: import java.io.File;
030: import java.io.FileWriter;
031: import java.io.IOException;
032:
033: import junit.framework.Test;
034: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
035: import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
036: import net.sourceforge.groboutils.codecoverage.v2.IChannelLogReaderUTestI;
037: import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReader;
038: import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReaderUTestI;
039: import net.sourceforge.groboutils.junit.v1.SubTestTestCase;
040: import net.sourceforge.groboutils.junit.v1.iftc.CxFactory;
041: import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
042:
043: /**
044: * Tests the DirectoryChannelLogReader class.
045: *
046: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
047: * @version $Date: 2004/07/07 09:39:13 $
048: * @since January 22, 2003
049: */
050: public class DirectoryChannelLogReaderUTest extends SubTestTestCase {
051: //-------------------------------------------------------------------------
052: // Standard JUnit Class-specific declarations
053:
054: private static final Class THIS_CLASS = DirectoryChannelLogReaderUTest.class;
055: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
056:
057: public DirectoryChannelLogReaderUTest(String name) {
058: super (name);
059: }
060:
061: //-------------------------------------------------------------------------
062: // Tests
063:
064: public void testConstructor1() throws Exception {
065: Thread.sleep(100);
066: File base = new File(".", Long.toString(System
067: .currentTimeMillis()));
068: try {
069: new DirectoryChannelLogReader(base, (short) 0);
070: fail("Didn't throw IllegalArgumentException.");
071: } catch (IllegalArgumentException ex) {
072: // test exception
073: }
074: }
075:
076: public void testConstructor2() throws Exception {
077: Thread.sleep(100);
078: File base = CCCreatorUtil.createNewDirectory();
079: try {
080: new DirectoryChannelLogReader(base, (short) 0);
081: fail("Didn't throw IllegalArgumentException.");
082: } catch (IllegalArgumentException ex) {
083: // test exception
084: }
085: }
086:
087: public void testGetReaderForClassSignature1() throws IOException {
088: String classSig = "a.MyClass-1";
089: File outdir = CCCreatorUtil.createNewDirectory();
090: File fd1 = new File(outdir, "0");
091: fd1.mkdirs();
092: File cd1 = new File(fd1, classSig
093: + DirectoryChannelLogger.CLASS_LOG_EXTENTION);
094: FileWriter fw = new FileWriter(cd1);
095: fw.write("0001 0002\n");
096: fw.close();
097: DirectoryChannelLogReader dclr = new DirectoryChannelLogReader(
098: outdir, (short) 0);
099: final IClassChannelLogReader cclr = dclr
100: .getReaderForClassSignature(classSig);
101: assertNotNull("Returned null class channel log reader.", cclr);
102: assertTrue("Not correct type (was " + cclr.getClass().getName()
103: + ").", cclr instanceof DirectoryClassChannelLogReader);
104:
105: InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite();
106: suite.addFactory(new CxFactory("GetReader1") {
107: public Object createImplObject() throws IOException {
108: return cclr;
109: }
110: });
111: addSubTest(suite);
112: }
113:
114: public void testGetReaderForClassSignature2() throws IOException {
115: String classSig = "a.MyClass-1";
116: File outdir = CCCreatorUtil.createNewDirectory();
117: File fd1 = new File(outdir, "0");
118: fd1.mkdirs();
119: DirectoryChannelLogReader dclr = new DirectoryChannelLogReader(
120: outdir, (short) 0);
121: final IClassChannelLogReader cclr = dclr
122: .getReaderForClassSignature(classSig);
123: assertNotNull("Returned null class channel log reader.", cclr);
124: assertTrue("Not correct type (was " + cclr.getClass().getName()
125: + ").", cclr instanceof EmptyClassChannelLogReader);
126:
127: InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite();
128: suite.addFactory(new CxFactory("GetReader2") {
129: public Object createImplObject() throws IOException {
130: return cclr;
131: }
132: });
133: addSubTest(suite);
134: }
135:
136: //-------------------------------------------------------------------------
137: // Helpers
138:
139: //-------------------------------------------------------------------------
140: // Standard JUnit declarations
141:
142: public static Test suite() {
143: InterfaceTestSuite suite = IChannelLogReaderUTestI.suite();
144: suite.addTestSuite(THIS_CLASS);
145: suite.addFactory(new CxFactory("A") {
146: public Object createImplObject() throws IOException {
147: File base = CCCreatorUtil.createNewDirectory();
148: File zero = new File(base, "0");
149: zero.mkdirs();
150: return new DirectoryChannelLogReader(base, (short) 0);
151: }
152: });
153:
154: return suite;
155: }
156:
157: public static void main(String[] args) {
158: String[] name = { THIS_CLASS.getName() };
159:
160: // junit.textui.TestRunner.main( name );
161: // junit.swingui.TestRunner.main( name );
162:
163: junit.textui.TestRunner.main(name);
164: }
165:
166: /**
167: *
168: * @exception Exception thrown under any exceptional condition.
169: */
170: protected void setUp() throws Exception {
171: super .setUp();
172:
173: // set ourself up
174: }
175:
176: /**
177: *
178: * @exception Exception thrown under any exceptional condition.
179: */
180: protected void tearDown() throws Exception {
181: // tear ourself down
182:
183: super.tearDown();
184: }
185: }
|