16
16
17
17
package org .springframework .context .annotation .jsr330 ;
18
18
19
- import java .util .Enumeration ;
20
- import java .util .Spliterator ;
21
- import java .util .Spliterators ;
19
+ import java .net .URI ;
20
+ import java .util .Collections ;
22
21
import java .util .stream .Stream ;
23
- import java .util .stream .StreamSupport ;
24
22
25
23
import junit .framework .TestCase ;
26
- import junit .framework .TestFailure ;
27
24
import junit .framework .TestResult ;
28
25
import junit .framework .TestSuite ;
29
26
import org .atinject .tck .Tck ;
44
41
import org .springframework .context .annotation .Jsr330ScopeMetadataResolver ;
45
42
import org .springframework .context .annotation .Primary ;
46
43
import org .springframework .context .support .GenericApplicationContext ;
44
+ import org .springframework .util .ClassUtils ;
47
45
48
46
import static org .junit .jupiter .api .DynamicContainer .dynamicContainer ;
49
47
import static org .junit .jupiter .api .DynamicTest .dynamicTest ;
@@ -61,7 +59,8 @@ class SpringAtInjectTckTests {
61
59
@ TestFactory
62
60
Stream <? extends DynamicNode > runTechnologyCompatibilityKit () {
63
61
TestSuite testSuite = (TestSuite ) Tck .testsFor (buildCar (), false , true );
64
- return generateDynamicTests (testSuite );
62
+ Class <?> suiteClass = resolveTestSuiteClass (testSuite );
63
+ return generateDynamicTests (testSuite , suiteClass );
65
64
}
66
65
67
66
@@ -84,45 +83,34 @@ private static Car buildCar() {
84
83
return ac .getBean (Car .class );
85
84
}
86
85
87
- private static Stream <? extends DynamicNode > generateDynamicTests (TestSuite testSuite ) {
88
- return stream (testSuite .tests ()).map (test -> {
86
+ private static Stream <? extends DynamicNode > generateDynamicTests (TestSuite testSuite , Class <?> suiteClass ) {
87
+ return Collections . list (testSuite .tests ()). stream ( ).map (test -> {
89
88
if (test instanceof TestSuite nestedSuite ) {
90
- return dynamicContainer (nestedSuite .getName (), generateDynamicTests (nestedSuite ));
89
+ Class <?> nestedSuiteClass = resolveTestSuiteClass (nestedSuite );
90
+ URI uri = URI .create ("class:" + nestedSuiteClass .getName ());
91
+ return dynamicContainer (nestedSuite .getName (), uri , generateDynamicTests (nestedSuite , nestedSuiteClass ));
91
92
}
92
93
if (test instanceof TestCase testCase ) {
93
- return dynamicTest (testCase .getName (), () -> runTestCase (testCase ));
94
+ URI uri = URI .create ("method:" + suiteClass .getName () + "#" + testCase .getName ());
95
+ return dynamicTest (testCase .getName (), uri , () -> runTestCase (testCase ));
94
96
}
95
97
throw new IllegalStateException ("Unsupported Test type: " + test .getClass ().getName ());
96
98
});
97
99
}
98
100
99
- private static void runTestCase (TestCase testCase ) {
101
+ private static void runTestCase (TestCase testCase ) throws Throwable {
100
102
TestResult testResult = new TestResult ();
101
103
testCase .run (testResult );
102
- assertSuccessfulResults (testResult );
103
- }
104
-
105
- private static void assertSuccessfulResults (TestResult testResult ) {
106
- if (!testResult .wasSuccessful ()) {
107
- Throwable throwable = Stream .concat (stream (testResult .failures ()), stream (testResult .errors ()))
108
- .map (TestFailure ::thrownException )
109
- .findFirst ()
110
- .get ();
111
-
112
- if (throwable instanceof Error error ) {
113
- throw error ;
114
- }
115
- if (throwable instanceof RuntimeException runtimeException ) {
116
- throw runtimeException ;
117
- }
118
- throw new AssertionError (throwable );
104
+ if (testResult .failureCount () > 0 ) {
105
+ throw testResult .failures ().nextElement ().thrownException ();
106
+ }
107
+ if (testResult .errorCount () > 0 ) {
108
+ throw testResult .errors ().nextElement ().thrownException ();
119
109
}
120
110
}
121
111
122
- private static <T > Stream <T > stream (Enumeration <T > enumeration ) {
123
- Spliterator <T > spliterator = Spliterators .spliteratorUnknownSize (
124
- enumeration .asIterator (), Spliterator .ORDERED );
125
- return StreamSupport .stream (spliterator , false );
112
+ private static Class <?> resolveTestSuiteClass (TestSuite testSuite ) {
113
+ return ClassUtils .resolveClassName (testSuite .getName (), Tck .class .getClassLoader ());
126
114
}
127
115
128
116
}
0 commit comments