@Before public void setUp() throws Exception { calendarService = Mockito.mock(WorkDaysService.class); sickNoteDAO = Mockito.mock(SickNoteDAO.class); sickNotes = new ArrayList<>(); Person person = TestDataCreator.createPerson(); SickNote sickNote1 = TestDataCreator.createSickNote( person, new DateMidnight(2013, DateTimeConstants.OCTOBER, 7), new DateMidnight(2013, DateTimeConstants.OCTOBER, 11), DayLength.FULL); SickNote sickNote2 = TestDataCreator.createSickNote( person, new DateMidnight(2013, DateTimeConstants.DECEMBER, 18), new DateMidnight(2014, DateTimeConstants.JANUARY, 3), DayLength.FULL); sickNotes.add(sickNote1); sickNotes.add(sickNote2); Mockito.when(sickNoteDAO.findNumberOfPersonsWithMinimumOneSickNote(2013)).thenReturn(7L); Mockito.when(sickNoteDAO.findAllActiveByYear(2013)).thenReturn(sickNotes); Mockito.when( calendarService.getWorkDays( DayLength.FULL, new DateMidnight(2013, DateTimeConstants.OCTOBER, 7), new DateMidnight(2013, DateTimeConstants.OCTOBER, 11), person)) .thenReturn(new BigDecimal("5")); Mockito.when( calendarService.getWorkDays( DayLength.FULL, new DateMidnight(2013, DateTimeConstants.DECEMBER, 18), new DateMidnight(2013, DateTimeConstants.DECEMBER, 31), person)) .thenReturn(new BigDecimal("9")); statistics = new SickNoteStatistics(2013, sickNoteDAO, calendarService); }
@Test(expected = IllegalArgumentException.class) public void testGetTotalNumberOfSickDaysInvalidDateRange() throws Exception { Mockito.when(sickNoteDAO.findAllActiveByYear(2015)).thenReturn(sickNotes); statistics = new SickNoteStatistics(2015, sickNoteDAO, calendarService); statistics.getTotalNumberOfSickDays(); }
@Test public void testGetAverageDurationOfDiseasePerPersonDivisionByZero() throws Exception { Mockito.when(sickNoteDAO.findNumberOfPersonsWithMinimumOneSickNote(2013)).thenReturn(0L); statistics = new SickNoteStatistics(2013, sickNoteDAO, calendarService); Assert.assertEquals(BigDecimal.ZERO, statistics.getAverageDurationOfDiseasePerPerson()); }