EventLoggerFactory { public void registerLoggers() { LOG.debug("Registering loggers..."); for (EventLogger logger : loggers) { LOG.info("Registering logger: " + logger.getClass().getName()); eventManager.addObserver(logger); } } EventLoggerFactory(final EventManager eventManager); static EventLoggerFactory getInstance(); void registerLoggers(); List<EventLogger> getLoggers(); void setLoggers(List<EventLogger> loggers);  }
@Test public void testRegisterLoggers() { final EventManager mockEventManager = context.mock(EventManager.class); final EventLoggerFactory eventLoggerFactory = new EventLoggerFactory(mockEventManager); List<EventLogger> loggers = new ArrayList<>(TOTAL_MOCK_LOGGERS); for (int i = 0; i < TOTAL_MOCK_LOGGERS; i++) { loggers.add(context.mock(EventLogger.class, "EventLogger" + i)); } eventLoggerFactory.setLoggers(loggers); context.checking(new Expectations() { { exactly(TOTAL_MOCK_LOGGERS).of(mockEventManager).addObserver(with(any(Observer.class))); } }); eventLoggerFactory.registerLoggers(); }