### Question:
InMemoryMessageVerifier { @SafeVarargs public static List<Event> publishedEvents(final InMemoryMessagePublisher<TypedMessage> inMemoryMessagePublisher, final Class<? extends Event>... eventClasses) { final Map<String, Class<? extends Event>> typeToEventClass = new HashMap<>(); for (final Class<? extends Event> eventClass : eventClasses) { try { typeToEventClass.put(eventClass.newInstance().type(), eventClass); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException("Unable to instatiate prototype event " + eventClass.getName()); } } final List<Event> events = new LinkedList<>(); for (final TypedMessage typedMessage : inMemoryMessagePublisher.getPublishedMessages()) { final Class<? extends Event> eventClass = typeToEventClass.get(typedMessage.getType()); if (eventClass != null) { events.add(AbstractEvent.newEvent(eventClass, typedMessage.getPayload())); } } return events; }  static boolean messageTypeSent(final InMemoryMessageSender<TypedMessage> inMemoryMessageSender,
            final String messageType); static boolean eventTypePublished(final InMemoryMessagePublisher<TypedMessage> inMemoryMessagePublisher,
            final Class<? extends Event> eventClass); static boolean eventPublished(final InMemoryMessagePublisher<TypedMessage> inMemoryMessagePublisher,
            final Event event); @SafeVarargs static List<Event> publishedEvents(final InMemoryMessagePublisher<TypedMessage> inMemoryMessagePublisher,
            final Class<? extends Event>... eventClasses);  }### Answer:
@Test public void shouldReturnPublishedEvents() { final InMemoryMessagePublisher<TypedMessage> inMemoryMessagePublisher = mock(InMemoryMessagePublisher.class); final List<TypedMessage> mockPublishedMessages = new ArrayList<>(); final StubEvent stubEvent = new StubEvent(); stubEvent.setEventField(randomString()); addSerializedEventMessage(mockPublishedMessages, stubEvent); final StubOtherEvent stubOtherEvent = new StubOtherEvent(); addSerializedEventMessage(mockPublishedMessages, stubOtherEvent); when(inMemoryMessagePublisher.getPublishedMessages()).thenReturn(mockPublishedMessages); final List<Event> publishedEvents = InMemoryMessageVerifier.publishedEvents(inMemoryMessagePublisher, StubEvent.class, StubOtherEvent.class); final List<Event> expectedEvents = Arrays.asList(stubEvent, stubOtherEvent); assertEquals(expectedEvents, publishedEvents); }
@Test public void shouldReturnFilteredPublishedEvents() { final InMemoryMessagePublisher<TypedMessage> inMemoryMessagePublisher = mock(InMemoryMessagePublisher.class); final List<TypedMessage> mockPublishedMessages = new ArrayList<>(); final StubEvent stubEvent = new StubEvent(); stubEvent.setEventField(randomString()); addSerializedEventMessage(mockPublishedMessages, stubEvent); final StubOtherEvent stubOtherEvent = new StubOtherEvent(); addSerializedEventMessage(mockPublishedMessages, stubOtherEvent); when(inMemoryMessagePublisher.getPublishedMessages()).thenReturn(mockPublishedMessages); final List<Event> publishedEvents = InMemoryMessageVerifier.publishedEvents(inMemoryMessagePublisher, StubOtherEvent.class); final List<Event> expectedEvents = Arrays.asList(stubOtherEvent); assertEquals(expectedEvents, publishedEvents); }