001: /*
002: * @(#)CxFactoryUTest.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.junit.v1.iftc;
028:
029: import org.easymock.EasyMock;
030: import org.easymock.MockControl;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034:
035: /**
036: * Tests the CxFactory class. Concrete test for an abstract class.
037: *
038: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
039: * @since October 30, 2002
040: * @version $Date: 2003/05/29 13:05:52 $
041: */
042: public class CxFactoryUTest extends TestCase {
043: //-------------------------------------------------------------------------
044: // Standard JUnit Class-specific declarations
045:
046: private static final Class THIS_CLASS = CxFactoryUTest.class;
047: private static final String TC = "CxFactoryUTest";
048: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(THIS_CLASS);
050:
051: public CxFactoryUTest(String name) {
052: super (name);
053: }
054:
055: // intentionally non-static inner class
056: public class MyCxFactory extends CxFactory {
057: public MyCxFactory(String n) {
058: super (n);
059: }
060:
061: public MyCxFactory(String n, boolean a) {
062: super (n, a);
063: }
064:
065: public Object createImplObject() {
066: return "";
067: }
068: }
069:
070: // intentionally static inner class
071: public static class MyStaticCxFactory extends CxFactory {
072: public MyStaticCxFactory(String n) {
073: super (n);
074: }
075:
076: public MyStaticCxFactory(String n, boolean a) {
077: super (n, a);
078: }
079:
080: public Object createImplObject() {
081: return "";
082: }
083: }
084:
085: //-------------------------------------------------------------------------
086: // Tests
087:
088: public void testToString1() {
089: // try with a named inner class.
090: CxFactory cf = new MyCxFactory("1");
091: assertEquals("Returned unexpected factory name.", "1", cf
092: .toString());
093: }
094:
095: public void testToString1b() {
096: // try with a named inner class.
097: CxFactory cf = new MyCxFactory("1b", false);
098: assertEquals("Returned unexpected factory name.", "1b", cf
099: .toString());
100: }
101:
102: public void testToString1a() {
103: // try with a named inner class.
104: CxFactory cf = new MyCxFactory("1a", true);
105: assertEquals("Returned unexpected factory name.", TC + "-1a",
106: cf.toString());
107: }
108:
109: public void testToString2() {
110: // try with an anonymous inner class.
111: // CxFactory should use the name of the owning class's name,
112: // not the inner class's name.
113: CxFactory cf = new MyCxFactory("2") {
114: };
115: assertEquals("Returned unexpected factory name.", "2", cf
116: .toString());
117: }
118:
119: public void testToString2b() {
120: // try with an anonymous inner class.
121: // CxFactory should use the name of the owning class's name,
122: // not the inner class's name.
123: CxFactory cf = new MyCxFactory("2b", false) {
124: };
125: assertEquals("Returned unexpected factory name.", "2b", cf
126: .toString());
127: }
128:
129: public void testToString2a() {
130: // try with an anonymous inner class.
131: // CxFactory should use the name of the owning class's name,
132: // not the inner class's name.
133: CxFactory cf = new MyCxFactory("2a", true) {
134: };
135: assertEquals("Returned unexpected factory name.", TC + "-2a",
136: cf.toString());
137: }
138:
139: public void testToString3() {
140: // try with a static inner class.
141: // CxFactory should use the name of the owning class's name,
142: // not the inner class's name.
143: CxFactory cf = new MyStaticCxFactory("3") {
144: };
145: assertEquals("Returned unexpected factory name.", "3", cf
146: .toString());
147: }
148:
149: public void testToString3b() {
150: // try with a static inner class.
151: // CxFactory should use the name of the owning class's name,
152: // not the inner class's name.
153: CxFactory cf = new MyStaticCxFactory("3b", false) {
154: };
155: assertEquals("Returned unexpected factory name.", "3b", cf
156: .toString());
157: }
158:
159: public void testToString3a() {
160: // try with a static inner class.
161: // CxFactory should use the name of the owning class's name,
162: // not the inner class's name.
163: CxFactory cf = new MyStaticCxFactory("3a", true) {
164: };
165: assertEquals("Returned unexpected factory name.", TC + "-3a",
166: cf.toString());
167: }
168:
169: public void testToString4() {
170: // try with an outside, stand-alone class.
171: LOG.debug("Test4:");
172: CxFactory cf = new CxFactorySample("4");
173: LOG.debug("Returned Sample factory toString: [" + cf.toString()
174: + "]");
175: assertEquals("Returned unexpected factory name.", "4", cf
176: .toString());
177: }
178:
179: public void testToString4b() {
180: // try with an outside, stand-alone class.
181: LOG.debug("Test4:");
182: CxFactory cf = new CxFactorySample("4b", false);
183: LOG.debug("Returned Sample factory toString: [" + cf.toString()
184: + "]");
185: assertEquals("Returned unexpected factory name.", "4b", cf
186: .toString());
187: }
188:
189: public void testToString4a() {
190: // try with an outside, stand-alone class.
191: LOG.debug("Test4:");
192: CxFactory cf = new CxFactorySample("4a", true);
193: LOG.debug("Returned Sample factory toString: [" + cf.toString()
194: + "]");
195: assertEquals("Returned unexpected factory name.",
196: "CxFactorySample-4a", cf.toString());
197: }
198:
199: //-------------------------------------------------------------------------
200: // Standard JUnit declarations
201:
202: public static InterfaceTestSuite suite() {
203: InterfaceTestSuite suite = ImplFactoryUTestI.suite();
204:
205: // yes, this is an inner class inside an inner class!
206: // shudder - luckily, this is only for testing.
207: suite.addFactory(new ImplFactory() {
208: public Object createImplObject() {
209: return new MyStaticCxFactory("A-B");
210: }
211:
212: public String toString() {
213: return "CxFactory-A";
214: }
215: });
216: suite.addTestSuite(THIS_CLASS);
217:
218: return suite;
219: }
220:
221: public static void main(String[] args) {
222: String[] name = { THIS_CLASS.getName() };
223:
224: // junit.textui.TestRunner.main( name );
225: // junit.swingui.TestRunner.main( name );
226:
227: junit.textui.TestRunner.main(name);
228: }
229:
230: /**
231: *
232: * @exception Exception thrown under any exceptional condition.
233: */
234: protected void setUp() throws Exception {
235: super .setUp();
236:
237: // set ourself up
238: }
239:
240: /**
241: *
242: * @exception Exception thrown under any exceptional condition.
243: */
244: protected void tearDown() throws Exception {
245: // tear ourself down
246:
247: super.tearDown();
248: }
249: }
|