use of org.apache.openejb.junit.jee.resources.TestResource in project tomee by apache.
the class InjectStatement method evaluate.
@Override
public void evaluate() throws Throwable {
if (startingStatement != null) {
Class<?> clazz = this.clazz;
while (!Object.class.equals(clazz)) {
for (final Field field : clazz.getDeclaredFields()) {
final TestResource resource = field.getAnnotation(TestResource.class);
if (resource != null) {
if (Context.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
field.set(Modifier.isStatic(field.getModifiers()) ? null : test, startingStatement.getContainer().getContext());
} else if (Hashtable.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
field.set(Modifier.isStatic(field.getModifiers()) ? null : test, startingStatement.getProperties());
} else if (EJBContainer.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
field.set(Modifier.isStatic(field.getModifiers()) ? null : test, startingStatement.getContainer());
} else {
throw new OpenEJBException("can't inject field '" + field.getName() + "'");
}
}
}
clazz = clazz.getSuperclass();
}
}
if (test != null) {
SystemInstance.get().setComponent(TestInstance.class, new TestInstance(test.getClass(), test));
// force eager init (MockitoInjector initialize eveything in its constructor)
SystemInstance.get().getComponent(FallbackPropertyInjector.class);
Injector.inject(test);
}
if (statement != null) {
statement.evaluate();
}
}
Aggregations