[jbpm-commits] JBoss JBPM SVN: r6630 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: test/java/org/jbpm/calendar and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Aug 27 16:04:46 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-08-27 16:04:45 -0400 (Fri, 27 Aug 2010)
New Revision: 6630

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
Log:
JBPM-1776 rework findPreviousDayPart and findNextDayPart methods

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java	2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/BusinessCalendar.java	2010-08-27 20:04:45 UTC (rev 6630)
@@ -32,7 +32,6 @@
 import java.util.Properties;
 
 import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmException;
 import org.jbpm.util.ClassLoaderUtil;
 
 /**
@@ -66,13 +65,8 @@
   }
 
   public BusinessCalendar(Properties calendarProperties) {
-    try {
-      weekDays = Day.parseWeekDays(calendarProperties, this);
-      holidays = Holiday.parseHolidays(calendarProperties, this);
-    }
-    catch (Exception e) {
-      throw new JbpmException("could not create business calendar", e);
-    }
+    weekDays = Day.parseWeekDays(calendarProperties, this);
+    holidays = Holiday.parseHolidays(calendarProperties, this);
   }
 
   public Day[] getWeekDays() {
@@ -98,15 +92,12 @@
       if (dayPart == null) {
         // outside business hours
         Day day = findDay(date);
-        Object[] result = new Object[2];
         if (duration.isNegative()) {
-          day.findPreviousDayPartEnd(date, result);
+          dayPart = day.findPreviousDayPart(date);
         }
         else {
-          day.findNextDayPartStart(0, date, result);
+          dayPart = day.findNextDayPart(date);
         }
-        date = (Date) result[0];
-        dayPart = (DayPart) result[1];
       }
       end = dayPart.add(date, duration);
     }
@@ -182,9 +173,7 @@
     if (nextDayPart == null) {
       date = findStartOfNextDay(date);
       Day day = findDay(date);
-      Object result[] = new Object[2];
-      day.findNextDayPartStart(0, date, result);
-      nextDayPart = (DayPart) result[1];
+      nextDayPart = day.findNextDayPart(date);
     }
     return nextDayPart;
   }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java	2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java	2010-08-27 20:04:45 UTC (rev 6630)
@@ -49,7 +49,8 @@
 
     Day[] weekDays = new Day[WEEK_DAY_KEYS.length];
     for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
-      weekDays[i] = new Day(calendarProperties.getProperty(WEEK_DAY_KEYS[i]), timeFormat,
+      weekDays[i] = new Day(calendarProperties.getProperty(WEEK_DAY_KEYS[i]),
+        timeFormat,
         businessCalendar);
     }
     return weekDays;
@@ -70,6 +71,7 @@
     }
   }
 
+  /** @deprecated with no replacement */
   public void findNextDayPartStart(int dayPartIndex, Date date, Object[] result) {
     // if there is a day part that starts after the given date
     if (dayPartIndex < dayParts.length) {
@@ -90,26 +92,64 @@
     }
   }
 
-  void findPreviousDayPartEnd(Date date, Object[] result) {
-    findPreviousDayPartEnd(dayParts.length - 1, date, result);
+  DayPart findNextDayPart(Date date) {
+    return findNextDayPart(date, 0);
   }
 
-  void findPreviousDayPartEnd(int dayPartIndex, Date date, Object[] result) {
+  /**
+   * Finds the business day part that starts on or after the given date and determines the time
+   * that day part begins.
+   * 
+   * @param date on input, the base date; on output, the day part start date.
+   * <strong>Beware!</strong> The method modifies the date.
+   */
+  DayPart findNextDayPart(Date date, int dayPartIndex) {
+    // if there is a day part that starts after the given date
+    if (dayPartIndex < dayParts.length) {
+      DayPart dayPart = dayParts[dayPartIndex];
+      if (dayPart.isStartAfter(date)) {
+        date.setTime(dayPart.getStartTime(date).getTime());
+        return dayPart;
+      }
+      else {
+        return findNextDayPart(date, dayPartIndex + 1);
+      }
+    }
+    else {
+      // descend recursively
+      date.setTime(businessCalendar.findStartOfNextDay(date).getTime());
+      Day nextDay = businessCalendar.findDay(date);
+      return nextDay.findNextDayPart(date);
+    }
+  }
+
+  DayPart findPreviousDayPart(Date date) {
+    return findPreviousDayPart(date, dayParts.length - 1);
+  }
+
+  /**
+   * Finds the business day part that ends on or before the given date and determines the time
+   * that day part ends.
+   * 
+   * @param date on input, the base date; on output, the day part end date.
+   * <strong>Beware!</strong> The method modifies the date.
+   */
+  DayPart findPreviousDayPart(Date date, int dayPartIndex) {
     // if there is a day part that ends before the given date
     if (dayPartIndex >= 0) {
       DayPart dayPart = dayParts[dayPartIndex];
       if (dayPart.endsBefore(date)) {
-        result[0] = dayPart.getEndTime(date);
-        result[1] = dayPart;
+        date.setTime(dayPart.getEndTime(date).getTime());
+        return dayPart;
       }
       else {
-        findPreviousDayPartEnd(dayPartIndex - 1, date, result);
+        return findPreviousDayPart(date, dayPartIndex - 1);
       }
     }
     else {
-      date = businessCalendar.findEndOfPreviousDay(date);
+      date.setTime(businessCalendar.findEndOfPreviousDay(date).getTime());
       Day previousDay = businessCalendar.findDay(date);
-      previousDay.findPreviousDayPartEnd(date, result);
+      return previousDay.findPreviousDayPart(date);
     }
   }
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java	2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/DayPart.java	2010-08-27 20:04:45 UTC (rev 6630)
@@ -38,8 +38,8 @@
   final int endHour;
   final int endMinute;
 
-  final Day day;
-  final int index;
+  private final Day day;
+  private final int index;
 
   public DayPart(String dayPartText, DateFormat timeFormat, Day day, int index) {
     // parse start time
@@ -90,10 +90,8 @@
       Duration remainder = new Duration(durationMillis - dayPartMillis);
       Date dayPartStartDate = new Date(date.getTime() + dayPartMillis);
 
-      Object[] result = new Object[2];
-      day.findPreviousDayPartEnd(index - 1, dayPartStartDate, result);
-      Date previousDayPartEnd = (Date) result[0];
-      DayPart previousDayPart = (DayPart) result[1];
+      DayPart previousDayPart = day.findPreviousDayPart(dayPartStartDate, index - 1);
+      Date previousDayPartEnd = dayPartStartDate;
 
       return previousDayPart.add(previousDayPartEnd, remainder);
     }
@@ -105,10 +103,8 @@
       Duration remainder = new Duration(durationMillis - dayPartMillis);
       Date dayPartEndDate = new Date(date.getTime() + dayPartMillis);
 
-      Object[] result = new Object[2];
-      day.findNextDayPartStart(index + 1, dayPartEndDate, result);
-      Date nextDayPartStart = (Date) result[0];
-      DayPart nextDayPart = (DayPart) result[1];
+      DayPart nextDayPart = day.findNextDayPart(dayPartEndDate, index + 1);
+      Date nextDayPartStart = dayPartEndDate;
 
       return nextDayPart.add(nextDayPartStart, remainder);
     }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java	2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/calendar/BusinessCalendarTest.java	2010-08-27 20:04:45 UTC (rev 6630)
@@ -30,7 +30,7 @@
 
   static BusinessCalendar businessCalendar = new BusinessCalendar();
 
-  public void testNonBusinessSecondAddition() throws Exception {
+  public void testNonBusinessSecondAddition() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -43,7 +43,7 @@
     assertEquals(expected, actual);
   }
 
-  public void testNonBusinessMinuteAddition() throws Exception {
+  public void testNonBusinessMinuteAddition() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -80,7 +80,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("10 days")));
   }
 
-  public void testNonBusinessWeekAddition() throws Exception {
+  public void testNonBusinessWeekAddition() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
     calendar.set(Calendar.MILLISECOND, 125);
@@ -92,7 +92,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("5 weeks")));
   }
 
-  public void testNonBusinessMonthAddition() throws Exception {
+  public void testNonBusinessMonthAddition() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
     calendar.set(Calendar.MILLISECOND, 125);
@@ -104,7 +104,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("3 months")));
   }
 
-  public void testNonBusinessYearAddition() throws Exception {
+  public void testNonBusinessYearAddition() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
     calendar.set(Calendar.MILLISECOND, 125);
@@ -116,7 +116,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("1 year")));
   }
 
-  public void testBusinessDurationAdditionOverBusinessTime() throws Exception {
+  public void testBusinessDurationAdditionOverBusinessTime() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -128,7 +128,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("1 business minute")));
   }
 
-  public void testBusinessDurationAdditionOverLunchBreak() throws Exception {
+  public void testBusinessDurationAdditionOverLunchBreak() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -142,7 +142,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
   }
 
-  public void testBusinessDurationAdditionOverDayBreak() throws Exception {
+  public void testBusinessDurationAdditionOverDayBreak() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 16, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -156,7 +156,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
   }
 
-  public void testBusinessDurationAdditionOverHoliday() throws Exception {
+  public void testBusinessDurationAdditionOverHoliday() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2010, Calendar.NOVEMBER, 10, 16, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -172,7 +172,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
   }
 
-  public void testBusinessDurationAdditionOverWeekend() throws Exception {
+  public void testBusinessDurationAdditionOverWeekend() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 8, 16, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -188,7 +188,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("10 business minutes")));
   }
 
-  public void testTwoBusinessHoursOverLunch() throws Exception {
+  public void testTwoBusinessHoursOverLunch() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 11, 15, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -202,7 +202,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("2 business hours")));
   }
 
-  public void testBusinessDurationAdditionOutsideBusinessHours() throws Exception {
+  public void testBusinessDurationAdditionOutsideBusinessHours() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -216,7 +216,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("30 business minutes")));
   }
 
-  public void testBusinessDurationAdditionOutsideBusinessHoursOverWeekend() throws Exception {
+  public void testBusinessDurationAdditionOutsideBusinessHoursOverWeekend() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -301,40 +301,4 @@
 
     assertEquals(expected, businessCalendar.add(start, new Duration("1 business year")));
   }
-
-  public void testNextDayStart() {
-    Calendar calendar = BusinessCalendar.getCalendar();
-    calendar.set(2005, Calendar.APRIL, 8, 13, 15);
-    Date fridayAfterLunch = calendar.getTime();
-
-    calendar.add(Calendar.DAY_OF_MONTH, 1);
-    calendar.set(Calendar.HOUR_OF_DAY, 0);
-    calendar.set(Calendar.MINUTE, 0);
-    calendar.set(Calendar.SECOND, 0);
-    calendar.set(Calendar.MILLISECOND, 0);
-    Date nextDay = calendar.getTime();
-
-    assertEquals(nextDay, businessCalendar.findStartOfNextDay(fridayAfterLunch));
-  }
-
-  public void testDayOfWeek() {
-    Calendar calendar = BusinessCalendar.getCalendar();
-    calendar.set(2005, Calendar.APRIL, 8, 13, 15);
-    Date fridayAfterLunch = calendar.getTime();
-
-    Day day = businessCalendar.findDay(fridayAfterLunch);
-    assertSame(businessCalendar.getWeekDays()[Calendar.FRIDAY], day);
-  }
-
-  public void testFindNextDayPart() {
-    Calendar calendar = BusinessCalendar.getCalendar();
-    calendar.set(2005, Calendar.APRIL, 8, 21, 15);
-    Date fridayNight = calendar.getTime();
-
-    DayPart dayPart = businessCalendar.findNextDayPart(fridayNight);
-    assertEquals(9, dayPart.startHour);
-    assertEquals(0, dayPart.startMinute);
-    assertEquals(businessCalendar.getWeekDays()[Calendar.MONDAY], dayPart.day);
-    assertEquals(0, dayPart.index);
-  }
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java	2010-08-27 06:54:23 UTC (rev 6629)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1776/JBPM1776Test.java	2010-08-27 20:04:45 UTC (rev 6630)
@@ -38,7 +38,7 @@
 
   static BusinessCalendar businessCalendar = new BusinessCalendar();
 
-  public void testNonBusinessSecondSubtraction() throws Exception {
+  public void testNonBusinessSecondSubtraction() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 10, 30, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -51,7 +51,7 @@
     assertEquals(expected, actual);
   }
 
-  public void testNonBusinessMinuteSubtraction() throws Exception {
+  public void testNonBusinessMinuteSubtraction() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -88,7 +88,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-10 days")));
   }
 
-  public void testNonBusinessWeekSubtraction() throws Exception {
+  public void testNonBusinessWeekSubtraction() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
     calendar.set(Calendar.MILLISECOND, 125);
@@ -100,7 +100,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-5 weeks")));
   }
 
-  public void testNonBusinessMonthSubtraction() throws Exception {
+  public void testNonBusinessMonthSubtraction() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
     calendar.set(Calendar.MILLISECOND, 125);
@@ -112,7 +112,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-3 months")));
   }
 
-  public void testNonBusinessYearSubtraction() throws Exception {
+  public void testNonBusinessYearSubtraction() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2008, Calendar.FEBRUARY, 5, 6, 30, 45);
     calendar.set(Calendar.MILLISECOND, 125);
@@ -124,7 +124,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-1 year")));
   }
 
-  public void testBusinessDurationSubtractionOverBusinessTime() throws Exception {
+  public void testBusinessDurationSubtractionOverBusinessTime() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 11, 55, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -136,7 +136,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-1 business minute")));
   }
 
-  public void testBusinessDurationSubtractionOverLunchBreak() throws Exception {
+  public void testBusinessDurationSubtractionOverLunchBreak() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 12, 35, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -150,7 +150,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
   }
 
-  public void testBusinessDurationSubtractionOverDayBreak() throws Exception {
+  public void testBusinessDurationSubtractionOverDayBreak() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 8, 9, 5, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -164,7 +164,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
   }
 
-  public void testBusinessDurationSubtractionOverHoliday() throws Exception {
+  public void testBusinessDurationSubtractionOverHoliday() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2010, Calendar.NOVEMBER, 12, 9, 5, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -180,7 +180,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
   }
 
-  public void testBusinessDurationSubtractionOverWeekend() throws Exception {
+  public void testBusinessDurationSubtractionOverWeekend() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 11, 9, 5, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -196,7 +196,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-10 business minutes")));
   }
 
-  public void testTwoBusinessHoursOverLunch() throws Exception {
+  public void testTwoBusinessHoursOverLunch() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 7, 13, 45, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -210,7 +210,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-2 business hours")));
   }
 
-  public void testBusinessDurationSubtractionOutsideBusinessHours() throws Exception {
+  public void testBusinessDurationSubtractionOutsideBusinessHours() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 8, 12, 15, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -224,7 +224,7 @@
     assertEquals(expected, businessCalendar.add(start, new Duration("-30 business minutes")));
   }
 
-  public void testBusinessDurationSubtractionOutsideBusinessHoursOverWeekend() throws Exception {
+  public void testBusinessDurationSubtractionOutsideBusinessHoursOverWeekend() {
     Calendar calendar = BusinessCalendar.getCalendar();
     calendar.set(2005, Calendar.APRIL, 11, 12, 15, 0);
     calendar.set(Calendar.MILLISECOND, 0);
@@ -241,4 +241,55 @@
 
     assertEquals(expected, businessCalendar.add(start, new Duration("-5 business hours")));
   }
+
+  public void testBusinessDaySubtraction() {
+    Calendar calendar = BusinessCalendar.getCalendar();
+    calendar.set(2005, Calendar.FEBRUARY, 21, 9, 30, 0);
+    calendar.set(Calendar.MILLISECOND, 0);
+    Date start = calendar.getTime();
+
+    calendar.set(Calendar.DAY_OF_MONTH, 7);
+    Date expected = calendar.getTime();
+
+    assertEquals(expected, businessCalendar.add(start, new Duration("-10 business days")));
+  }
+
+  public void testBusinessWeekSubtraction() {
+    Calendar calendar = BusinessCalendar.getCalendar();
+    calendar.set(2005, Calendar.MARCH, 14, 9, 30, 0);
+    calendar.set(Calendar.MILLISECOND, 0);
+    Date start = calendar.getTime();
+
+    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
+    calendar.set(Calendar.DAY_OF_MONTH, 7);
+    Date expected = calendar.getTime();
+
+    assertEquals(expected, businessCalendar.add(start, new Duration("-5 business weeks")));
+  }
+
+  public void testBusinessMonthSubtraction() {
+    Calendar calendar = BusinessCalendar.getCalendar();
+    calendar.set(2010, Calendar.MAY, 7, 9, 30, 0);
+    calendar.set(Calendar.MILLISECOND, 0);
+    Date start = calendar.getTime();
+
+    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
+    calendar.set(Calendar.DAY_OF_MONTH, 8);
+    Date expected = calendar.getTime();
+
+    assertEquals(expected, businessCalendar.add(start, new Duration("-3 business months")));
+  }
+
+  public void testBusinessYearSubtraction() {
+    Calendar calendar = BusinessCalendar.getCalendar();
+    calendar.set(2011, Calendar.FEBRUARY, 9, 9, 30, 0);
+    calendar.set(Calendar.MILLISECOND, 0);
+    Date start = calendar.getTime();
+
+    calendar.set(Calendar.YEAR, 2010);
+    calendar.set(Calendar.DAY_OF_MONTH, 8);
+    Date expected = calendar.getTime();
+
+    assertEquals(expected, businessCalendar.add(start, new Duration("-1 business year")));
+  }
 }



More information about the jbpm-commits mailing list