Repository: quarkusio/quarkus
Issue: Classloading error with QuarkusMock regression in 1.12.0.CR1

**Describe the bug**
I upgraded from `1.11.2` to `1.12.0.CR1`, and I get the following error in my unit tests:
```
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.123 s <<< FAILURE! - in com.xx.arte.ocpdeploy.deploy.noreg.DeployNoRegFtuTest
[ERROR] com.xx.arte.ocpdeploy.deploy.noreg.DeployNoRegFtuTest.noreg  Time elapsed: 1.327 s  <<< ERROR!
java.lang.ClassCastException: class org.mockito.codegen.VaultSystemBackendEngine$MockitoMock$192437934 cannot be cast to class io.quarkus.vault.runtime.VaultSystemBackendManager (org.mockito.codegen.VaultSystemBackendEngine$MockitoMock$192437934 is in
unnamed module of loader net.bytebuddy.dynamic.loading.MultipleParentClassLoader @36d1793a; io.quarkus.vault.runtime.VaultSystemBackendManager is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @6b08b323)
        at com.xx.arte.ocpdeploy.deploy.noreg.DeployNoRegFtuTest.noreg(DeployNoRegFtuTest.java:21)
```
I don't have a stacktrace other than the line of the test.

**Expected behavior**
No regression. Mock works as expected.

**Actual behavior**
The unit test fails with the above exception.

**To Reproduce**
I don't have yet an independent reproducer. Here is the code in my application that is causing the issue:
```
    @BeforeAll
    public static void mockVaultSystemBackendEngine() {

        VaultSystemBackendEngine sys = Mockito.mock(VaultSystemBackendEngine.class);
        VaultHealthStatus vaultHealthStatus = new VaultHealthStatus();
        vaultHealthStatus.setInitialized(true);
        Mockito.when(sys.healthStatus()).thenReturn(vaultHealthStatus);
        QuarkusMock.installMockForType(sys, VaultSystemBackendEngine.class);
    }
```

**Environment (please complete the following information):**
 - Output of `uname -a` or `ver`:  `Microsoft Windows [Version 10.0.17763.1697]`
 - Output of `java -version`: `openjdk version "11.0.1-redhat" 2018-10-16 LTS`
 - GraalVM version (if different from Java):  N/A
 - Quarkus version or git rev: `1.12.0.CR1`
 - Build tool (ie. output of `mvnw --version` or `gradlew --version`): `Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)`


Changed files:
independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java
test-framework/junit5/src/main/java/io/quarkus/test/junit/MockSupport.java

diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java
index 7e8718e6295..4410f808f41 100644
--- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java
+++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java
@@ -118,7 +118,7 @@ Collection<Resource> generate(BeanInfo bean, String beanClassName,
         FieldCreator beanField = clientProxy.getFieldCreator(BEAN_FIELD, DescriptorUtils.extToInt(beanClassName))
                 .setModifiers(ACC_PRIVATE | ACC_FINAL);
         if (mockable) {
-            clientProxy.getFieldCreator(MOCK_FIELD, Object.class).setModifiers(ACC_PRIVATE | ACC_VOLATILE);
+            clientProxy.getFieldCreator(MOCK_FIELD, providerType.descriptorName()).setModifiers(ACC_PRIVATE | ACC_VOLATILE);
         }
         FieldCreator contextField = null;
         if (BuiltinScope.APPLICATION.is(bean.getScope())) {
@@ -133,7 +133,7 @@ Collection<Resource> generate(BeanInfo bean, String beanClassName,
         implementGetContextualInstance(clientProxy, providerType);
         implementGetBean(clientProxy, beanField.getFieldDescriptor());
         if (mockable) {
-            implementMockMethods(clientProxy);
+            implementMockMethods(clientProxy, providerType);
         }
 
         for (MethodInfo method : getDelegatingMethods(bean, bytecodeTransformerConsumer, transformUnproxyableClasses)) {
@@ -231,17 +231,19 @@ Collection<Resource> generate(BeanInfo bean, String beanClassName,
         return classOutput.getResources();
     }
 
-    private void implementMockMethods(ClassCreator clientProxy) {
+    private void implementMockMethods(ClassCreator clientProxy, ProviderType providerType) {
         MethodCreator clear = clientProxy
                 .getMethodCreator(MethodDescriptor.ofMethod(clientProxy.getClassName(), CLEAR_MOCK_METHOD_NAME, void.class));
-        clear.writeInstanceField(FieldDescriptor.of(clientProxy.getClassName(), MOCK_FIELD, Object.class), clear.getThis(),
+        clear.writeInstanceField(FieldDescriptor.of(clientProxy.getClassName(), MOCK_FIELD, providerType.descriptorName()),
+                clear.getThis(),
                 clear.loadNull());
         clear.returnValue(null);
 
         MethodCreator set = clientProxy
                 .getMethodCreator(
                         MethodDescriptor.ofMethod(clientProxy.getClassName(), SET_MOCK_METHOD_NAME, void.class, Object.class));
-        set.writeInstanceField(FieldDescriptor.of(clientProxy.getClassName(), MOCK_FIELD, Object.class), set.getThis(),
+        set.writeInstanceField(FieldDescriptor.of(clientProxy.getClassName(), MOCK_FIELD, providerType.descriptorName()),
+                set.getThis(),
                 set.getMethodParam(0));
         set.returnValue(null);
     }
@@ -268,7 +270,8 @@ void implementDelegate(ClassCreator clientProxy, ProviderType providerType, Fiel
         if (mockable) {
             //if mockable and mocked just return the mock
             ResultHandle mock = creator.readInstanceField(
-                    FieldDescriptor.of(clientProxy.getClassName(), MOCK_FIELD, Object.class.getName()), creator.getThis());
+                    FieldDescriptor.of(clientProxy.getClassName(), MOCK_FIELD, providerType.descriptorName()),
+                    creator.getThis());
             BytecodeCreator falseBranch = creator.ifNull(mock).falseBranch();
             falseBranch.returnValue(falseBranch.checkCast(mock, providerType.className()));
         }
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 2bbf9b6c1de..60107393d70 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,6 +36,10 @@ static <T> 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);