Attendance { public void assureStatus(boolean isHoliday, TimeCard timeCard, Leave leave) { status = withCondition(isHoliday, timeCard, leave).toStatus(); } Attendance(String employeeId, LocalDate workDay); void assureStatus(boolean isHoliday, TimeCard timeCard, Leave leave); AttendanceStatus status();  }
@Test public void should_throw_InvalidAttendanceException_given_leave_with_different_workday() { LocalDate anotherWorkDay = LocalDate.of(2019, 12, 25); Leave leave = Leave.of(employeeId, anotherWorkDay, LeaveType.Sick); Attendance attendance = new Attendance(employeeId, workDay); assertThatThrownBy(() -> attendance.assureStatus(notHoliday, null, leave)) .isInstanceOf(InvalidAttendanceException.class) .hasMessageContaining("different work day for attendance, time card and leave"); }
@Test public void should_throw_InvalidAttendanceException_given_time_card_with_different_workday() { LocalDate anotherWorkDay = LocalDate.of(2019, 12, 25); TimeCard timeCard = TimeCard.of(anotherWorkDay, startWork, endWork, workTimeRule); Attendance attendance = new Attendance(employeeId, workDay); assertThatThrownBy(() -> attendance.assureStatus(notHoliday, timeCard, null)) .isInstanceOf(InvalidAttendanceException.class) .hasMessageContaining("different work day for attendance, time card and leave"); }