### Question:
MappingDataValidationImpl extends AbstractValidation<MappingData> implements MappingDataValidation { @Override protected void validate(ValidationContext<MappingData> context) { validateNotNull(context); MappingData data = context.objectToValidate; for (MappingEntry entry: data.getEntries()) { ValidationResult result = mappingEntryValidation.validate(entry); if (result.isValid()) { continue; } addErrorMessage(context,result.getErrorDescription()); } }    }### Answer:
@Test public void having_2_mapping_entries_calls_map_entry_validation_two_times() { MappingData data = new MappingData(); data.getEntries().add(entry1); data.getEntries().add(entry2); when(mappingEntryValidation.validate(any())).thenReturn(new ValidationResult()); validationToTest.validate(data); verify(mappingEntryValidation).validate(entry1); verify(mappingEntryValidation).validate(entry2); }
@Test public void having_2_mapping_entries_calls_and_two_good_than_valid() { MappingData data = new MappingData(); data.getEntries().add(entry1); data.getEntries().add(entry2); when(mappingEntryValidation.validate(any())).thenReturn(new ValidationResult()); assertTrue(validationToTest.validate(data).isValid()); }
@Test public void having_2_mapping_entries_calls_and_none_good_than_invalid() { MappingData data = new MappingData(); data.getEntries().add(entry1); data.getEntries().add(entry2); ValidationResult result1 = new ValidationResult(); result1.addError("error1"); ValidationResult result2 = new ValidationResult(); result1.addError("error2"); when(mappingEntryValidation.validate(entry1)).thenReturn(result1); when(mappingEntryValidation.validate(entry2)).thenReturn(result2); assertFalse(validationToTest.validate(data).isValid()); }
@Test public void having_2_mapping_entries_calls_and_entry1_bad_than_invalid() { MappingData data = new MappingData(); data.getEntries().add(entry1); data.getEntries().add(entry2); ValidationResult result1 = new ValidationResult(); result1.addError("error1"); ValidationResult result2 = new ValidationResult(); when(mappingEntryValidation.validate(entry1)).thenReturn(result1); when(mappingEntryValidation.validate(entry2)).thenReturn(result2); boolean valid = validationToTest.validate(data).isValid(); assertFalse(valid); }
@Test public void having_2_mapping_entries_calls_and_entry2_bad_than_invalid() { MappingData data = new MappingData(); data.getEntries().add(entry1); data.getEntries().add(entry2); ValidationResult result1 = new ValidationResult(); ValidationResult result2 = new ValidationResult(); result2.addError("error1"); when(mappingEntryValidation.validate(entry1)).thenReturn(result1); when(mappingEntryValidation.validate(entry2)).thenReturn(result2); assertFalse(validationToTest.validate(data).isValid()); }