From 0e394812d75aa4fe931aefa5d69b455a6da75b2e Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Fri, 16 Jun 2023 15:57:32 +0300 Subject: [PATCH] Unwrap `InvocationTargetException` in `RepositoryWrapperInvocationHandler` to show stack trace in generated tests --- .../RepositoryWrapperInvocationHandler.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utbot-spring-commons/src/main/kotlin/org/utbot/spring/repositoryWrapper/RepositoryWrapperInvocationHandler.kt b/utbot-spring-commons/src/main/kotlin/org/utbot/spring/repositoryWrapper/RepositoryWrapperInvocationHandler.kt index 4b47e94216..37dea711b2 100644 --- a/utbot-spring-commons/src/main/kotlin/org/utbot/spring/repositoryWrapper/RepositoryWrapperInvocationHandler.kt +++ b/utbot-spring-commons/src/main/kotlin/org/utbot/spring/repositoryWrapper/RepositoryWrapperInvocationHandler.kt @@ -2,6 +2,7 @@ package org.utbot.spring.repositoryWrapper import org.utbot.spring.api.repositoryWrapper.RepositoryInteraction import java.lang.reflect.InvocationHandler +import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method class RepositoryWrapperInvocationHandler( @@ -10,7 +11,11 @@ class RepositoryWrapperInvocationHandler( ) : InvocationHandler { override fun invoke(proxy: Any, method: Method, args: Array?): Any? { val nonNullArgs = args ?: emptyArray() - val result = runCatching { method.invoke(originalRepository, *nonNullArgs) } + val result = try { + Result.success(method.invoke(originalRepository, *nonNullArgs)) + } catch (e: InvocationTargetException) { + Result.failure(e.targetException) + } RepositoryInteraction.recordedInteractions.add( RepositoryInteraction(beanName, method, nonNullArgs.toList(), result) )