use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.
the class PluginsTest method shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher.
@Test
void shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
EventListener plugin = mock(EventListener.class);
plugins.addPlugin(plugin);
plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
verify(rootEventPublisher, times(1)).registerHandlerFor(eq(Event.class), ArgumentMatchers.any());
}
use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.
the class RuntimeTest method generates_events_for_glue_and_scenario_scoped_glue.
@Test
void generates_events_for_glue_and_scenario_scoped_glue() {
final Feature feature = TestFeatureParser.parse("test.feature", "" + "Feature: feature name\n" + " Scenario: Run a scenario once\n" + " Given global scoped\n" + " And scenario scoped\n" + " Scenario: Then do it again\n" + " Given global scoped\n" + " And scenario scoped\n" + "");
final List<StepDefinition> stepDefinedEvents = new ArrayList<>();
Plugin eventListener = (EventListener) publisher -> publisher.registerHandlerFor(StepDefinedEvent.class, (StepDefinedEvent event) -> {
stepDefinedEvents.add(event.getStepDefinition());
});
final MockedStepDefinition mockedStepDefinition = new MockedStepDefinition();
final MockedScenarioScopedStepDefinition mockedScenarioScopedStepDefinition = new MockedScenarioScopedStepDefinition();
BackendSupplier backendSupplier = new TestBackendSupplier() {
private Glue glue;
@Override
public void loadGlue(Glue glue, List<URI> gluePaths) {
this.glue = glue;
glue.addStepDefinition(mockedStepDefinition);
}
@Override
public void buildWorld() {
glue.addStepDefinition(mockedScenarioScopedStepDefinition);
}
};
FeatureSupplier featureSupplier = new StubFeatureSupplier(feature);
Runtime.builder().withBackendSupplier(backendSupplier).withAdditionalPlugins(eventListener).withEventBus(new TimeServiceEventBus(new StepDurationTimeService(ZERO), UUID::randomUUID)).withFeatureSupplier(featureSupplier).build().run();
assertThat(stepDefinedEvents.get(0).getPattern(), is(mockedStepDefinition.getPattern()));
assertThat(stepDefinedEvents.get(1).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
// Twice, once for each scenario
assertThat(stepDefinedEvents.get(2).getPattern(), is(mockedStepDefinition.getPattern()));
assertThat(stepDefinedEvents.get(3).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
assertThat(stepDefinedEvents.size(), is(4));
}
use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.
the class RuntimeTest method emits_a_meta_message.
@Test
void emits_a_meta_message() {
List<Envelope> messages = new ArrayList<>();
EventListener listener = publisher -> publisher.registerHandlerFor(Envelope.class, messages::add);
Runtime.builder().withAdditionalPlugins(listener).build().run();
Meta meta = messages.get(0).getMeta();
assertThat(meta.getProtocolVersion(), matchesPattern("\\d+\\.\\d+\\.\\d+(-RC\\d+)?(-SNAPSHOT)?"));
assertThat(meta.getImplementation().getName(), is("cucumber-jvm"));
assertThat(meta.getImplementation().getVersion(), matchesPattern("\\d+\\.\\d+\\.\\d+(-RC\\d+)?(-SNAPSHOT)?"));
assertThat(meta.getOs().getName(), matchesPattern(".+"));
assertThat(meta.getCpu().getName(), matchesPattern(".+"));
}
use of io.cucumber.plugin.EventListener in project cucumber-jvm by cucumber.
the class PluginsTest method shouldSetNonConcurrentEventListener.
@Test
void shouldSetNonConcurrentEventListener() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
EventListener plugin = mock(EventListener.class);
plugins.addPlugin(plugin);
plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
verify(plugin, times(1)).setEventPublisher(eventPublisher.capture());
assertThat(eventPublisher.getValue().getClass(), is(equalTo(CanonicalOrderEventPublisher.class)));
}
Aggregations