1919import java .util .Deque ;
2020import java .util .Stack ;
2121
22- import org .junit .Test ;
23- import org .junit .jupiter .api .Assertions ;
24- import org .junit .runner .RunWith ;
25- import org .junit .runners .BlockJUnit4ClassRunner ;
26- import org .junit .runners .ParentRunner ;
27- import sun .reflect .Reflection ;
22+ import org .junit .jupiter .api .Test ;
23+ import org .junit .jupiter .api .condition .EnabledOnJre ;
24+ import org .junit .jupiter .api .condition .JRE ;
25+ import org .junit .jupiter .engine .descriptor .TestMethodTestDescriptor ;
26+ import org .junit .platform .engine .support .hierarchical .ThrowableCollector ;
2827
29- import static org .junit .Assert .assertEquals ;
30- import static org .junit .Assert .assertNotNull ;
31- import static org .junit .Assert .assertSame ;
28+ import static org .junit .jupiter . api . Assertions .assertEquals ;
29+ import static org .junit .jupiter . api . Assertions .assertNotNull ;
30+ import static org .junit .jupiter . api . Assertions .assertSame ;
3231
3332/**
34- * Tests {@link StackLocatorUtilTest }.
33+ * Tests {@link StackLocatorUtil }.
3534 */
36- @ RunWith (BlockJUnit4ClassRunner .class )
3735public class StackLocatorUtilTest {
3836
3937 @ Test
38+ @ EnabledOnJre (JRE .JAVA_8 )
4039 public void testStackTraceEquivalence () throws Exception {
41- for (int i = 1 ; i < 15 ; i ++) {
42- final Class <?> expected = Reflection .getCallerClass (i + StackLocator .JDK_7U25_OFFSET );
40+ // Frame 8 is a hidden frame and does not show in the stacktrace
41+ for (int i = 1 ; i < 8 ; i ++) {
42+ final Class <?> expected = (Class <?>) Class .forName ("sun.reflect.Reflection" )
43+ .getMethod ("getCallerClass" , int .class )
44+ .invoke (null , i + StackLocator .JDK_7U25_OFFSET );
4345 final Class <?> actual = StackLocatorUtil .getCallerClass (i );
4446 final Class <?> fallbackActual = Class .forName (
4547 StackLocatorUtil .getStackTraceElement (i ).getClassName ());
@@ -88,22 +90,23 @@ public void testTopElementInStackTrace() {
8890 final Deque <Class <?>> classes = stackLocator .getCurrentStackTrace ();
8991 //Removing private class in "PrivateSecurityManagerStackTraceUtil"
9092 classes .removeFirst ();
91- Assertions . assertSame (PrivateSecurityManagerStackTraceUtil .class , classes .getFirst ());
93+ assertSame (PrivateSecurityManagerStackTraceUtil .class , classes .getFirst ());
9294 }
9395
9496 @ Test
9597 public void testGetCallerClassViaName () throws Exception {
96- final Class <?> expected = BlockJUnit4ClassRunner .class ;
97- final Class <?> actual = StackLocatorUtil .getCallerClass ("org.junit.runners.ParentRunner" );
98+ if (true ) new RuntimeException ().printStackTrace ();
99+ final Class <?> expected = TestMethodTestDescriptor .class ;
100+ final Class <?> actual = StackLocatorUtil .getCallerClass ("org.junit.platform.engine.support.hierarchical.ThrowableCollector" );
98101 // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and
99102 // update this test accordingly
100103 assertSame (expected , actual );
101104 }
102105
103106 @ Test
104107 public void testGetCallerClassViaAnchorClass () throws Exception {
105- final Class <?> expected = BlockJUnit4ClassRunner .class ;
106- final Class <?> actual = StackLocatorUtil .getCallerClass (ParentRunner .class );
108+ final Class <?> expected = TestMethodTestDescriptor .class ;
109+ final Class <?> actual = StackLocatorUtil .getCallerClass (ThrowableCollector .class );
107110 // if this test fails in the future, it's probably because of a JUnit upgrade; check the new stack trace and
108111 // update this test accordingly
109112 assertSame (expected , actual );
@@ -113,8 +116,8 @@ public void testGetCallerClassViaAnchorClass() throws Exception {
113116 public void testLocateClass () {
114117 final ClassLocator locator = new ClassLocator ();
115118 final Class <?> clazz = locator .locateClass ();
116- assertNotNull ("Could not locate class" , clazz );
117- assertEquals ("Incorrect class" , this .getClass (), clazz );
119+ assertNotNull (clazz , "Could note locate class" );
120+ assertEquals (this .getClass (), clazz , "Incorrect class" );
118121 }
119122
120123}
0 commit comments