use of org.neo4j.test.extension.Inject in project neo4j by neo4j.
the class ActorsSupportExtension method postProcessTestInstance.
@Override
public void postProcessTestInstance(Object testInstance, ExtensionContext extensionContext) throws Exception {
ActorsManager manager = (ActorsManager) getStore(extensionContext).getOrComputeIfAbsent(ACTOR_MANAGER, k -> new ActorsManager(extensionContext.getDisplayName()));
Class<?> clazz = testInstance.getClass();
List<Field> declaredFields = getAllFields(clazz);
for (Field declaredField : declaredFields) {
if (declaredField.getType() == Actor.class && declaredField.isAnnotationPresent(Inject.class)) {
if (Modifier.isStatic(declaredField.getModifiers())) {
throw new ExtensionConfigurationException(format("Actors cannot be inject into static field: %s.%s.", clazz.getName(), declaredField.getName()));
}
declaredField.setAccessible(true);
if (declaredField.get(testInstance) != null) {
throw new ExtensionConfigurationException(format("Field %s that is marked for injection in class %s is managed by extension container " + "and should not have any manually assigned value.", declaredField.getName(), clazz.getName()));
}
declaredField.set(testInstance, manager.createActor(declaredField.getName()));
}
}
}
Aggregations