From 678ff1163fad60773607f18bf5e0481ef321188c Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 8 Apr 2021 10:59:10 +1000 Subject: [PATCH] Change assignability check for interfaces --- .../src/main/java/io/quarkus/test/junit/MockSupport.java | 4 ---- .../src/main/java/io/quarkus/test/junit/QuarkusMock.java | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/MockSupport.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/MockSupport.java index 60107393d702d..2bbf9b6c1de55 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/MockSupport.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/MockSupport.java @@ -36,10 +36,6 @@ static void installMock(T instance, T mock) { if (inst == null) { throw new IllegalStateException("No test in progress"); } - if (!(instance.getClass().getSuperclass().isAssignableFrom(mock.getClass()))) { - throw new RuntimeException(mock - + " is not assignable to type " + instance.getClass().getSuperclass()); - } try { Method setMethod = instance.getClass().getDeclaredMethod("arc$setMock", Object.class); setMethod.invoke(instance, mock); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java index d49cc9075f435..36dd7b34e74ef 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMock.java @@ -48,6 +48,12 @@ public static void installMockForInstance(T mock, T instance) { */ public static void installMockForType(T mock, Class instance, Annotation... qualifiers) { //mock support does the actual work, but exposes other methods that are not part of the user API + if (!instance.isAssignableFrom(mock.getClass())) { + if (!(instance.getClass().getSuperclass().isAssignableFrom(mock.getClass()))) { + throw new RuntimeException(mock + + " is not assignable to type " + instance.getClass().getSuperclass()); + } + } MockSupport.installMock(CDI.current().select(instance, qualifiers).get(), mock); } }