예제 #1
0
 public <T> T imposterise(
     final MethodInterceptor interceptor, Class<T> mockedType, Class<?>... ancillaryTypes) {
   Class<Factory> proxyClass = null;
   Object proxyInstance = null;
   try {
     setConstructorsAccessible(mockedType, true);
     proxyClass = createProxyClass(mockedType, ancillaryTypes);
     proxyInstance = createProxy(proxyClass, interceptor);
     return mockedType.cast(proxyInstance);
   } catch (ClassCastException cce) {
     throw new MockitoException(
         join(
             "ClassCastException occurred while creating the mockito proxy :",
             "  class to mock : " + describeClass(mockedType),
             "  created class : " + describeClass(proxyClass),
             "  proxy instance class : " + describeClass(proxyInstance),
             "  instance creation by : " + instantiator.getClass().getSimpleName(),
             "",
             "You might experience classloading issues, disabling the Objenesis cache *might* help (see MockitoConfiguration)"),
         cce);
   } finally {
     setConstructorsAccessible(mockedType, false);
   }
 }