use of com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner in project junit-servers by mjeanroy.
the class JunitServerExtensionTest method it_should_inject_annotated_field_before_each_test.
@Test
void it_should_inject_annotated_field_before_each_test() {
final JunitServerExtension extension = new JunitServerExtension();
final FixtureClass testInstance = new FixtureClass();
final FakeExtensionContext context = new FakeExtensionContext(testInstance);
extension.beforeAll(context);
final FakeStore store = context.getSingleStore();
final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
extension.beforeEach(context);
final AnnotationsHandlerRunner annotationsAdapter = store.get("annotationsAdapter", AnnotationsHandlerRunner.class);
assertThat(annotationsAdapter).isNotNull();
assertThat(testInstance.server).isNotNull().isSameAs(serverAdapter.getServer());
assertThat(testInstance.configuration).isNotNull().isSameAs(serverAdapter.getServer().getConfiguration());
assertThat(testInstance.client).isNotNull();
}
use of com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner in project junit-servers by mjeanroy.
the class JunitServerExtension method afterEach.
@Override
public void afterEach(ExtensionContext context) {
try {
Object target = context.getRequiredTestInstance();
AnnotationsHandlerRunner annotationsAdapter = findAnnotationsHandlerAdapterInStore(context);
annotationsAdapter.afterEach(target);
} finally {
unregisterEmbeddedServer(context, false);
removeAnnotationsHandlerAdapterFromStore(context);
}
}
use of com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner in project junit-servers by mjeanroy.
the class JunitServerExtension method beforeEach.
@Override
public void beforeEach(ExtensionContext context) {
EmbeddedServerRunner serverAdapter = findEmbeddedServerAdapterInStore(context);
// The extension was not declared as a static extension.
if (serverAdapter == null) {
serverAdapter = registerEmbeddedServer(context, false);
}
EmbeddedServer<?> server = serverAdapter.getServer();
AbstractConfiguration configuration = server.getConfiguration();
AnnotationsHandlerRunner annotationsAdapter = new AnnotationsHandlerRunner(server, configuration);
annotationsAdapter.beforeEach(context.getRequiredTestInstance());
putAnnotationsHandlerAdapterInStore(context, annotationsAdapter);
}
Aggregations