1 26 27 package net.sourceforge.groboutils.junit.v1.iftc; 28 29 import junit.framework.Test; 31 import junit.framework.TestCase; 32 import junit.framework.TestSuite; 33 34 import java.io.IOException ; 35 import java.lang.reflect.Method ; 36 37 38 46 public class InnerClassNameEUTest extends TestCase 47 { 48 51 private static final Class THIS_CLASS = InnerClassNameEUTest.class; 52 53 public InnerClassNameEUTest( String name ) 54 { 55 super( name ); 56 } 57 58 59 static boolean IS_JDK_12_COMPAT = true; 60 static { 61 try 62 { 63 Class.forName("java.lang.ThreadLocal"); 64 } 65 catch (ThreadDeath td) 66 { 67 throw td; 68 } 69 catch (Throwable t) 70 { 71 IS_JDK_12_COMPAT = false; 72 } 73 } 74 75 76 79 86 87 88 89 public void testGetDeclaringClass1() 90 { 91 Class owner = THIS_CLASS.getDeclaringClass(); 92 assertNull( 93 "Test class has a declaring class.", 94 owner ); 95 } 96 97 98 private class MyClass1 {} 99 100 public void testGetDeclaringClass2() 101 { 102 Class c = MyClass1.class; 103 Class owner = c.getDeclaringClass(); 104 if (IS_JDK_12_COMPAT) 105 { 106 assertNotNull( 107 "Inner class has no declaring class.", 108 owner ); 109 assertEquals( 110 "Did not return expected owning class.", 111 THIS_CLASS, 112 owner 113 ); 114 } 115 else 116 { 117 assertNull( 118 "Inner class's owner is not null.", 119 owner ); 120 } 121 } 122 123 124 private static class MyClass2 {} 125 126 public void testGetDeclaringClass3() 127 { 128 Class c = MyClass2.class; 129 Class owner = c.getDeclaringClass(); 130 if (IS_JDK_12_COMPAT) 131 { 132 assertNotNull( 133 "Static inner class has no declaring class.", 134 owner ); 135 assertEquals( 136 "Did not return expected owning class.", 137 THIS_CLASS, 138 owner 139 ); 140 } 141 else 142 { 143 assertNull( 144 "Static inner class' owner is not null.", 145 owner ); 146 } 147 } 148 149 150 public void testGetDeclaringClass4() 151 { 152 163 } 164 165 166 167 168 169 172 173 public static Test suite() 174 { 175 TestSuite suite = new TestSuite( THIS_CLASS ); 176 177 return suite; 178 } 179 180 public static void main( String [] args ) 181 { 182 String [] name = { THIS_CLASS.getName() }; 183 184 187 junit.textui.TestRunner.main( name ); 188 } 189 190 191 195 protected void setUp() throws Exception 196 { 197 super.setUp(); 198 199 } 201 202 203 207 protected void tearDown() throws Exception 208 { 209 211 212 super.tearDown(); 213 } 214 } 215 216 | Popular Tags |