001: /*
002: * @(#)AbstractWriterServerUTestI.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.autodoc.v1.testserver;
028:
029: import net.sourceforge.groboutils.autodoc.v1.*;
030:
031: import java.io.Writer;
032: import java.io.StringWriter;
033: import java.io.IOException;
034:
035: import org.easymock.EasyMock;
036: import org.easymock.MockControl;
037: import net.sourceforge.groboutils.junit.v1.iftc.*;
038: import junit.framework.Test;
039: import junit.framework.TestCase;
040: import junit.framework.TestSuite;
041: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
042:
043: /**
044: * Tests the AbstractWriterServer abstract class.
045: *
046: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
047: * @since April 8, 2002
048: * @version $Date: 2003/02/10 22:52:17 $
049: */
050: public class AbstractWriterServerUTestI extends InterfaceTestCase {
051: //-------------------------------------------------------------------------
052: // Standard JUnit Class-specific declarations
053:
054: private static final Class THIS_CLASS = AbstractWriterServerUTestI.class;
055:
056: public AbstractWriterServerUTestI(String name, ImplFactory f) {
057: super (name, AbstractWriterServer.class, f);
058: }
059:
060: //-------------------------------------------------------------------------
061: // setup
062:
063: /**
064: *
065: * @exception Exception thrown under any exceptional condition.
066: */
067: protected void setUp() throws Exception {
068: super .setUp();
069:
070: // set ourself up
071: }
072:
073: public AbstractWriterServer createAbstractWriterServer() {
074: return (AbstractWriterServer) createImplObject();
075: }
076:
077: //-------------------------------------------------------------------------
078: // Tests
079:
080: public void testWriteTestData1() throws Exception {
081: AbstractWriterServer aws = createAbstractWriterServer();
082: StringWriter sw = new StringWriter();
083:
084: // should fail gracefully
085: aws.writeTestData(null, sw);
086: }
087:
088: public void testWriteTestData2() throws Exception {
089: AbstractWriterServer aws = createAbstractWriterServer();
090: StringWriter sw = new StringWriter();
091: TestData td = new TestData() {
092: public TestInfo getTestInfo() {
093: return null;
094: }
095: };
096:
097: // should fail gracefully
098: aws.writeTestData(td, sw);
099: }
100:
101: public void testWriteTestData3() throws Exception {
102: AbstractWriterServer aws = createAbstractWriterServer();
103: StringWriter sw = new StringWriter();
104: final TestInfo ti = new DefaultTestInfo("a", "b");
105: TestData td = new TestData() {
106: public TestInfo getTestInfo() {
107: return ti;
108: }
109: };
110:
111: // should work w/o error
112: aws.writeTestData(td, sw);
113: }
114:
115: public void testWriteTestData4() throws Exception {
116: AbstractWriterServer aws = createAbstractWriterServer();
117: StringWriter sw = new StringWriter();
118: final TestInfo ti = new DefaultTestInfo();
119: TestData td = new TestData() {
120: public TestInfo getTestInfo() {
121: return ti;
122: }
123: };
124:
125: // should fail gracefully, if it does fail.
126: aws.writeTestData(td, sw);
127: }
128:
129: protected void _innerOpenOutput(AbstractWriterServer aws,
130: TestData td) {
131: try {
132: Writer w = aws.openOutput(td);
133: assertNotNull(
134: "If no exception was thrown, then openOutput must never "
135: + "return null.", w);
136: aws.closeOutput(w);
137: } catch (IOException ioe) {
138: // this exception is fine.
139: }
140: }
141:
142: public void testOpenOutput1() {
143: AbstractWriterServer aws = createAbstractWriterServer();
144:
145: try {
146: _innerOpenOutput(aws, null);
147: } catch (NullPointerException e) {
148: // this is ok
149: } catch (IllegalArgumentException e) {
150: // this is ok
151: }
152: }
153:
154: public void testOpenOutput2() {
155: AbstractWriterServer aws = createAbstractWriterServer();
156: StringWriter sw = new StringWriter();
157: TestData td = new TestData() {
158: public TestInfo getTestInfo() {
159: return null;
160: }
161: };
162:
163: try {
164: _innerOpenOutput(aws, td);
165: } catch (NullPointerException e) {
166: // this is ok
167: } catch (IllegalArgumentException e) {
168: // this is ok
169: }
170: }
171:
172: public void testOpenOutput3() {
173: AbstractWriterServer aws = createAbstractWriterServer();
174: StringWriter sw = new StringWriter();
175: final TestInfo ti = new DefaultTestInfo();
176: TestData td = new TestData() {
177: public TestInfo getTestInfo() {
178: return ti;
179: }
180: };
181:
182: _innerOpenOutput(aws, td);
183: }
184:
185: public void testOpenOutput4() {
186: AbstractWriterServer aws = createAbstractWriterServer();
187: StringWriter sw = new StringWriter();
188: final TestInfo ti = new DefaultTestInfo("a", "b");
189: TestData td = new TestData() {
190: public TestInfo getTestInfo() {
191: return ti;
192: }
193: };
194:
195: _innerOpenOutput(aws, td);
196: }
197:
198: //-------------------------------------------------------------------------
199: // Helpers
200:
201: //-------------------------------------------------------------------------
202: // Standard JUnit declarations
203:
204: public static InterfaceTestSuite suite() {
205: InterfaceTestSuite suite = new InterfaceTestSuite(THIS_CLASS);
206: suite.addInterfaceTestSuite(ServerUTestI.suite());
207:
208: return suite;
209: }
210:
211: public static void main(String[] args) {
212: String[] name = { THIS_CLASS.getName() };
213:
214: // junit.textui.TestRunner.main( name );
215: // junit.swingui.TestRunner.main( name );
216:
217: junit.textui.TestRunner.main(name);
218: }
219:
220: /**
221: *
222: * @exception Exception thrown under any exceptional condition.
223: */
224: protected void tearDown() throws Exception {
225: // tear ourself down
226:
227: super.tearDown();
228: }
229: }
|