@@ -36,39 +36,45 @@ class LoggingInvocationInterceptor : InvocationInterceptor {
36
36
private class LoggingInvocationInterceptorHandler : InvocationHandler {
37
37
@Throws(Throwable ::class )
38
38
override fun invoke (proxy : Any , method : Method , args : Array <Any >): Any? {
39
- if (
39
+ val methodName = method.name
40
+ val invocationContextClass: Class <* > =
41
+ when (methodName) {
42
+ " interceptDynamicTest" -> DynamicTestInvocationContext ::class .java
43
+ else -> ReflectiveInvocationContext ::class .java
44
+ }
45
+ try {
40
46
LoggingInvocationInterceptor ::class
41
47
.java
42
48
.getDeclaredMethod(
43
49
method.name,
44
50
InvocationInterceptor .Invocation ::class .java,
45
- ReflectiveInvocationContext :: class .java ,
51
+ invocationContextClass ,
46
52
ExtensionContext ::class .java
47
- ) == null
48
- ) {
53
+ )
54
+ } catch (_ : NoSuchMethodException ) {
49
55
LOGGER .error(
50
56
" Junit LoggingInvocationInterceptor executing unknown interception point {}" ,
51
57
method.name
52
58
)
53
59
return method.invoke(proxy, * (args))
54
60
}
55
61
val invocation = args[0 ] as InvocationInterceptor .Invocation <* >?
56
- val invocationContext = args[1 ] as ReflectiveInvocationContext <* >
62
+ val reflectiveInvocationContext = args[1 ] as ? ReflectiveInvocationContext <* >
57
63
val extensionContext = args[2 ] as ExtensionContext ?
58
- val methodName = method.name
59
64
val logLineSuffix: String
60
65
val methodMatcher = methodPattern.matcher(methodName)
61
66
if (methodName == " interceptDynamicTest" ) {
62
67
logLineSuffix =
63
68
" execution of DynamicTest %s" .formatted(extensionContext!! .displayName)
64
69
} else if (methodName == " interceptTestClassConstructor" ) {
65
70
logLineSuffix =
66
- " instance creation for %s" .formatted(invocationContext !! .targetClass)
71
+ " instance creation for %s" .formatted(reflectiveInvocationContext !! .targetClass)
67
72
} else if (methodMatcher.matches()) {
68
73
val interceptedEvent = methodMatcher.group(1 )
69
- val methodRealClassName = invocationContext!! .executable!! .declaringClass.simpleName
70
- val methodName = invocationContext.executable!! .name
71
- val targetClassName = invocationContext!! .targetClass.simpleName
74
+ val methodRealClassName =
75
+ reflectiveInvocationContext!! .executable!! .declaringClass.simpleName
76
+ val methodName = reflectiveInvocationContext.executable!! .name
77
+ val targetClassName = reflectiveInvocationContext.targetClass.simpleName
72
78
val methodDisplayName =
73
79
if (targetClassName == methodRealClassName) methodName
74
80
else " $methodName ($methodRealClassName )"
@@ -86,7 +92,7 @@ class LoggingInvocationInterceptor : InvocationInterceptor {
86
92
val timeoutTask = TimeoutInteruptor (currentThread)
87
93
val start = Instant .now()
88
94
try {
89
- val timeout = getTimeout(invocationContext )
95
+ val timeout = reflectiveInvocationContext?. let (::getTimeout )
90
96
if (timeout != null ) {
91
97
LOGGER .info(
92
98
" Junit starting {} with timeout of {}" ,
0 commit comments