001: /*
002: * @(#)JUnitTestSuiteEUTest.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 net.sourceforge.groboutils.testing.junitlog.v1.*;
030: import junit.framework.Test;
031: import junit.framework.TestCase;
032: import junit.framework.TestSuite;
033:
034: import java.io.IOException;
035: import java.lang.reflect.Method;
036:
037: /**
038: * Tests the functionality of the JUnit TestSuite class for conformance to
039: * expected behaviors.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @since October 31, 2002
043: * @version $Date: 2003/02/10 22:52:22 $
044: */
045: public class InnerClassNameEUTest extends TestCase {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = InnerClassNameEUTest.class;
050:
051: public InnerClassNameEUTest(String name) {
052: super (name);
053: }
054:
055: static boolean IS_JDK_12_COMPAT = true;
056: static {
057: try {
058: Class.forName("java.lang.ThreadLocal");
059: } catch (ThreadDeath td) {
060: throw td;
061: } catch (Throwable t) {
062: IS_JDK_12_COMPAT = false;
063: }
064: }
065:
066: //-------------------------------------------------------------------------
067: // Tests
068:
069: /*
070: * These tests show off very interesting behavior:
071: * - JDK 1.1 always returns NULL for the "getDeclaringClass()"
072: * call.
073: * - JDK 1.2-1.4 correctly report the declared class for all classes
074: * except anonymous inner classes.
075: */
076:
077: public void testGetDeclaringClass1() {
078: Class owner = THIS_CLASS.getDeclaringClass();
079: assertNull("Test class has a declaring class.", owner);
080: }
081:
082: private class MyClass1 {
083: }
084:
085: public void testGetDeclaringClass2() {
086: Class c = MyClass1.class;
087: Class owner = c.getDeclaringClass();
088: if (IS_JDK_12_COMPAT) {
089: assertNotNull("Inner class has no declaring class.", owner);
090: assertEquals("Did not return expected owning class.",
091: THIS_CLASS, owner);
092: } else {
093: assertNull("Inner class's owner is not null.", owner);
094: }
095: }
096:
097: private static class MyClass2 {
098: }
099:
100: public void testGetDeclaringClass3() {
101: Class c = MyClass2.class;
102: Class owner = c.getDeclaringClass();
103: if (IS_JDK_12_COMPAT) {
104: assertNotNull("Static inner class has no declaring class.",
105: owner);
106: assertEquals("Did not return expected owning class.",
107: THIS_CLASS, owner);
108: } else {
109: assertNull("Static inner class' owner is not null.", owner);
110: }
111: }
112:
113: public void testGetDeclaringClass4() {
114: /* The following test works on JDK 1.1.8 and JDK 1.4.0, but fails for
115: JDK 1.2.2 (all on Windows). It's all so confusing!!!
116: Object o = new MyClass2() {};
117: Class c = o.getClass();
118: Class owner = c.getDeclaringClass();
119:
120: // Not really what you expect, is it?
121: assertNull(
122: "Anonymous inner class has a declaring class.",
123: owner );
124: */
125: }
126:
127: //-------------------------------------------------------------------------
128: // Standard JUnit declarations
129:
130: public static Test suite() {
131: TestSuite suite = new TestSuite(THIS_CLASS);
132:
133: return suite;
134: }
135:
136: public static void main(String[] args) {
137: String[] name = { THIS_CLASS.getName() };
138:
139: // junit.textui.TestRunner.main( name );
140: // junit.swingui.TestRunner.main( name );
141:
142: junit.textui.TestRunner.main(name);
143: }
144:
145: /**
146: *
147: * @exception Exception thrown under any exceptional condition.
148: */
149: protected void setUp() throws Exception {
150: super .setUp();
151:
152: // set ourself up
153: }
154:
155: /**
156: *
157: * @exception Exception thrown under any exceptional condition.
158: */
159: protected void tearDown() throws Exception {
160: // tear ourself down
161:
162: super.tearDown();
163: }
164: }
|