### Question:
PaymentServiceImpl { @NotNull @SecureReceipt public Receipt payEntity( @NotNull @Valid Account account, @NotNull @Size(min = 5, max = 32) String counterparty, @NotNull @DecimalMin("0.0") BigDecimal amount) { System.out.printf("%s.payEntity( %s, %s, %.2f )\n", getClass().getSimpleName(), account.getAccount(), counterparty, amount.doubleValue() ); String msg; if ( counterparty.contains("Bridgetown")) msg = "SEC123"; else msg = "Boo! Hoo!"; Account acct2 = new Account( account.getAccount(), account.getAmount().subtract(amount)); return new Receipt(msg,counterparty,acct2, new Date()); }  @NotNull @SecureReceipt Receipt payEntity(
            @NotNull @Valid Account account,
            @NotNull @Size(min = 5, max = 32) String counterparty,
            @NotNull @DecimalMin("0.0") BigDecimal amount);  }### Answer:
@Test public void shouldFailValidateAllPaymentInputConstraints() { try{ serviceBean.payEntity(null,null,null); fail("expected "+ConstraintViolationException.class.getName()); } catch (EJBException ex) { if ( ex.getCause() instanceof ConstraintViolationException ) { ConstraintViolationException cve = (ConstraintViolationException)ex.getCause(); cve.printStackTrace(System.err); assertEquals(3, cve.getConstraintViolations().size() ); } else { throw ex; } } }
@Test public void shouldValidateAllPaymentConstraints() { serviceBean.payEntity( new Account("10002000", new BigDecimal("400.00")), "Bridgetown Markets", new BigDecimal("250.00")); }
@Test(expected = EJBException.class) public void shouldNotValidatePaymentWithReturnConstraint() { serviceBean.payEntity( new Account("10002000", new BigDecimal("1000.00")) , "Clear Ridge", new BigDecimal("750000.00")); }