@Test public void whenInvalidRegExCaseSensitiveThenThrowsException() { try { custJsWO.setRegExCaseSensitiveField("abCfoobar"); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("Reg Ex Case Sensitive Field")); } }
@Test public void whenInvalidMaxLengthThenThrowsException() { try { custJsWO.setMaxLengthField("This is far too long"); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(MaxLengthFacetAnnotationForProperty.class)); assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("Max Length Field")); } }
@Test public void whenAssociationInvalidMandatoryThenThrowsException() { try { custJsWO.setMandatoryAssociation(null); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(MandatoryFacetDefault.class)); assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("Mandatory Association")); } }
@Test public void whenInvalidRegExCaseInsensitiveThenThrowsException() { try { custJsWO.setRegExCaseInsensitiveField("abXfoobar"); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(RegExFacetAnnotationForProperty.class)); assertThat( ex.getIdentifier().getMemberNaturalName(), equalTo("Reg Ex Case Insensitive Field")); } }
@Test public void whenActionInvalidImperativelyThenThrowsException() { custJsDO.validatePlaceOrder = "can't place order"; try { custJsWO.placeOrder(product355DO, 3); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(ActionValidationFacetViaMethod.class)); assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("Place Order")); assertThat(ex.getMessage(), Matchers.containsString("can't place order")); } }
@Test public void whenCollectionInvalidImperativelyThenAddToThrowsException() { custJsDO.validateAddToVisitedCountries = "bad country"; try { custJsWO.addToVisitedCountries(countryGbrDO); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(CollectionValidateAddToFacetViaMethod.class)); assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("Visited Countries")); assertThat(ex.getMessage(), Matchers.containsString("bad country")); } }
@Test public void whenAssociationInvalidImperativelyThenThrowsException() { custJsDO.validateCountryOfBirth = "bad country of birth"; final Country[] values = new Country[] {countryUsaDO}; for (final Country value : values) { try { custJsWO.setCountryOfBirth(value); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(PropertyValidateFacetViaMethod.class)); assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("Country Of Birth")); assertThat(ex.getMessage(), Matchers.containsString("bad country of birth")); } } }
@Test public void whenValueInvalidImperativelyThenThrowsException() { final String[] values = new String[] {"Dick", "Harry"}; for (final String value : values) { custJsDO.validateFirstNameExpectedArg = value; custJsDO.validateFirstName = "bad first name"; try { custJsWO.setFirstName(value); fail("Should have thrown exception"); } catch (final InvalidException ex) { assertThat(ex.getAdvisorClass(), classEqualTo(PropertyValidateFacetViaMethod.class)); assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("First Name")); assertThat(ex.getMessage(), Matchers.containsString("bad first name")); } } }
@Ignore // different behaviour testing in Eclipse vs Maven (different exception type thrown); not // sure why @Test public void whenValueInvalidImperativelyOnMandatoryThenThrowsException() { final String[] values = new String[] {null}; for (final String value : values) { custJsDO.validateFirstNameMandatoryExpectedArg = value; custJsDO.validateFirstNameMandatory = "bad first name"; try { custJsWO.setFirstNameMandatory(value); fail("Should have thrown exception"); } catch (final InvalidException ex) { // assertThat(ex.getAdvisorClass(), classEqualTo(MandatoryFacetDefault.class)); // in // Eclipse? assertThat( ex.getAdvisorClass(), classEqualTo(PropertyValidateFacetViaMethod.class)); // in Maven? assertThat(ex.getIdentifier().getMemberNaturalName(), equalTo("First Name Mandatory")); assertThat(ex.getMessage(), Matchers.containsString("bad first name")); } } }
@Ignore // different behaviour testing in Eclipse vs Maven (different exception type thrown); not // sure why @Test public void whenAssociationNullOnMandatoryImperativelyThenThrowsException() { custJsDO.validateCountryOfBirthMandatory = "bad country of birth"; final Country[] values = new Country[] {null}; for (final Country value : values) { try { custJsWO.setCountryOfBirthMandatory(value); fail("Should have thrown exception"); } catch (final InvalidException ex) { // assertThat(ex.getAdvisorClass(), classEqualTo(MandatoryFacetDefault.class)); // in // Eclipse? assertThat( ex.getAdvisorClass(), classEqualTo(PropertyValidateFacetViaMethod.class)); // in Maven? assertThat( ex.getIdentifier().getMemberNaturalName(), equalTo("Country Of Birth Mandatory")); assertThat(ex.getMessage(), Matchers.containsString("bad country of birth")); } } }