AnswerReplayer extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { if (source instanceof ReplayJobStatus) { replayAnswer((QuestionAskedEvent) event, (ReplayJobStatus) source); } } AnswerReplayer(); @Override void onEvent(Event event, Object source, Object data); static final String NAME; }
@Test void replayAnswerOK() { QuestionAskedEvent questionAskedEvent = new QuestionAskedEvent(); String question = "What's up?"; QuestionRecorder<Object> questionRecorder = mock(QuestionRecorder.class); when(questionRecorder.replay(question)).thenReturn(true); Map<String, QuestionRecorder<Object>> answers = new HashMap<>(); answers.put(question.getClass().getName(), questionRecorder); ExtensionJobHistoryRecord currentRecord = new ExtensionJobHistoryRecord(null, null, answers, null, null); ReplayJobStatus replayJobStatus = mock(ReplayJobStatus.class); when(replayJobStatus.getCurrentRecord()).thenReturn(currentRecord); when(replayJobStatus.getQuestion()).thenReturn(question); AnswerReplayer answerReplayer = new AnswerReplayer(); answerReplayer.onEvent(questionAskedEvent, replayJobStatus, null); assertTrue(questionAskedEvent.isAnswered()); }