Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bseber committed Nov 15, 2024
1 parent 8458bd3 commit 16d2bc6
Showing 1 changed file with 59 additions and 57 deletions.
116 changes: 59 additions & 57 deletions src/test/java/de/focusshift/zeiterfassung/report/ReportDayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ void reportDayEntries() {
final ZonedDateTime to = dateTime(2024, 11, 13, 2, 0);
final ReportDayEntry reportDayEntry = new ReportDayEntry(batman, "hard work", from, to, true);

LocalDate reportDate = LocalDate.of(2024, 11, 13);
ReportDay reportDay = new ReportDay(reportDate, Map.of(), Map.of(batmanIdComposite, List.of(reportDayEntry)), Map.of());
final LocalDate reportDate = LocalDate.of(2024, 11, 13);
final ReportDay sut = new ReportDay(reportDate, Map.of(), Map.of(batmanIdComposite, List.of(reportDayEntry)), Map.of());

List<ReportDayEntry> reportDayEntries = reportDay.reportDayEntries();

assertThat(reportDayEntries).hasSize(1).containsExactly(reportDayEntry);
final List<ReportDayEntry> reportDayEntries = sut.reportDayEntries();
assertThat(reportDayEntries)
.hasSize(1)
.containsExactly(reportDayEntry);
}

@Test
Expand All @@ -61,17 +62,18 @@ void plannedWorkingHours() {
final UserLocalId robinLocalId = new UserLocalId(1337L);
final UserIdComposite robinIdComposite = new UserIdComposite(robinId, robinLocalId);

LocalDate reportDate = LocalDate.of(2024, 11, 13);
ReportDay reportDay = new ReportDay(
reportDate,
Map.of(
batmanIdComposite, new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of()),
robinIdComposite, new WorkingTimeCalendar(Map.of(reportDate, new PlannedWorkingHours(Duration.ofHours(4))), Map.of())
),
Map.of(),
Map.of());

assertThat(reportDay.plannedWorkingHours().duration()).isEqualTo(Duration.ofHours(12));
final LocalDate reportDate = LocalDate.of(2024, 11, 13);

final ReportDay sut = new ReportDay(
reportDate,
Map.of(
batmanIdComposite, new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of()),
robinIdComposite, new WorkingTimeCalendar(Map.of(reportDate, new PlannedWorkingHours(Duration.ofHours(4))), Map.of())
),
Map.of(),
Map.of());

assertThat(sut.plannedWorkingHours().duration()).isEqualTo(Duration.ofHours(12));
}

@Test
Expand All @@ -86,11 +88,11 @@ void ensureToRemoveBreaks() {
final ZonedDateTime to = dateTime(2021, 1, 4, 2, 0);
final ReportDayEntry reportDayEntry = new ReportDayEntry(batman, "hard work", from, to, true);

LocalDate reportDate = LocalDate.of(2021, 1, 4);
WorkingTimeCalendar workingTimeCalendar = new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of());
final ReportDay reportDay = new ReportDay(reportDate, Map.of(batmanIdComposite, workingTimeCalendar), Map.of(batmanIdComposite, List.of(reportDayEntry)), Map.of());
final LocalDate reportDate = LocalDate.of(2021, 1, 4);
final WorkingTimeCalendar workingTimeCalendar = new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of());

assertThat(reportDay.workDuration().duration()).isEqualTo(Duration.ZERO);
final ReportDay sut = new ReportDay(reportDate, Map.of(batmanIdComposite, workingTimeCalendar), Map.of(batmanIdComposite, List.of(reportDayEntry)), Map.of());
assertThat(sut.workDuration().duration()).isEqualTo(Duration.ZERO);
}

@Test
Expand All @@ -103,13 +105,13 @@ void shouldWorkingHoursReturnsZeroForFullyAbsentUser() {

final ZonedDateTime from = dateTime(2021, 1, 4, 1, 0);
final ZonedDateTime to = dateTime(2021, 1, 4, 2, 0);
Absence absence = new Absence(batmanId, from, to, FULL, locale -> "foo", RED, HOLIDAY);
final Absence absence = new Absence(batmanId, from, to, FULL, locale -> "foo", RED, HOLIDAY);

LocalDate reportDate = LocalDate.of(2021, 1, 4);
WorkingTimeCalendar workingTimeCalendar = new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of(reportDate, List.of(absence)));
final ReportDay reportDay = new ReportDay(reportDate, Map.of(batmanIdComposite, workingTimeCalendar), Map.of(batmanIdComposite, List.of()), Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence))));
final LocalDate reportDate = LocalDate.of(2021, 1, 4);
final WorkingTimeCalendar workingTimeCalendar = new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of(reportDate, List.of(absence)));

assertThat(reportDay.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ZERO));
final ReportDay sut = new ReportDay(reportDate, Map.of(batmanIdComposite, workingTimeCalendar), Map.of(batmanIdComposite, List.of()), Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence))));
assertThat(sut.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ZERO));
}

@ParameterizedTest
Expand All @@ -123,13 +125,13 @@ void shouldWorkingHoursReturnsHalfShouldWorkingHoursForHalfDayAbsentUser(DayLeng

final ZonedDateTime from = dateTime(2021, 1, 4, 1, 0);
final ZonedDateTime to = dateTime(2021, 1, 4, 2, 0);
Absence absence = new Absence(batmanId, from, to, dayLength, locale -> "foo", RED, HOLIDAY);
final Absence absence = new Absence(batmanId, from, to, dayLength, locale -> "foo", RED, HOLIDAY);

LocalDate reportDate = LocalDate.of(2021, 1, 4);
WorkingTimeCalendar workingTimeCalendar = new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of(reportDate, List.of(absence)));
final ReportDay reportDay = new ReportDay(LocalDate.of(2021, 1, 4), Map.of(batmanIdComposite, workingTimeCalendar), Map.of(batmanIdComposite, List.of()), Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence))));
final LocalDate reportDate = LocalDate.of(2021, 1, 4);
final WorkingTimeCalendar workingTimeCalendar = new WorkingTimeCalendar(Map.of(reportDate, PlannedWorkingHours.EIGHT), Map.of(reportDate, List.of(absence)));

assertThat(reportDay.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ofHours(4)));
final ReportDay sut = new ReportDay(LocalDate.of(2021, 1, 4), Map.of(batmanIdComposite, workingTimeCalendar), Map.of(batmanIdComposite, List.of()), Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence))));
assertThat(sut.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ofHours(4)));
}

@Test
Expand All @@ -142,27 +144,27 @@ void shouldWorkingHoursReturnsShouldHoursForOneAbsentUserAndOneWorkingUser() {

final ZonedDateTime from = dateTime(2021, 1, 4, 1, 0);
final ZonedDateTime to = dateTime(2021, 1, 4, 2, 0);
Absence absence = new Absence(batmanId, from, to, FULL, locale -> "foo", RED, HOLIDAY);
final Absence absence = new Absence(batmanId, from, to, FULL, locale -> "foo", RED, HOLIDAY);

final UserId robinId = new UserId("uuid2");
final UserLocalId robinLocalId = new UserLocalId(1337L);
final UserIdComposite robinIdComposite = new UserIdComposite(robinId, robinLocalId);

Map<UserIdComposite, List<ReportDayEntry>> entriesByUser = Map.of(batmanIdComposite, List.of(), robinIdComposite, List.of());
Map<UserIdComposite, List<ReportDayAbsence>> absencesByUser = Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence)), robinIdComposite, List.of());

LocalDate reportDate = LocalDate.of(2021, 1, 4);
Map<UserIdComposite, WorkingTimeCalendar> plannedWorkingHoursByUser = Map.of(
batmanIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, PlannedWorkingHours.EIGHT),
Map.of(reportDate, List.of(absence))),
robinIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, new PlannedWorkingHours(Duration.ofHours(4))),
Map.of(reportDate, List.of()))
final Map<UserIdComposite, List<ReportDayEntry>> entriesByUser = Map.of(batmanIdComposite, List.of(), robinIdComposite, List.of());
final Map<UserIdComposite, List<ReportDayAbsence>> absencesByUser = Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence)), robinIdComposite, List.of());

final LocalDate reportDate = LocalDate.of(2021, 1, 4);
final Map<UserIdComposite, WorkingTimeCalendar> plannedWorkingHoursByUser = Map.of(
batmanIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, PlannedWorkingHours.EIGHT),
Map.of(reportDate, List.of(absence))),
robinIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, new PlannedWorkingHours(Duration.ofHours(4))),
Map.of(reportDate, List.of()))
);
final ReportDay reportDay = new ReportDay(reportDate, plannedWorkingHoursByUser, entriesByUser, absencesByUser);

assertThat(reportDay.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ofHours(4L)));
final ReportDay sut = new ReportDay(reportDate, plannedWorkingHoursByUser, entriesByUser, absencesByUser);
assertThat(sut.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ofHours(4L)));
}

@ParameterizedTest
Expand All @@ -176,26 +178,26 @@ void shouldWorkingHoursReturnsSummedShouldHoursForOneHalfAbsentUserAndOneWorking

final ZonedDateTime from = dateTime(2021, 1, 4, 1, 0);
final ZonedDateTime to = dateTime(2021, 1, 4, 2, 0);
Absence absence = new Absence(batmanId, from, to, dayLength, locale -> "foo", RED, HOLIDAY);
final Absence absence = new Absence(batmanId, from, to, dayLength, locale -> "foo", RED, HOLIDAY);

final UserId robinId = new UserId("uuid2");
final UserLocalId robinLocalId = new UserLocalId(1337L);
final UserIdComposite robinIdComposite = new UserIdComposite(robinId, robinLocalId);

Map<UserIdComposite, List<ReportDayEntry>> entriesByUser = Map.of(batmanIdComposite, List.of(), robinIdComposite, List.of());
Map<UserIdComposite, List<ReportDayAbsence>> absencesByUser = Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence)), robinIdComposite, List.of());
LocalDate reportDate = LocalDate.of(2021, 1, 4);
Map<UserIdComposite, WorkingTimeCalendar> plannedWorkingHoursByUser = Map.of(
batmanIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, PlannedWorkingHours.EIGHT),
Map.of(reportDate, List.of(absence))),
robinIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, new PlannedWorkingHours(Duration.ofHours(4))),
Map.of(reportDate, List.of()))
final Map<UserIdComposite, List<ReportDayEntry>> entriesByUser = Map.of(batmanIdComposite, List.of(), robinIdComposite, List.of());
final Map<UserIdComposite, List<ReportDayAbsence>> absencesByUser = Map.of(batmanIdComposite, List.of(new ReportDayAbsence(batman, absence)), robinIdComposite, List.of());
final LocalDate reportDate = LocalDate.of(2021, 1, 4);
final Map<UserIdComposite, WorkingTimeCalendar> plannedWorkingHoursByUser = Map.of(
batmanIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, PlannedWorkingHours.EIGHT),
Map.of(reportDate, List.of(absence))),
robinIdComposite, new WorkingTimeCalendar(
Map.of(reportDate, new PlannedWorkingHours(Duration.ofHours(4))),
Map.of(reportDate, List.of()))
);
final ReportDay reportDay = new ReportDay(reportDate, plannedWorkingHoursByUser, entriesByUser, absencesByUser);

assertThat(reportDay.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ofHours(8L)));
final ReportDay sut = new ReportDay(reportDate, plannedWorkingHoursByUser, entriesByUser, absencesByUser);
assertThat(sut.shouldWorkingHours()).isEqualTo(new ShouldWorkingHours(Duration.ofHours(8L)));
}

private static ZonedDateTime dateTime(int year, int month, int dayOfMonth, int hour, int minute) {
Expand Down

0 comments on commit 16d2bc6

Please sign in to comment.