}
@Test
public void testValidCustomer() {
Order order = new Order();
Customer customer = new Customer();
customer.setRegistered(false);
customer.setBusinessCustomer(true);
order.setCustomer(customer);
Errors errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateCustomer(customer, errors);
assertEquals(2, errors.getAllErrors().size());
assertEquals("error.customer.registration", errors.getFieldError("customer.registered").getCode());
assertEquals("error.customer.companyname", errors.getFieldError("customer.companyName").getCode());
customer = new Customer();
customer.setRegistered(true);
customer.setBusinessCustomer(false);
customer.setRegistrationId(Long.MIN_VALUE);
order.setCustomer(customer);
errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateCustomer(customer, errors);
assertEquals(3, errors.getAllErrors().size());
assertEquals("error.customer.firstname", errors.getFieldError("customer.firstName").getCode());
assertEquals("error.customer.lastname", errors.getFieldError("customer.lastName").getCode());
assertEquals("error.customer.registrationid", errors.getFieldError("customer.registrationId").getCode());
customer = new Customer();
customer.setRegistered(true);
customer.setBusinessCustomer(false);
customer.setRegistrationId(Long.MAX_VALUE);
order.setCustomer(customer);
errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateCustomer(customer, errors);
assertEquals(3, errors.getAllErrors().size());
assertEquals("error.customer.firstname", errors.getFieldError("customer.firstName").getCode());
assertEquals("error.customer.lastname", errors.getFieldError("customer.lastName").getCode());
assertEquals("error.customer.registrationid", errors.getFieldError("customer.registrationId").getCode());
customer = new Customer();
customer.setRegistered(true);
customer.setBusinessCustomer(true);
customer.setCompanyName("Acme Inc");
customer.setRegistrationId(5L);
order.setCustomer(customer);
errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateCustomer(customer, errors);
assertEquals(0, errors.getAllErrors().size());
customer = new Customer();
customer.setRegistered(true);
customer.setBusinessCustomer(false);
customer.setFirstName("John");
customer.setLastName("Doe");
customer.setRegistrationId(5L);
order.setCustomer(customer);
errors = new BeanPropertyBindingResult(order, "validOrder");
orderValidator.validateCustomer(customer, errors);