/** * Convenience method to determine if the order is expired as of the specified date * * @return boolean indicating whether the order is expired at the current time * @since 1.10.1 */ public boolean isExpired() { return isExpired(new Date()); }
/** * Convenience method to determine if the order is active as of the specified date * * @param checkDate - the date on which to check order. if null, will use current date * @return boolean indicating whether the order was active on the check date * @since 1.10.1 * @should return true if an order expired on the check date * @should return true if an order was discontinued on the check date * @should return true if an order was activated on the check date * @should return true if an order was activated on the check date but scheduled for the future * @should return false for a voided order * @should return false for a discontinued order * @should return false for an expired order * @should return false for an order activated after the check date * @should return false for a discontinuation order */ public boolean isActive(Date aCheckDate) { if (getVoided() || action == Action.DISCONTINUE) { return false; } Date checkDate = aCheckDate == null ? new Date() : aCheckDate; return isActivated(checkDate) && !isDiscontinued(checkDate) && !isExpired(checkDate); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfDateStoppedIsNullAndAutoExpireDateIsEqualToCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); Date checkDate = DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT); order.setAutoExpireDate(checkDate); assertNull(order.getDateStopped()); assertFalse(order.isExpired(checkDate)); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfCheckDateIsAfterBothDateStoppedAutoExpireDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT))); }
@Override public boolean evaluate(Object object) { Order order = (Order) object; return order.isDiscontinued(asOfDate) || order.isExpired(asOfDate); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfDateStoppedAndAutoExpireDateAreBothNull() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertNull(order.getAutoExpireDate()); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfDateActivatedIsAfterCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); assertNull(order.getDateStopped()); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnTrueIfDateStoppedIsNullAndAutoExpireDateIsBeforeCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); assertNull(order.getDateStopped()); assertTrue(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfDateStoppedIsNullAndAutoExpireDateIsAfterCheckDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); assertNull(order.getDateStopped()); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT))); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseIfCheckDateIsAfterDateStoppedButBeforeAutoExpireDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldReturnFalseForAVoidedOrder() throws Exception { Order order = new Order(); order.setVoided(true); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); assertNull(order.getDateStopped()); assertFalse(order.isExpired(DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT))); }
/** * @see Order#isExpired(java.util.Date) */ @Test public void isExpired_shouldFailIfDateStoppedIsAfterAutoExpireDate() throws Exception { Order order = new Order(); order.setDateActivated(DateUtils.parseDate("2014-11-01 11:11:10", DATE_FORMAT)); order.setAutoExpireDate(DateUtils.parseDate("2014-11-01 11:11:11", DATE_FORMAT)); OrderUtilTest.setDateStopped(order, DateUtils.parseDate("2014-11-01 11:11:12", DATE_FORMAT)); expectedException.expect(APIException.class); expectedException.expectMessage( Context.getMessageSourceService().getMessage("Order.error.invalidDateStoppedAndAutoExpireDate")); order.isExpired(DateUtils.parseDate("2014-11-01 11:11:13", DATE_FORMAT)); }