@Test public void ensureIsNotAllDayForNoonPeriod() { DateMidnight today = DateMidnight.now(); Period period = new Period(today, today, DayLength.NOON); Absence absence = new Absence(person, period, EventType.ALLOWED_APPLICATION, timeConfiguration); Assert.assertFalse("Should be not all day", absence.isAllDay()); }
@Test public void ensureIsAllDayForFullDayPeriod() { DateMidnight start = DateMidnight.now(); DateMidnight end = start.plusDays(2); Period period = new Period(start, end, DayLength.FULL); Absence absence = new Absence(person, period, EventType.ALLOWED_APPLICATION, timeConfiguration); Assert.assertTrue("Should be all day", absence.isAllDay()); }
@Test public void ensureCorrectTimeForMorningAbsence() { DateMidnight today = DateMidnight.now(); Date start = today.toDateTime().withHourOfDay(8).toDate(); Date end = today.toDateTime().withHourOfDay(12).toDate(); Period period = new Period(today, today, DayLength.MORNING); Absence absence = new Absence(person, period, EventType.ALLOWED_APPLICATION, timeConfiguration); Assert.assertEquals("Should start at 8 am", start, absence.getStartDate()); Assert.assertEquals("Should end at 12 pm", end, absence.getEndDate()); }
@Test public void ensureCorrectEventSubject() { DateMidnight today = DateMidnight.now(); Period period = new Period(today, today, DayLength.FULL); BiConsumer<EventType, String> assertCorrectEventSubject = (type, subject) -> { Absence absence = new Absence(person, period, type, timeConfiguration); assertThat(absence.getEventType(), is(type)); assertThat(absence.getEventSubject(), is(subject)); }; assertCorrectEventSubject.accept( EventType.WAITING_APPLICATION, "Antrag auf Urlaub Marlene Muster"); assertCorrectEventSubject.accept(EventType.ALLOWED_APPLICATION, "Urlaub Marlene Muster"); assertCorrectEventSubject.accept(EventType.SICKNOTE, "Marlene Muster krank"); }
@Test public void ensureCanBeInstantiatedWithCorrectProperties() { DateMidnight start = new DateMidnight(2015, 9, 21); DateMidnight end = new DateMidnight(2015, 9, 23); Period period = new Period(start, end, DayLength.FULL); Absence absence = new Absence(person, period, EventType.WAITING_APPLICATION, timeConfiguration); Assert.assertNotNull("Start date must not be null", absence.getStartDate()); Assert.assertNotNull("End date must not be null", absence.getEndDate()); Assert.assertNotNull("Person must not be null", absence.getPerson()); Assert.assertNotNull("Event type must not be null", absence.getEventType()); Assert.assertEquals("Wrong start date", start.toDate(), absence.getStartDate()); Assert.assertEquals("Wrong end date", end.plusDays(1).toDate(), absence.getEndDate()); Assert.assertEquals("Wrong person", person, absence.getPerson()); Assert.assertEquals("Wrong event type", EventType.WAITING_APPLICATION, absence.getEventType()); }
@Test public void ensureCanBeInstantiatedWithCorrectPropertiesConsideringDaylightSavingTime() { // Date where daylight saving time is relevant DateMidnight start = new DateMidnight(2015, 10, 23); DateMidnight end = new DateMidnight(2015, 10, 25); Period period = new Period(start, end, DayLength.FULL); Absence absence = new Absence(person, period, EventType.ALLOWED_APPLICATION, timeConfiguration); Assert.assertNotNull("Start date must not be null", absence.getStartDate()); Assert.assertNotNull("End date must not be null", absence.getEndDate()); Assert.assertNotNull("Person must not be null", absence.getPerson()); Assert.assertNotNull("Event type must not be null", absence.getEventType()); Assert.assertEquals("Wrong start date", start.toDate(), absence.getStartDate()); Assert.assertEquals("Wrong end date", end.plusDays(1).toDate(), absence.getEndDate()); Assert.assertEquals("Wrong person", person, absence.getPerson()); Assert.assertEquals("Wrong event type", EventType.ALLOWED_APPLICATION, absence.getEventType()); }