001: /*
002: * @(#)IClassMetaDataReaderUTestI.java
003: *
004: * Copyright (C) 2002-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:
031: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
032: import net.sourceforge.groboutils.junit.v1.iftc.ImplFactory;
033: import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestCase;
034: import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
035:
036: /**
037: * Tests the IClassMetaDataReader interface.
038: *
039: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
040: * @version $Date: 2004/04/15 05:48:28 $
041: * @since December 28, 2002
042: */
043: public class IClassMetaDataReaderUTestI extends InterfaceTestCase {
044: //-------------------------------------------------------------------------
045: // Standard JUnit Class-specific declarations
046:
047: private static final Class THIS_CLASS = IClassMetaDataReaderUTestI.class;
048: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
049:
050: public IClassMetaDataReaderUTestI(String name, ImplFactory f) {
051: super (name, IClassMetaDataReader.class, f);
052: }
053:
054: public IClassMetaDataReader createIClassMetaDataReader() {
055: return (IClassMetaDataReader) createImplObject();
056: }
057:
058: //-------------------------------------------------------------------------
059: // Tests
060:
061: public void testGetClassSignatures1() throws Exception {
062: IClassMetaDataReader cmdr = createIClassMetaDataReader();
063: String sigs1[] = cmdr.getClassSignatures();
064: assertNotNull("Returned null sigs.", sigs1);
065: String sigs2[] = cmdr.getClassSignatures();
066: assertNotNull("Returned null sigs on second attempt.", sigs2);
067: assertEquals(
068: "Two consecutive calls returned different class signatures.",
069: sigs1.length, sigs2.length);
070: }
071:
072: public void testGetClassSignatures2() throws Exception {
073: IClassMetaDataReader cmdr = createIClassMetaDataReader();
074: cmdr.close();
075: try {
076: cmdr.getClassSignatures();
077: fail("Did not throw IOException.");
078: } catch (IOException ioe) {
079: assertNotNull("Null exception message.", ioe.getMessage());
080: }
081: }
082:
083: public void testGetClassSignatures3() throws Exception {
084: IClassMetaDataReader cmdr = createIClassMetaDataReader();
085: String sigs1[] = cmdr.getClassSignatures();
086: cmdr.close();
087: try {
088: cmdr.getClassSignatures();
089: fail("Did not throw IOException.");
090: } catch (IOException ioe) {
091: assertNotNull("Null exception message.", ioe.getMessage());
092: }
093: }
094:
095: public void testGetClassSignatures4() throws Exception {
096: IClassMetaDataReader cmdr = createIClassMetaDataReader();
097: String sigs[] = cmdr.getClassSignatures();
098: for (int i = 0; i < sigs.length; ++i) {
099: assertNotNull(
100: "Returned null signature at index " + i + ".",
101: sigs[i]);
102: }
103: }
104:
105: public void testReadClass1() throws Exception {
106: IClassMetaDataReader cmdr = createIClassMetaDataReader();
107: cmdr.close();
108: try {
109: cmdr.readClass("a");
110: fail("Did not throw IOException.");
111: } catch (IOException ioe) {
112: assertNotNull("Null exception message.", ioe.getMessage());
113: }
114: }
115:
116: public void testReadClass2() throws Exception {
117: IClassMetaDataReader cmdr = createIClassMetaDataReader();
118: cmdr.close();
119: try {
120: cmdr.readClass(null);
121: fail("Did not throw IllegalArgumentException.");
122: } catch (IllegalArgumentException ex) {
123: assertNotNull("Null exception message.", ex.getMessage());
124: }
125: }
126:
127: public void testReadClass3() throws Exception {
128: IClassMetaDataReader cmdr = createIClassMetaDataReader();
129: String nonExistClassName = "a";
130: String sigs[] = cmdr.getClassSignatures();
131: boolean inSigs = true;
132: while (inSigs) {
133: nonExistClassName += "1";
134: inSigs = false;
135: for (int i = 0; i < sigs.length; ++i) {
136: if (sigs[i].equals(nonExistClassName)) {
137: inSigs = true;
138: break;
139: }
140: }
141: }
142:
143: ClassRecord cr = cmdr.readClass(nonExistClassName);
144: assertNull(
145: "Incorrectly returned a class for a non-existent class "
146: + "signature '" + nonExistClassName + "'.", cr);
147: }
148:
149: public void testReadAllClasses1() throws Exception {
150: IClassMetaDataReader cmdr = createIClassMetaDataReader();
151: String sigs[] = cmdr.getClassSignatures();
152: assertNotNull("Returned null sigs.", sigs);
153: for (int i = 0; i < sigs.length; ++i) {
154: ClassRecord cr = cmdr.readClass(sigs[i]);
155: assertNotNull(
156: "Read null class from returned class signature.",
157: cr);
158: }
159: }
160:
161: public void testClose1() throws Exception {
162: IClassMetaDataReader cmdr = createIClassMetaDataReader();
163: cmdr.close();
164: }
165:
166: public void testClose2() throws Exception {
167: IClassMetaDataReader cmdr = createIClassMetaDataReader();
168: cmdr.close();
169: try {
170: cmdr.close();
171: fail("Did not throw IOException.");
172: } catch (IOException ex) {
173: assertNotNull("Null exception message.", ex.getMessage());
174: }
175: }
176:
177: //-------------------------------------------------------------------------
178: // Standard JUnit declarations
179:
180: public static InterfaceTestSuite suite() {
181: InterfaceTestSuite suite = new InterfaceTestSuite(THIS_CLASS);
182:
183: return suite;
184: }
185:
186: public static void main(String[] args) {
187: String[] name = { THIS_CLASS.getName() };
188:
189: // junit.textui.TestRunner.main( name );
190: // junit.swingui.TestRunner.main( name );
191:
192: junit.textui.TestRunner.main(name);
193: }
194:
195: /**
196: *
197: * @exception Exception thrown under any exceptional condition.
198: */
199: protected void setUp() throws Exception {
200: super .setUp();
201:
202: // set ourself up
203: }
204:
205: /**
206: *
207: * @exception Exception thrown under any exceptional condition.
208: */
209: protected void tearDown() throws Exception {
210: // tear ourself down
211:
212: super.tearDown();
213: }
214: }
|