/** * {@inheritDoc} */ @Override public int getValidationErrorsCount() { int count = super.getValidationErrorsCount(); if (null != propertyValidation) { count += propertyValidation.getErrorCount(); } return count; }
/** * Returns current count of validation errors. Sub-class can override this method to provide * additional errors in the count. * * @return Returns current count of validation errors on this page. */ public int getValidationErrorsCount() { if (MapUtils.isEmpty(validationMap)) { return 0; } else { int count = 0; for (PropertyValidation propertyValidation : validationMap.values()) { count += propertyValidation.getErrorCount(); } return count; } }
assertThat(propertyValidation.getErrorCount(), is(1)); assertThat(propertyValidation.getErrors(), hasSize(1)); assertThat(propertyValidation.getErrors().iterator().next().getMessage(), is(equalTo(validationMsg)));
@Test public void validationFailsOnSingleProperty() { GroupedProperty groupedProperty = new GroupedProperty(); groupedProperty.addSingleProperty(singleProperty1); groupedProperty.addSingleProperty(singleProperty2); groupedProperty.addValidator(validator1); groupedProperty.addValidator(validator2); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); PropertyValidation propertyValidation = (PropertyValidation) args[0]; propertyValidation.addValidationError(new ValidationError()); return null; } }).when(singleProperty1).validate(Matchers.<PropertyValidation> anyObject()); PropertyValidation propertyValidation = groupedProperty.validate(); assertThat(propertyValidation.hasErrors(), is(true)); assertThat(propertyValidation.getErrorCount(), is(1)); verify(singleProperty1, times(1)).validate(propertyValidation); verify(singleProperty2, times(1)).validate(propertyValidation); verify(validator1, times(1)).validate(groupedProperty, propertyValidation); verify(validator2, times(1)).validate(groupedProperty, propertyValidation); verifyNoMoreInteractions(singleProperty1, singleProperty2, validator1, validator2); }
assertThat(propertyValidation.getErrorCount(), is(2));