{
Method method = providedClass.getMethod( annotation.providedBy() );
if ( !element.getType().isAssignableFrom( method.getReturnType() ) )
{
throw new HandleException( "Impossible to mock %s due to compatibility type, method provider %s#%s returns %s",
element.getDeclaringClass().getName(),
providedClass.getName(),
annotation.providedBy(),
method.getReturnType().getName() );
}
try
{
Object mocked = getMockProviderForType( element.getType(), method, type );
mockedObjects.put( element, mocked );
}
catch ( Throwable t )
{
throw new HandleException( "Impossible to mock %s, method provider %s#%s raised an error: %s",
element.getDeclaringClass().getName(),
providedClass.getName(),
annotation.providedBy(),
t );
}
}
catch ( SecurityException e )
{
throw new HandleException( "Impossible to mock %s, impossible to access to method provider %s#%s: %s",
element.getDeclaringClass().getName(),
providedClass.getName(),
annotation.providedBy(),
e );
}
catch ( NoSuchMethodException e )
{
throw new HandleException( "Impossible to mock %s, the method provider %s#%s doesn't exist.",
element.getDeclaringClass().getName(),
providedClass.getName(),
annotation.providedBy() );
}
}