Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAEL-8117 Add code for the Finding min date in list improvement #16939

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ static final Date findMaxDateOfWithComparator(List<Event> events) {
.max(Comparator.naturalOrder())
.get();
}

static final Date findMinDateOf(List<Event> events) {
if (events == null || events.isEmpty()) {
return null;
}
return events.stream()
.map(Event::getDate)
.min(Date::compareTo)
.get();
}

static final Date findMinDateOfWithComparator(List<Event> events) {
if (events == null || events.isEmpty()) {
return null;
}
return events.stream()
.map(Event::getDate)
.min(Comparator.naturalOrder())
.get();
}

static final LocalDate findMaxDateOfLocalEvents(List<LocalEvent> events) {
if (events == null || events.isEmpty()) {
Expand All @@ -46,5 +66,25 @@ static final LocalDate findMaxDateOfLocalEventsWithComparator(List<LocalEvent> e
.max(Comparator.naturalOrder())
.get();
}

static final LocalDate findMinDateOfLocalEvents(List<LocalEvent> events) {
if (events == null || events.isEmpty()) {
return null;
}
return events.stream()
.map(LocalEvent::getDate)
.min(LocalDate::compareTo)
.get();
}

static final LocalDate findMinDateOfLocalEventsWithComparator(List<LocalEvent> events) {
if (events == null || events.isEmpty()) {
return null;
}
return events.stream()
.map(LocalEvent::getDate)
.min(Comparator.naturalOrder())
.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,83 +27,164 @@ class DateHelperUnitTest {
LocalEvent NEXT_WEEK_LOCAL_EVENT = new LocalEvent(NEXT_WEEK_LOCAL);

@Test
void givenNullEventList_WhenFindMaxDateOf_ThenNull() {
void givenNullEventList_whenFindMaxDateOf_thenNull() {
assertNull(DateHelper.findMaxDateOf(null));
}

@Test
void givenEmptyEventList_WhenFindMaxDateOf_ThenNull() {
void givenEmptyEventList_whenFindMaxDateOf_thenNull() {
assertNull(DateHelper.findMaxDateOf(List.of()));
}

@Test
void givenSingleElementEventList_WhenFindMaxDateOf_ThenReturnElementDate() {
void givenSingleElementEventList_whenFindMaxDateOf_thenReturnElementDate() {
assertEquals(TODAY, DateHelper.findMaxDateOf(List.of(TODAYS_EVENT)));
}

@Test
void givenEventList_WhenFindMaxDateOf_ThenReturnMaxDate() {
void givenEventList_whenFindMaxDateOf_thenReturnMaxDate() {
assertEquals(NEXT_WEEK, DateHelper.findMaxDateOf(List.of(TODAYS_EVENT, TOMORROWS_EVENT, NEXT_WEEK_EVENT)));
}

@Test
void givenNullEventList_WhenFindMaxDateOfWithComparator_ThenNull() {
void givenNullEventList_whenFindMaxDateOfWithComparator_thenNull() {
assertNull(DateHelper.findMaxDateOfWithComparator(null));
}

@Test
void givenEmptyEventList_WhenFindMaxDateOfWithComparator_ThenNull() {
void givenEmptyEventList_whenFindMaxDateOfWithComparator_thenNull() {
assertNull(DateHelper.findMaxDateOfWithComparator(List.of()));
}

@Test
void givenSingleElementEventList_WhenFindMaxDateOfWithComparator_ThenReturnElementDate() {
void givenSingleElementEventList_whenFindMaxDateOfWithComparator_thenReturnElementDate() {
assertEquals(TODAY, DateHelper.findMaxDateOfWithComparator(List.of(TODAYS_EVENT)));
}

@Test
void givenEventList_WhenFindMaxDateOfWithComparator_ThenReturnMaxDate() {
void givenEventList_whenFindMaxDateOfWithComparator_thenReturnMaxDate() {
assertEquals(NEXT_WEEK, DateHelper.findMaxDateOfWithComparator(List.of(TODAYS_EVENT, TOMORROWS_EVENT, NEXT_WEEK_EVENT)));
}

@Test
void givenNullEventList_whenFindMinDateOf_thenNull() {
assertNull(DateHelper.findMinDateOf(null));
}

@Test
void givenEmptyEventList_whenFindMinDateOf_thenNull() {
assertNull(DateHelper.findMinDateOf(List.of()));
}

@Test
void givenSingleElementEventList_whenFindMinDateOf_thenReturnElementDate() {
assertEquals(TODAY, DateHelper.findMinDateOf(List.of(TODAYS_EVENT)));
}

@Test
void givenEventList_whenFindMinDateOf_thenReturnMinDate() {
assertEquals(TODAY, DateHelper.findMinDateOf(List.of(TODAYS_EVENT, TOMORROWS_EVENT, NEXT_WEEK_EVENT)));
}

@Test
void givenNullEventList_whenFindMinDateOfWithComparator_thenNull() {
assertNull(DateHelper.findMinDateOfWithComparator(null));
}

@Test
void givenEmptyEventList_whenFindMinDateOfWithComparator_thenNull() {
assertNull(DateHelper.findMinDateOfWithComparator(List.of()));
}

@Test
void givenSingleElementEventList_whenFindMinDateOfWithComparator_thenReturnElementDate() {
assertEquals(TODAY, DateHelper.findMinDateOfWithComparator(List.of(TODAYS_EVENT)));
}

@Test
void givenEventList_whenFindMinDateOfWithComparator_thenReturnMaxDate() {
assertEquals(TODAY, DateHelper.findMinDateOfWithComparator(List.of(TODAYS_EVENT, TOMORROWS_EVENT, NEXT_WEEK_EVENT)));
}

@Test
void givenNullLocalEventList_WhenFindMaxDateOfLocalEvents_ThenNull() {
void givenNullLocalEventList_whenFindMaxDateOfLocalEvents_thenNull() {
assertNull(DateHelper.findMaxDateOfLocalEvents(null));
}

@Test
void givenEmptyLocalEventList_WhenFindMaxDateOfLocalEvents_ThenNull() {
void givenEmptyLocalEventList_whenFindMaxDateOfLocalEvents_thenNull() {
assertNull(DateHelper.findMaxDateOfLocalEvents(List.of()));
}

@Test
void givenSingleElementLocalEventList_WhenFindMaxDateOfLocalEvents_ThenReturnElementDate() {
void givenSingleElementLocalEventList_whenFindMaxDateOfLocalEvents_thenReturnElementDate() {
assertEquals(TODAY_LOCAL, DateHelper.findMaxDateOfLocalEvents(List.of(TODAY_LOCAL_EVENT)));
}

@Test
void givenLocalEventList_WhenFindMaxDateOfLocalEvents_ThenReturnMaxDate() {
void givenLocalEventList_whenFindMaxDateOfLocalEvents_thenReturnMaxDate() {
assertEquals(NEXT_WEEK_LOCAL, DateHelper.findMaxDateOfLocalEvents(List.of(TODAY_LOCAL_EVENT, TOMORROW_LOCAL_EVENT, NEXT_WEEK_LOCAL_EVENT)));
}

@Test
void givenNullLocalEventList_WhenFindMaxDateOfLocalEventsWithComparator_ThenNull() {
void givenNullLocalEventList_whenFindMaxDateOfLocalEventsWithComparator_thenNull() {
assertNull(DateHelper.findMaxDateOfLocalEventsWithComparator(null));
}

@Test
void givenEmptyLocalEventList_WhenFindMaxDateOfLocalEventsWithComparator_ThenNull() {
void givenEmptyLocalEventList_whenFindMaxDateOfLocalEventsWithComparator_thenNull() {
assertNull(DateHelper.findMaxDateOfLocalEventsWithComparator(List.of()));
}

@Test
void givenSingleElementLocalEventList_WhenFindMaxDateOfLocalEventsWithComparator_ThenReturnElementDate() {
void givenSingleElementLocalEventList_whenFindMaxDateOfLocalEventsWithComparator_thenReturnElementDate() {
assertEquals(TODAY_LOCAL, DateHelper.findMaxDateOfLocalEventsWithComparator(List.of(TODAY_LOCAL_EVENT)));
}

@Test
void givenLocalEventList_WhenFindMaxDateOfLocalEventsWithComparator_ThenReturnMaxDate() {
void givenLocalEventList_whenFindMaxDateOfLocalEventsWithComparator_thenReturnMaxDate() {
assertEquals(NEXT_WEEK_LOCAL, DateHelper.findMaxDateOfLocalEventsWithComparator(List.of(TODAY_LOCAL_EVENT, TOMORROW_LOCAL_EVENT, NEXT_WEEK_LOCAL_EVENT)));
}

@Test
void givenNullLocalEventList_whenFindinxDateOfLocalEvents_thenNull() {
assertNull(DateHelper.findMinDateOfLocalEvents(null));
}

@Test
void givenEmptyLocalEventList_whenFindMinDateOfLocalEvents_thenNull() {
assertNull(DateHelper.findMinDateOfLocalEvents(List.of()));
}

@Test
void givenSingleElementLocalEventList_whenFindMinDateOfLocalEvents_thenReturnElementDate() {
assertEquals(TODAY_LOCAL, DateHelper.findMinDateOfLocalEvents(List.of(TODAY_LOCAL_EVENT)));
}

@Test
void givenLocalEventList_whenFindMinDateOfLocalEvents_thenReturnMaxDate() {
assertEquals(TODAY_LOCAL, DateHelper.findMinDateOfLocalEvents(List.of(TODAY_LOCAL_EVENT, TOMORROW_LOCAL_EVENT, NEXT_WEEK_LOCAL_EVENT)));
}

@Test
void givenNullLocalEventList_whenFindMinDateOfLocalEventsWithComparator_thenNull() {
assertNull(DateHelper.findMinDateOfLocalEventsWithComparator(null));
}

@Test
void givenEmptyLocalEventList_whenFindMinDateOfLocalEventsWithComparator_thenNull() {
assertNull(DateHelper.findMinDateOfLocalEventsWithComparator(List.of()));
}

@Test
void givenSingleElementLocalEventList_whenFindMinDateOfLocalEventsWithComparator_thenReturnElementDate() {
assertEquals(TODAY_LOCAL, DateHelper.findMinDateOfLocalEventsWithComparator(List.of(TODAY_LOCAL_EVENT)));
}

@Test
void givenLocalEventList_whenFindMinDateOfLocalEventsWithComparator_thenReturnMaxDate() {
assertEquals(TODAY_LOCAL, DateHelper.findMinDateOfLocalEventsWithComparator(List.of(TODAY_LOCAL_EVENT, TOMORROW_LOCAL_EVENT, NEXT_WEEK_LOCAL_EVENT)));
}


}