@Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(Envelope.class, this::write);
    }
@Test
    void writes_report_xml() {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        JUnitFormatter formatter = new JUnitFormatter(bytes);
        EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
        formatter.setEventPublisher(bus);

        TestRunStarted testRunStarted = new TestRunStarted(new Timestamp(10L, 0L));
        bus.send(Envelope.of(testRunStarted));

        TestRunFinished testRunFinished = new TestRunFinished(null, true, new Timestamp(15L, 0L), null);
        bus.send(Envelope.of(testRunFinished));

        assertThat(bytes, bytes(equalTo("" +
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<testsuite name=\"Cucumber\" time=\"5\" tests=\"0\" skipped=\"0\" failures=\"0\" errors=\"0\">\n" +
                "</testsuite>\n")));
    }