Search in sources :

Example 1 with EventHandler

use of io.cucumber.plugin.event.EventHandler in project cucumber-jvm by cucumber.

the class EventBusTest method handlers_do_not_receive_the_events_they_did_not_registered_for.

@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
    EventHandler handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    TestCase testCase = mock(TestCase.class);
    TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler, never()).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase) EventHandler(io.cucumber.plugin.event.EventHandler) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 2 with EventHandler

use of io.cucumber.plugin.event.EventHandler in project cucumber-jvm by cucumber.

the class CachingGlueTest method emits_hook_messages_to_bus.

@Test
public void emits_hook_messages_to_bus() {
    List<Envelope> events = new ArrayList<>();
    EventHandler<Envelope> messageEventHandler = e -> events.add(e);
    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    bus.registerHandlerFor(Envelope.class, messageEventHandler);
    CachingGlue glue = new CachingGlue(bus);
    glue.addBeforeHook(new MockedScenarioScopedHookDefinition());
    glue.addAfterHook(new MockedScenarioScopedHookDefinition());
    glue.addBeforeStepHook(new MockedScenarioScopedHookDefinition());
    glue.addAfterStepHook(new MockedScenarioScopedHookDefinition());
    glue.prepareGlue(stepTypeRegistry);
    assertThat(events.size(), is(4));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DataTableTypeDefinition(io.cucumber.core.backend.DataTableTypeDefinition) ParameterTypeDefinition(io.cucumber.core.backend.ParameterTypeDefinition) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) SourceReference(io.cucumber.core.backend.SourceReference) Step(io.cucumber.core.gherkin.Step) DefaultDataTableCellTransformerDefinition(io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition) DefaultDataTableEntryTransformerDefinition(io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition) DefaultParameterTransformerDefinition(io.cucumber.core.backend.DefaultParameterTransformerDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) DataTableType(io.cucumber.datatable.DataTableType) ScenarioScoped(io.cucumber.core.backend.ScenarioScoped) ArrayList(java.util.ArrayList) StepDefinition(io.cucumber.core.backend.StepDefinition) TestCaseState(io.cucumber.core.backend.TestCaseState) Is.is(org.hamcrest.core.Is.is) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENGLISH(java.util.Locale.ENGLISH) DataTable(io.cucumber.datatable.DataTable) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) EventBus(io.cucumber.core.eventbus.EventBus) HookDefinition(io.cucumber.core.backend.HookDefinition) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) Envelope(io.cucumber.messages.types.Envelope) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) EventHandler(io.cucumber.plugin.event.EventHandler) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) Type(java.lang.reflect.Type) ParameterByTypeTransformer(io.cucumber.cucumberexpressions.ParameterByTypeTransformer) TableCellByTypeTransformer(io.cucumber.datatable.TableCellByTypeTransformer) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Feature(io.cucumber.core.gherkin.Feature) DocStringType(io.cucumber.docstring.DocStringType) Clock(java.time.Clock) Optional(java.util.Optional) TableEntryByTypeTransformer(io.cucumber.datatable.TableEntryByTypeTransformer) DocStringTypeDefinition(io.cucumber.core.backend.DocStringTypeDefinition) ParameterType(io.cucumber.cucumberexpressions.ParameterType) Mockito.mock(org.mockito.Mockito.mock) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ArrayList(java.util.ArrayList) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Envelope(io.cucumber.messages.types.Envelope) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

EventBus (io.cucumber.core.eventbus.EventBus)2 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)2 EventHandler (io.cucumber.plugin.event.EventHandler)2 UUID (java.util.UUID)2 DataTableTypeDefinition (io.cucumber.core.backend.DataTableTypeDefinition)1 DefaultDataTableCellTransformerDefinition (io.cucumber.core.backend.DefaultDataTableCellTransformerDefinition)1 DefaultDataTableEntryTransformerDefinition (io.cucumber.core.backend.DefaultDataTableEntryTransformerDefinition)1 DefaultParameterTransformerDefinition (io.cucumber.core.backend.DefaultParameterTransformerDefinition)1 DocStringTypeDefinition (io.cucumber.core.backend.DocStringTypeDefinition)1 HookDefinition (io.cucumber.core.backend.HookDefinition)1 ParameterTypeDefinition (io.cucumber.core.backend.ParameterTypeDefinition)1 ScenarioScoped (io.cucumber.core.backend.ScenarioScoped)1 SourceReference (io.cucumber.core.backend.SourceReference)1 StepDefinition (io.cucumber.core.backend.StepDefinition)1 TestCaseState (io.cucumber.core.backend.TestCaseState)1 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)1 Feature (io.cucumber.core.gherkin.Feature)1 Step (io.cucumber.core.gherkin.Step)1 StepTypeRegistry (io.cucumber.core.stepexpression.StepTypeRegistry)1 ParameterByTypeTransformer (io.cucumber.cucumberexpressions.ParameterByTypeTransformer)1