jomarko commented on code in PR #3788:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3788#discussion_r1875866522


##########
jbpm/jbpm-flow/src/test/java/org/jbpm/process/core/timer/BusinessCalendarImplTest.java:
##########
@@ -18,491 +18,367 @@
  */
 package org.jbpm.process.core.timer;
 
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Date;
+import java.util.List;
 import java.util.Properties;
-import java.util.concurrent.TimeUnit;
+import java.util.function.BiFunction;
+import java.util.stream.IntStream;
 
 import org.jbpm.test.util.AbstractBaseTest;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
-import org.kie.kogito.timer.SessionPseudoClock;
 import org.slf4j.LoggerFactory;
 
+import static java.time.temporal.ChronoUnit.DAYS;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.jbpm.process.core.timer.BusinessCalendarImpl.END_HOUR;
+import static org.jbpm.process.core.timer.BusinessCalendarImpl.HOLIDAYS;
+import static 
org.jbpm.process.core.timer.BusinessCalendarImpl.HOLIDAY_DATE_FORMAT;
+import static org.jbpm.process.core.timer.BusinessCalendarImpl.START_HOUR;
+import static org.jbpm.process.core.timer.BusinessCalendarImpl.WEEKEND_DAYS;
 
-public class BusinessCalendarImplTest extends AbstractBaseTest {
+class BusinessCalendarImplTest extends AbstractBaseTest {
 
     public void addLogger() {
         logger = LoggerFactory.getLogger(this.getClass());
     }
 
     @Test
-    public void testCalculateHours() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-04 16:45";
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-04 13:45").getTime());
-
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("3h");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
-    }
-
-    @Test
-    public void testCalculateHoursCustomWorkingHours() {
-        Properties config = new Properties();
-        config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "6");
-        String expectedDate = "2012-05-04 15:45";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-03 13:45").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("8h");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
-    }
-
-    @Test
-    public void testCalculateHoursPassingOverWeekend() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-07 12:45";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-04 13:45").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("7h");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
-    }
-
-    @Test
-    public void testCalculateHoursPassingOverCustomDefinedWeekend() {
-        Properties config = new Properties();
-        config.setProperty(BusinessCalendarImpl.WEEKEND_DAYS, Calendar.FRIDAY 
+ "," + Calendar.SATURDAY);
-        String expectedDate = "2012-05-06 12:45";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-03 13:45").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("7h");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
-    }
-
-    @Test
-    public void testCalculateMinutesPassingOverWeekend() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-07 09:15";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-04 16:45").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("30m");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
-    }
-
-    @Test
-    public void testCalculateMinutesPassingOverHoliday() {
-        Properties config = new Properties();
-        config.setProperty(BusinessCalendarImpl.HOLIDAYS, 
"2012-05-12:2012-05-19");
-        String expectedDate = "2012-05-21 09:15";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-11 16:45").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("30m");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
-    }
-
-    @Test
-    public void testCalculateDays() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-14 09:00";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDate("2012-05-04").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("6d");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
+    void instantiate() {
+        BusinessCalendarImpl retrieved = 
BusinessCalendarImpl.builder().build();
+        assertThat(retrieved).isNotNull();
+        retrieved = BusinessCalendarImpl.builder()
+                .withCalendarBean(CalendarBeanFactory.createCalendarBean())
+                .build();
+        assertThat(retrieved).isNotNull();
+
+        Properties calendarConfiguration = new Properties();
+        int startHour = 10;
+        int endHour = 16;
+        calendarConfiguration.put(START_HOUR, String.valueOf(startHour));
+        calendarConfiguration.put(END_HOUR, String.valueOf(endHour));
+        retrieved = BusinessCalendarImpl.builder()
+                .withCalendarBean(new CalendarBean(calendarConfiguration))
+                .build();
+        assertThat(retrieved).isNotNull();
     }
 
     @Test
-    public void testCalculateDaysStartingInWeekend() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-09 09:00";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDate("2012-05-05").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("2d");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
+    void calculateBusinessTimeAsDateInsideDailyWorkingHourWithDelay() {
+        int daysToSkip = 0; // since executionHourDelay falls before endHOurGap
+        commonCalculateBusinessTimeAsDateAssertBetweenHours(-4, 4, 0, 3, 
daysToSkip, null, null);
     }
 
     @Test
-    public void testCalculateDaysCustomWorkingDays() {
-        Properties config = new Properties();
-        config.setProperty(BusinessCalendarImpl.DAYS_PER_WEEK, "4");
-        config.setProperty(BusinessCalendarImpl.WEEKEND_DAYS, Calendar.FRIDAY 
+ "," + Calendar.SATURDAY + "," + Calendar.SUNDAY);
-        String expectedDate = "2012-05-15 14:30";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-03 14:30").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("6d");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
+    void calculateBusinessTimeAsDateInsideDailyWorkingHourWithoutDelay() {
+        int daysToSkip = 0; // since executionHourDelay falls before endHOurGap
+        commonCalculateBusinessTimeAsDateAssertBetweenHours(-4, 4, 0, 0, 
daysToSkip, null, null);
     }
 
+    @Disabled("TO FIX 
https://github.com/apache/incubator-kie-issues/issues/1651";)
     @Test
-    public void testCalculateDaysMiddleDay() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-11 12:27";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDateWithTime("2012-05-03 12:27").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("6d");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
+    void calculateBusinessTimeAsDateInsideNightlyWorkingHour() {
+        int daysToSkip = 0; // since executionHourDelay falls before endHOurGap
+        commonCalculateBusinessTimeAsDateAssertBetweenHours(4, -4, 0, 3, 
daysToSkip, null, null);
     }
 
     @Test
-    public void testCalculateDaysHoursMinutes() {
-        Properties config = new Properties();
-        String expectedDate = "2012-05-14 14:20";
-
-        SessionPseudoClock clock = new 
StaticPseudoClock(parseToDate("2012-05-04").getTime());
-        BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, 
clock);
-
-        Date result = businessCal.calculateBusinessTimeAsDate("6d4h80m");
-
-        assertThat(formatDate("yyyy-MM-dd HH:mm", 
result)).isEqualTo(expectedDate);
+    void calculateBusinessTimeAsDateBeforeWorkingHourWithDelay() {
+        int daysToSkip = 0; // since executionHourDelay falls before endHOurGap
+        commonCalculateBusinessTimeAsDateAssertBetweenHours(2, 4, -1, 1, 
daysToSkip, null, null);
     }
 
     @Test
-    public void testCalculateTimeDaysHoursMinutesHolidays() {
+    void calculateBusinessTimeAsDateBeforeWorkingHourWithDelayFineGrained() {

Review Comment:
   I like the structure of this test 
`calculateBusinessTimeAsDateBeforeWorkingHourWithDelayFineGrained`. I can 
understand its goal even without deep knowwledge of `BusinessCalendar`ish code. 
   
   Tests, that reduce the code repetition using 
`commonCalculateBusinessTimeAsDateAssertBetweenHours` are not easy to read and 
understand for me. My comment is, that more natural language === more smaller 
methods would help to understand the tests. However I am not going to block the 
PR as I am not sure if we have resources to address my point. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to