use of io.cucumber.core.eventbus.EventBus 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);
}
use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.
the class PluginFactoryTest method plugin_does_not_buffer_its_output.
@Test
void plugin_does_not_buffer_its_output() {
PrintStream previousSystemOut = System.out;
OutputStream mockSystemOut = new ByteArrayOutputStream();
try {
System.setOut(new PrintStream(mockSystemOut));
// Need to create a new plugin factory here since we need it to pick
// up the new value of System.out
fc = new PluginFactory();
PluginOption option = parse("progress");
ProgressFormatter plugin = (ProgressFormatter) fc.create(option);
EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
plugin.setEventPublisher(bus);
Result result = new Result(Status.PASSED, ZERO, null);
TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class), mock(PickleStepTestStep.class), result);
bus.send(event);
assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
} finally {
System.setOut(previousSystemOut);
}
}
use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.
the class SingletonRunnerSupplierTest method before.
@BeforeEach
void before() {
Supplier<ClassLoader> classLoader = SingletonRunnerSupplier.class::getClassLoader;
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(classLoader, runtimeOptions);
ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
BackendServiceLoader backendSupplier = new BackendServiceLoader(getClass()::getClassLoader, objectFactory);
EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
runnerSupplier = new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactory);
}
use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.
the class HtmlFormatterTest method ignores_step_definitions.
@Test
void ignores_step_definitions() throws Throwable {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
HtmlFormatter formatter = new HtmlFormatter(bytes);
EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
formatter.setEventPublisher(bus);
TestRunStarted testRunStarted = new TestRunStarted();
testRunStarted.setTimestamp(new Timestamp(10L, 0L));
Envelope testRunStartedEnvelope = new Envelope();
testRunStartedEnvelope.setTestRunStarted(testRunStarted);
bus.send(testRunStartedEnvelope);
StepDefinition stepDefinition = new StepDefinition();
Envelope stepDefinitionEnvelope = new Envelope();
stepDefinitionEnvelope.setStepDefinition(stepDefinition);
bus.send(stepDefinitionEnvelope);
Hook hook = new Hook();
Envelope hookEnvelope = new Envelope();
hookEnvelope.setHook(hook);
bus.send(hookEnvelope);
ParameterType parameterType = new ParameterType();
Envelope parameterTypeEnvelope = new Envelope();
parameterTypeEnvelope.setParameterType(parameterType);
bus.send(parameterTypeEnvelope);
TestRunFinished testRunFinished = new TestRunFinished();
testRunFinished.setTimestamp(new Timestamp(15L, 0L));
Envelope testRunFinishedEnvelope = new Envelope();
testRunFinishedEnvelope.setTestRunFinished(testRunFinished);
bus.send(testRunFinishedEnvelope);
String html = new String(bytes.toByteArray(), UTF_8);
assertThat(html, containsString("" + "window.CUCUMBER_MESSAGES = [" + "{\"testRunStarted\":{\"timestamp\":{\"seconds\":10,\"nanos\":0}}}," + "{\"testRunFinished\":{\"timestamp\":{\"seconds\":15,\"nanos\":0}}}" + "];\n"));
}
use of io.cucumber.core.eventbus.EventBus in project cucumber-jvm by cucumber.
the class EventBusTest method handlers_receive_the_events_they_registered_for.
@Test
void handlers_receive_the_events_they_registered_for() {
EventHandler<TestStepFinished> handler = mock(EventHandler.class);
PickleStepTestStep testStep = mock(PickleStepTestStep.class);
Result result = new Result(Status.PASSED, ZERO, null);
TestCase testCase = mock(TestCase.class);
TestStepFinished event = new TestStepFinished(EPOCH, testCase, testStep, result);
EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
bus.registerHandlerFor(TestStepFinished.class, handler);
bus.send(event);
verify(handler).receive(event);
}
Aggregations