assertEquals(0, errors.getAllErrors().size());
}
@Test
public void testValidOrder() {
Order order = new Order();
order.setOrderId(-5);
order.setOrderDate(new Date(new Date().getTime() + 1000000000L));
order.setTotalLines(10);
order.setLineItems(new ArrayList<LineItem>());
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateOrder(order, errors);
assertEquals(3, errors.getAllErrors().size());
assertEquals("error.order.id", errors.getFieldError("orderId").getCode());
assertEquals("error.order.date.future", errors.getFieldError("orderDate").getCode());
assertEquals("error.order.lines.badcount", errors.getFieldError("totalLines").getCode());
order = new Order();
order.setOrderId(Long.MAX_VALUE);
order.setOrderDate(new Date(new Date().getTime() - 1000));
order.setTotalLines(0);
List<LineItem> items = new ArrayList<LineItem>();
items.add(new LineItem());
order.setLineItems(items);
errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateOrder(order, errors);
assertEquals(2, errors.getAllErrors().size());
assertEquals("error.order.id", errors.getFieldError("orderId").getCode());
assertEquals("error.order.lines.badcount", errors.getFieldError("totalLines").getCode());
order = new Order();
order.setOrderId(5L);
order.setOrderDate(new Date(new Date().getTime() - 1000));
order.setTotalLines(1);
items = new ArrayList<LineItem>();
items.add(new LineItem());
order.setLineItems(items);
errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateOrder(order, errors);