use of org.spockframework.runtime.extension.IMethodInvocation in project micronaut-test by micronaut-projects.
the class MicronautSpockExtension method alignMocks.
@Override
protected void alignMocks(IMethodInvocation context, Object instance) {
for (MethodInjectionPoint injectedMethod : specDefinition.getInjectedMethods()) {
final Argument<?>[] args = injectedMethod.getArguments();
if (args.length == 1) {
final Optional<FieldInfo> fld = context.getSpec().getAllFields().stream().filter(f -> f.getName().equals(args[0].getName())).findFirst();
if (fld.isPresent()) {
final FieldInfo fieldInfo = fld.get();
final Object fieldInstance = fieldInfo.readValue(instance);
if (fieldInstance instanceof InterceptedProxy) {
Object interceptedTarget = ((InterceptedProxy) fieldInstance).interceptedTarget();
if (mockUtil.isMock(interceptedTarget)) {
fieldInfo.writeValue(instance, interceptedTarget);
}
}
}
}
}
}
Aggregations