use of org.evosuite.runtime.FalsePositiveException in project evosuite by EvoSuite.
the class Injector method validateBean.
/**
* Check if all beans that need injection have been properly injected
*
* @param instance
* @param clazz
* @param <T>
* @throws FalsePositiveException
* @throws IllegalArgumentException
*/
@Constraints(noNullInputs = true, notMutable = true, noDirectInsertion = true)
public static <T> void validateBean(@BoundInputVariable(initializer = true, atMostOnceWithSameParameters = true) T instance, Class<?> clazz) throws FalsePositiveException, IllegalArgumentException {
Inputs.checkNull(instance, clazz);
for (Field f : getAllFieldsToInject(clazz)) {
f.setAccessible(true);
try {
Object obj = f.get(instance);
if (obj == null) {
throw new FalsePositiveException("Missing dependency injection for field " + f.getName() + " in class " + clazz.getName());
}
// it might be a bean with its own dependency injections.
// but those should be handled in its instantiation
} catch (IllegalAccessException e) {
// shouldn't really happen
logger.warn(e.toString());
}
}
Class<?> parent = clazz.getSuperclass();
if (parent != null && !parent.equals(Object.class)) {
validateBean(instance, parent);
}
}
Aggregations