001: /*
002: * @(#)JavaMakerUTest.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.uicapture.v1.javamaker;
028:
029: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
030: import net.sourceforge.groboutils.junit.v1.iftc.*;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034:
035: import java.io.*;
036: import net.sourceforge.groboutils.uicapture.v1.*;
037:
038: /**
039: * Tests the JavaMaker class.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2003/05/29 13:05:56 $
043: * @since Oct 3, 2002
044: */
045: public class JavaMakerUTest extends TestCase {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = JavaMakerUTest.class;
050: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
051:
052: public JavaMakerUTest(String name) {
053: super (name);
054: }
055:
056: //-------------------------------------------------------------------------
057: // Tests
058:
059: public void testInstantiation1() throws IOException {
060: try {
061: new JavaMaker((File) null, null, null);
062: } catch (IllegalArgumentException e) {
063: // test exception?
064: }
065: }
066:
067: public void testInstantiation2() {
068: try {
069: new JavaMaker((Writer) null, null, null);
070: } catch (IllegalArgumentException e) {
071: // test exception?
072: }
073: }
074:
075: public void testInstantiation3() {
076: JavaMaker jm = new JavaMaker(new StringWriter(), "a", "b");
077: }
078:
079: public void testInstantiation4() throws IOException {
080: File f = File.createTempFile("JavaMakerUTest", ".tmp");
081: JavaMaker jm = new JavaMaker(f, "a", "b");
082: }
083:
084: public void testStartEnd1() {
085: DOC.getIT().testsIssue(618295);
086: StringWriter sw = new StringWriter();
087: JavaMaker jm = new JavaMaker(sw, "a", "b");
088:
089: jm.start();
090: jm.end();
091:
092: assertTrue("Did not create Java package header correctly.", sw
093: .toString().indexOf("package a;") >= 0);
094: assertTrue(
095: "Did not create Java class definition header correctly.",
096: sw.toString().indexOf("public class b") >= 0);
097: }
098:
099: //-------------------------------------------------------------------------
100: // Standard JUnit declarations
101:
102: public static Test suite() {
103: InterfaceTestSuite suite = IScriptMakerUTestI.suite();
104:
105: // all tests are covered by the interface tests, so don't need this
106: // line. But will add it for insurance in case tests are needed later.
107: suite.addTestSuite(THIS_CLASS);
108:
109: suite.addFactory(new CxFactory("A") {
110: public Object createImplObject() {
111: return new JavaMaker(new StringWriter(), "my.package",
112: "MyClass");
113: }
114: });
115:
116: return suite;
117: }
118:
119: public static void main(String[] args) {
120: String[] name = { THIS_CLASS.getName() };
121:
122: // junit.textui.TestRunner.main( name );
123: // junit.swingui.TestRunner.main( name );
124:
125: junit.textui.TestRunner.main(name);
126: }
127:
128: /**
129: *
130: * @exception Exception thrown under any exceptional condition.
131: */
132: protected void setUp() throws Exception {
133: super .setUp();
134:
135: // set ourself up
136: }
137:
138: /**
139: *
140: * @exception Exception thrown under any exceptional condition.
141: */
142: protected synchronized void tearDown() throws Exception {
143: // tear ourself down
144:
145: super.tearDown();
146: }
147: }
|