@Test public void gradeBookIsUpdatedOnRecordGradeEventForOnTimeSubmission() { GradeBook book = new GradeBook("Test"); Student student = new Student("studentId"); book.addStudent(student); Assignment poa = new Assignment("poa", 1.0); book.addAssignment(poa); bus.post(new GradeBookLoaded(book)); boolean isLate = false; double score = 0.6; this.bus.post(new RecordGradeEvent(score, student, poa, isLate)); Grade grade = student.getGrade(poa.getName()); assertThat(grade, notNullValue()); assertThat(grade.getScore(), equalTo(score)); assertThat(student.getLate(), not(contains(poa.getName()))); }
@Test public void recordingGradeEnablesSaveGradeBookInView() { GradeBook book = new GradeBook("Test"); Student student = new Student("studentId"); book.addStudent(student); Assignment poa = new Assignment("poa", 1.0); book.addAssignment(poa); student.setGrade(poa, 0.9); bus.post(new GradeBookLoaded(book)); verify(view).canSaveGradeBook(false); boolean isLate = false; double newScore = 0.6; this.bus.post(new RecordGradeEvent(newScore, student, poa, isLate)); verify(view).canSaveGradeBook(true); }
@Test public void savingGradeBookInViewPublishesSaveGradeBookEvent() throws IOException { ArgumentCaptor<SaveGradeBookListener> listener = ArgumentCaptor.forClass(SaveGradeBookListener.class); verify(this.view).addSaveGradeBookListener(listener.capture()); GradeBook book = new GradeBook("Test"); Student student = new Student("studentId"); book.addStudent(student); Assignment poa = new Assignment("poa", 1.0); book.addAssignment(poa); student.setGrade(poa, 0.9); bus.post(new GradeBookLoaded(book)); SaveGradeBookEventHandler eventHandler = mock(SaveGradeBookEventHandler.class); bus.register(eventHandler); listener.getValue().saveGradeBook(); ArgumentCaptor<SaveGradeBook> event = ArgumentCaptor.forClass(SaveGradeBook.class); verify(eventHandler).saveGradeBook(event.capture()); assertThat(event.getValue().getGradeBook(), equalTo(book)); }