* @return <code>true</code> if method is single-find, <code>false</code> otherwise.
* @throws SpecificationViolationException
*
*/
private static boolean validateReturnType(@NotNull final Method method) {
final Finder f = AnnotationUtils.findAnnotation(method, Finder.class);
final boolean singleFind = !Collection.class.isAssignableFrom(method.getReturnType());
if (!singleFind) {
final Class<?> returnType = method.getReturnType();
if (!returnType.isAssignableFrom(f.returnAs())) {
throw new SpecificationViolationException(
"@Finder.returnAs value (" + f.returnAs().getName()
+ ") cannot be cast to method return type (" + returnType.getName() + ")", method
);
} else if (f.returnAs() != List.class) {
if (f.returnAs().isInterface()) {
throw new SpecificationViolationException(
"@Finder.returnAs value (" + f.returnAs().getName() + ") cannot be an interface", method
);
} else {
try {
f.returnAs().getConstructor();
} catch (NoSuchMethodException e) {
throw new SpecificationViolationException(
"@Finder.returnAs value (" + f.returnAs().getName() + ") doesn't have no-arg constructor.", method
);
}
}
}
}