public InterceptorMetadata with(Class<?> mockingClass, Method method, Object[] args) {
Annotation[] annotations = mockingClass.getAnnotations();
List<InterceptorMetadata> interceptorsMetadata = new ArrayList<>();
for (Annotation annotation : annotations) {
Interceptor interceptorAnnotation = annotation.annotationType()
.getAnnotation(Interceptor.class);
if (interceptorAnnotation == null) continue;
Metadata metadata = new Metadata(mockingClass,
method, args, annotation, method.getGenericReturnType());
Interceptor.Behaviour interceptor = instantiateInterface
.from(interceptorAnnotation.value());
interceptorsMetadata.add(new InterceptorMetadata(metadata, interceptor));
}
if (interceptorsMetadata.size() > 1) {
String message = Messages.multipleInterceptorsFoundOnClass(mockingClass);
throw new RuntimeException(message);
}
if (interceptorsMetadata.isEmpty()) {
String message = Messages.noInterceptorsFoundOnClass(mockingClass);
throw new RuntimeException(message);
}
return interceptorsMetadata.get(0);
}