예제 #1
0
  /**
   * This test makes sure that the {@link Order#isDiscontinued()} is the one getting called instead
   * of a method like {@link Order#getDiscontinued()}. The latter was using the date object and
   * looking at several attributes at one point instead of looking at the boolean 'discontinued'
   * attribute.
   *
   * @throws ELException
   */
  @Test
  public void getDiscontinued_shouldGetDiscontinuedProperty() throws ELException {
    Order order = new Order();
    MockPageContext pageCtxt = new MockPageContext();
    pageCtxt.setAttribute("order", order);
    ExpressionEvaluator evtr = pageCtxt.getExpressionEvaluator();

    order.setDiscontinued(true);
    Object result = evtr.evaluate("${order.discontinued}", Boolean.class, null, null);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof Boolean);
    Assert.assertTrue((Boolean) result);

    order.setDiscontinued(false);
    result = evtr.evaluate("${order.discontinued}", Boolean.class, null, null);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof Boolean);
    Assert.assertFalse((Boolean) result);
  }
 private Pair<Date, Date> getDateRange(String period) throws ELException {
   Long duration = (Long) EVALUATOR.evaluate("${" + period + "}", Long.class, RESOLVER, RESOLVER);
   Date end = new Date();
   Date start = new Date(end.getTime() - duration);
   return Pair.of(start, end);
 }