Skip to content

Commit c4e9bbc

Browse files
author
extern-maksim-kuzmin1
committed
fix: skip empty predicate for employee report
1 parent 627604a commit c4e9bbc

File tree

7 files changed

+10
-9
lines changed

7 files changed

+10
-9
lines changed

src/main/java/com/whiskels/notifier/reporting/service/employee/convert/EmployeeEventReportMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Iterable<Payload> convert(@Nonnull ReportData<Employee> data) {
4444
}
4545

4646
private Payload createReport(ReportData<Employee> data, ReportContext context) {
47-
var skipEmpty = context.isSkipEmpty();
47+
var skipEmpty = context.getSkipEmpty().test(data.requestDate());
4848

4949
List<EmployeeDto> birthdays = data.data().stream()
5050
.filter(employee -> context.getBirthdayPredicate().test(employee, data.requestDate()))

src/main/java/com/whiskels/notifier/reporting/service/employee/convert/ReportContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@AllArgsConstructor
1818
public class ReportContext {
1919
private final Function<LocalDate, String> headerMapper;
20-
private final boolean skipEmpty;
20+
private final Predicate<LocalDate> skipEmpty;
2121
private final BiPredicate<Employee, LocalDate> birthdayPredicate;
2222
private final BiPredicate<Employee, LocalDate> anniversaryPredicate;
2323
}

src/main/java/com/whiskels/notifier/reporting/service/employee/convert/context/BeforeEventReportContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class BeforeEventReportContext extends ReportContext {
1616
public BeforeEventReportContext(String headerPrefix, int daysBefore) {
1717
super(date -> STR."\{headerPrefix}\{reportDate(date)}",
18-
false,
18+
_ -> true,
1919
(employee, date) -> {
2020
var birthday = employee.getBirthday();
2121
return isSameDay(birthday, date.plusDays(daysBefore));

src/main/java/com/whiskels/notifier/reporting/service/employee/convert/context/DailyReportContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public class DailyReportContext extends ReportContext {
2626
};
2727

2828
public DailyReportContext(String headerPrefix) {
29-
super(date -> STR."\{headerPrefix}\{reportDate(date)}", true, BIRTHDAY_PREDICATE, ANNIVERSARY_PREDICATE);
29+
super(date -> STR."\{headerPrefix}\{reportDate(date)}", _ -> true, BIRTHDAY_PREDICATE, ANNIVERSARY_PREDICATE);
3030
}
3131
}

src/main/java/com/whiskels/notifier/reporting/service/employee/convert/context/MonthMiddleReportContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import static com.whiskels.notifier.utilities.DateTimeUtil.isLater;
1010
import static com.whiskels.notifier.utilities.DateTimeUtil.isSameMonth;
11+
import static com.whiskels.notifier.utilities.DateTimeUtil.reportDate;
1112

1213
public class MonthMiddleReportContext extends ReportContext {
1314
private static final BiPredicate<Employee, LocalDate> BIRTHDAY_PREDICATE = (employee, date) -> {
@@ -21,7 +22,7 @@ public class MonthMiddleReportContext extends ReportContext {
2122
};
2223

2324
public MonthMiddleReportContext(String header) {
24-
super(_ignored -> header, false, BIRTHDAY_PREDICATE, ANNIVERSARY_PREDICATE);
25+
super(_ignored -> header, MonthMiddleReportContext::isMiddleOfMonth, BIRTHDAY_PREDICATE, ANNIVERSARY_PREDICATE);
2526
}
2627

2728
private static boolean isMiddleOfMonth(LocalDate date) {

src/main/java/com/whiskels/notifier/reporting/service/employee/convert/context/MonthStartReportContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MonthStartReportContext extends ReportContext {
2323
};
2424

2525
public MonthStartReportContext(String header) {
26-
super(_ignored -> header, false, BIRTHDAY_PREDICATE, ANNIVERSARY_PREDICATE);
26+
super(_ignored -> header, MonthStartReportContext::isStartOfMonth, BIRTHDAY_PREDICATE, ANNIVERSARY_PREDICATE);
2727
}
2828

2929
private static boolean isStartOfMonth(LocalDate date) {

src/test/java/com/whiskels/notifier/reporting/service/employee/convert/EmployeeEventReportMessageConverterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ void shouldConvertEmployeePayload() {
160160
"metadata" : null
161161
}""";
162162
ReportContext birthdayContext = mock(ReportContext.class);
163-
when(birthdayContext.isSkipEmpty()).thenReturn(false);
163+
when(birthdayContext.getSkipEmpty()).thenReturn(_ -> false);
164164
when(birthdayContext.getBirthdayPredicate()).thenReturn((_, _) -> true);
165165
when(birthdayContext.getAnniversaryPredicate()).thenReturn((_, _) -> false);
166166
when(birthdayContext.getHeaderMapper()).thenReturn(_ -> "Birthday Header");
167167

168168
ReportContext anniversaryContext = mock(ReportContext.class);
169-
when(anniversaryContext.isSkipEmpty()).thenReturn(true);
169+
when(anniversaryContext.getSkipEmpty()).thenReturn(_ -> true);
170170
when(anniversaryContext.getBirthdayPredicate()).thenReturn((_, _) -> false);
171171
when(anniversaryContext.getAnniversaryPredicate()).thenReturn((_, _) -> true);
172172
when(anniversaryContext.getHeaderMapper()).thenReturn(_ -> "Anniversary Header");
@@ -192,7 +192,7 @@ void shouldConvertEmployeePayload() {
192192
@DisplayName("Should return null if skip empty and no data")
193193
void shouldReturnNullIfSkipEmptyAndNoData() {
194194
ReportContext context = mock(ReportContext.class);
195-
when(context.isSkipEmpty()).thenReturn(true);
195+
when(context.getSkipEmpty()).thenReturn(_ -> true);
196196
when(context.getBirthdayPredicate()).thenReturn((_, _) -> false);
197197
when(context.getAnniversaryPredicate()).thenReturn((_, _) -> false);
198198

0 commit comments

Comments
 (0)