40
40
import java .util .function .Consumer ;
41
41
import java .util .function .Function ;
42
42
import java .util .function .Predicate ;
43
- import java .util .function .Supplier ;
44
- import java .util .regex .Pattern ;
45
43
46
44
import org .eclipse .microprofile .config .spi .ConfigProviderResolver ;
47
45
import org .jboss .jandex .AnnotationInstance ;
52
50
import org .jboss .jandex .Type ;
53
51
import org .jboss .logging .Logger ;
54
52
import org .junit .jupiter .api .Nested ;
55
- import org .junit .jupiter .api .TestInfo ;
56
53
import org .junit .jupiter .api .extension .AfterAllCallback ;
57
54
import org .junit .jupiter .api .extension .AfterEachCallback ;
58
55
import org .junit .jupiter .api .extension .AfterTestExecutionCallback ;
106
103
import io .quarkus .test .junit .callback .QuarkusTestContext ;
107
104
import io .quarkus .test .junit .callback .QuarkusTestMethodContext ;
108
105
import io .quarkus .test .junit .internal .DeepClone ;
109
- import io .quarkus .test .junit .internal .SerializationWithXStreamFallbackDeepClone ;
106
+ import io .quarkus .test .junit .internal .NewSerializingDeepClone ;
110
107
111
108
public class QuarkusTestExtension extends AbstractJvmQuarkusTestExtension
112
109
implements BeforeEachCallback , BeforeTestExecutionCallback , AfterTestExecutionCallback , AfterEachCallback ,
@@ -124,7 +121,6 @@ public class QuarkusTestExtension extends AbstractJvmQuarkusTestExtension
124
121
// needed for @Nested
125
122
private static final Deque <Object > outerInstances = new ArrayDeque <>(1 );
126
123
private static RunningQuarkusApplication runningQuarkusApplication ;
127
- private static Pattern clonePattern ;
128
124
private static Throwable firstException ; //if this is set then it will be thrown from the very first test that is run, the rest are aborted
129
125
130
126
private static Class <?> quarkusTestMethodContextClass ;
@@ -260,11 +256,11 @@ public Thread newThread(Runnable r) {
260
256
runningQuarkusApplication = startupAction
261
257
.runMainClass (profileInstance .commandLineParameters ());
262
258
}
263
- String patternString = runningQuarkusApplication .getConfigValue ("quarkus.test.class-clone-pattern" , String .class )
264
- .orElse ("java\\ ..*" );
265
- clonePattern = Pattern .compile (patternString );
259
+
266
260
TracingHandler .quarkusStarted ();
267
261
262
+ deepClone .setRunningQuarkusApplication (runningQuarkusApplication );
263
+
268
264
//now we have full config reset the hang timer
269
265
270
266
if (hangTaskKey != null ) {
@@ -351,7 +347,7 @@ private void shutdownHangDetection() {
351
347
}
352
348
353
349
private void populateDeepCloneField (StartupAction startupAction ) {
354
- deepClone = new SerializationWithXStreamFallbackDeepClone ( startupAction .getClassLoader ());
350
+ deepClone = new NewSerializingDeepClone ( originalCl , startupAction .getClassLoader ());
355
351
}
356
352
357
353
private void populateTestMethodInvokers (ClassLoader quarkusClassLoader ) {
@@ -957,50 +953,14 @@ private Object runExtensionMethod(ReflectiveInvocationContext<Method> invocation
957
953
List <Object > argumentsFromTccl = new ArrayList <>();
958
954
Parameter [] parameters = invocationContext .getExecutable ().getParameters ();
959
955
for (int i = 0 ; i < originalArguments .size (); i ++) {
960
- Object arg = originalArguments .get (i );
961
- boolean cloneRequired = false ;
962
- Object replacement = null ;
963
- Class <?> argClass = parameters [i ].getType ();
964
- if (arg != null ) {
965
- Class <?> theclass = argClass ;
966
- while (theclass .isArray ()) {
967
- theclass = theclass .getComponentType ();
968
- }
969
- if (theclass .isPrimitive ()) {
970
- cloneRequired = false ;
971
- } else if (TestInfo .class .isAssignableFrom (theclass )) {
972
- TestInfo info = (TestInfo ) arg ;
973
- Method newTestMethod = info .getTestMethod ().isPresent ()
974
- ? determineTCCLExtensionMethod (info .getTestMethod ().get (), testClassFromTCCL )
975
- : null ;
976
- replacement = new TestInfoImpl (info .getDisplayName (), info .getTags (),
977
- Optional .of (testClassFromTCCL ),
978
- Optional .ofNullable (newTestMethod ));
979
- } else if (clonePattern .matcher (theclass .getName ()).matches ()) {
980
- cloneRequired = true ;
981
- } else {
982
- try {
983
- cloneRequired = runningQuarkusApplication .getClassLoader ()
984
- .loadClass (theclass .getName ()) != theclass ;
985
- } catch (ClassNotFoundException e ) {
986
- if (arg instanceof Supplier ) {
987
- cloneRequired = true ;
988
- } else {
989
- throw e ;
990
- }
991
- }
992
- }
993
- }
956
+ if (testMethodInvokerToUse != null ) {
957
+ Class <?> argClass = parameters [i ].getType ();
994
958
995
- if (replacement != null ) {
996
- argumentsFromTccl .add (replacement );
997
- } else if (cloneRequired ) {
998
- argumentsFromTccl .add (deepClone .clone (arg ));
999
- } else if (testMethodInvokerToUse != null ) {
1000
959
argumentsFromTccl .add (testMethodInvokerToUse .getClass ().getMethod ("methodParamInstance" , String .class )
1001
960
.invoke (testMethodInvokerToUse , argClass .getName ()));
1002
961
} else {
1003
- argumentsFromTccl .add (arg );
962
+ Object arg = originalArguments .get (i );
963
+ argumentsFromTccl .add (deepClone .clone (arg ));
1004
964
}
1005
965
}
1006
966
@@ -1235,7 +1195,6 @@ protected void doClose() throws IOException {
1235
1195
log .error ("Failed to shutdown Quarkus" , e );
1236
1196
} finally {
1237
1197
runningQuarkusApplication = null ;
1238
- clonePattern = null ;
1239
1198
Thread .currentThread ().setContextClassLoader (old );
1240
1199
ConfigProviderResolver .setInstance (null );
1241
1200
}
0 commit comments