001: /*
002: * @(#)AnalysisModuleSetIOUTest.java
003: *
004: * Copyright (C) 2003 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.datastore;
028:
029: import java.io.IOException;
030: import java.io.StringReader;
031: import java.io.StringWriter;
032:
033: import junit.framework.Test;
034: import junit.framework.TestCase;
035: import junit.framework.TestSuite;
036: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
037: import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
038: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
039:
040: /**
041: * Tests the AnalysisModuleSetIO class.
042: *
043: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
044: * @version $Date: 2004/04/15 05:48:28 $
045: * @since January 7, 2003
046: */
047: public class AnalysisModuleSetIOUTest extends TestCase {
048: //-------------------------------------------------------------------------
049: // Standard JUnit Class-specific declarations
050:
051: private static final Class THIS_CLASS = AnalysisModuleSetIOUTest.class;
052: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
053:
054: public AnalysisModuleSetIOUTest(String name) {
055: super (name);
056: }
057:
058: //-------------------------------------------------------------------------
059: // Tests
060:
061: public void testWriteAnalysisModuleSet1() throws Exception {
062: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
063: StringWriter sw = new StringWriter();
064: AnalysisModuleSet ams = new AnalysisModuleSet();
065:
066: amsio.writeAnalysisModuleSet(ams, sw);
067:
068: String res = sw.toString();
069: DOC.getLog().info("Wrote module set [" + res + "]");
070: assertEquals("Incorrect result format.", "0{}", res);
071: }
072:
073: public void testWriteAnalysisModuleSet2() throws Exception {
074: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
075: StringWriter sw = new StringWriter();
076: AnalysisModuleSet ams = createAnalysisModuleSet(new IAnalysisModule[] { createIAnalysisModule(
077: "n", "u", "m"), });
078:
079: amsio.writeAnalysisModuleSet(ams, sw);
080:
081: String res = sw.toString();
082: DOC.getLog().info("Wrote module set [" + res + "]");
083: assertEquals("Incorrect result format.",
084: "1{[0;11;1:n,1:u,1:m]}", res);
085: }
086:
087: public void testWriteAnalysisModuleSet3() throws Exception {
088: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
089: StringWriter sw = new StringWriter();
090: AnalysisModuleSet ams = createAnalysisModuleSet(new IAnalysisModule[] {
091: createIAnalysisModule("n", "u", "m"),
092: createIAnalysisModule("", "", ""),
093: createIAnalysisModule("aaaa", "bbbb", "1234"), });
094:
095: amsio.writeAnalysisModuleSet(ams, sw);
096:
097: String res = sw.toString();
098: DOC.getLog().info("Wrote module set [" + res + "]");
099: assertEquals(
100: "Incorrect result format.",
101: "3{[0;11;1:n,1:u,1:m][1;8;0:,0:,0:][2;20;4:aaaa,4:bbbb,4:1234]}",
102: res);
103: }
104:
105: public void testReadAnalysisModuleSet1() throws Exception {
106: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
107: StringReader sr = new StringReader("0{}");
108: AnalysisModuleSet ams = amsio.readAnalysisModuleSet(sr);
109: IAnalysisModule[] amL = ams.getAnalysisModules();
110: assertNotNull("Returned null data list.", amL);
111: assertEquals("Did not return an empty data set.", 0, amL.length);
112: }
113:
114: public void testReadAnalysisModuleSet2() throws Exception {
115: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
116: StringReader sr = new StringReader("1{[0;11;1:n,1:u,1:m]}");
117: AnalysisModuleSet ams = amsio.readAnalysisModuleSet(sr);
118: IAnalysisModule[] amL = ams.getAnalysisModules();
119: assertNotNull("Returned null data list.", amL);
120: assertEquals("Did not return an empty data set.", 1, amL.length);
121: IAnalysisModule am = amL[0];
122: assertNotNull("Returned null module 0.", am);
123: assertEquals("name incorrect.", "n", am.getMeasureName());
124: assertEquals("unit incorrect.", "u", am.getMeasureUnit());
125: assertEquals("encoding incorrect.", "m", am.getMimeEncoding());
126: }
127:
128: public void testReadAnalysisModuleSet3() throws Exception {
129: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
130: StringReader sr = new StringReader(
131: "2{[0;11;1:n,1:u,1:m][1;8;0:,0:,0:]}");
132: AnalysisModuleSet ams = amsio.readAnalysisModuleSet(sr);
133: IAnalysisModule[] amL = ams.getAnalysisModules();
134: assertNotNull("Returned null data list.", amL);
135: assertEquals("Did not return an empty data set.", 2, amL.length);
136:
137: IAnalysisModule am = amL[0];
138: assertNotNull("Returned null module 0.", am);
139: assertEquals("0: name incorrect.", "n", am.getMeasureName());
140: assertEquals("0: unit incorrect.", "u", am.getMeasureUnit());
141: assertEquals("0: encoding incorrect.", "m", am
142: .getMimeEncoding());
143:
144: am = amL[1];
145: assertNotNull("Returned null module 1.", am);
146: assertEquals("1: name incorrect.", "", am.getMeasureName());
147: assertEquals("1: unit incorrect.", "", am.getMeasureUnit());
148: assertEquals("1: encoding incorrect.", "", am.getMimeEncoding());
149: }
150:
151: public void testReadAnalysisModuleSet4() throws Exception {
152: AnalysisModuleSetIO amsio = new AnalysisModuleSetIO();
153: StringReader sr = new StringReader("{}");
154: try {
155: amsio.readAnalysisModuleSet(sr);
156: fail("Did not throw IOException.");
157: } catch (IOException ioe) {
158: // test exception
159: }
160: }
161:
162: //-------------------------------------------------------------------------
163: // Helpers
164:
165: protected AnalysisModuleSet createAnalysisModuleSet(
166: IAnalysisModule amL[]) {
167: return CCCreatorUtil.createAnalysisModuleSet(amL);
168: }
169:
170: protected IAnalysisModule createIAnalysisModule(String name,
171: String unit, String mime) {
172: return CCCreatorUtil.createIAnalysisModule(name, unit, mime);
173: }
174:
175: //-------------------------------------------------------------------------
176: // Standard JUnit declarations
177:
178: public static Test suite() {
179: TestSuite suite = new TestSuite(THIS_CLASS);
180:
181: return suite;
182: }
183:
184: public static void main(String[] args) {
185: String[] name = { THIS_CLASS.getName() };
186:
187: // junit.textui.TestRunner.main( name );
188: // junit.swingui.TestRunner.main( name );
189:
190: junit.textui.TestRunner.main(name);
191: }
192:
193: /**
194: *
195: * @exception Exception thrown under any exceptional condition.
196: */
197: protected void setUp() throws Exception {
198: super .setUp();
199:
200: // set ourself up
201: }
202:
203: /**
204: *
205: * @exception Exception thrown under any exceptional condition.
206: */
207: protected void tearDown() throws Exception {
208: // tear ourself down
209:
210: super.tearDown();
211: }
212: }
|