### Question:
KmeliaValidation { void validate(final List<PublicationDetail> publications) { for (PublicationDetail publication : publications) { validate(publication); } } private  KmeliaValidation(final String validatorId); static KmeliaValidation by(final String validatorId);  }### Answer:
@Test public void validatePublicationValidationIsNotRequiredShouldNotPerformValidation() { PublicationDetail publication = createPublication(DRAFT_STATUS); kmeliaValidation.validate(publication); verifyZeroInteractions(kmeliaService); }
@Test public void validateAlreadyValidatedPublicationShouldNotPerformValidation() { PublicationDetail publication = createPublication(VALID_STATUS); kmeliaValidation.validate(publication); verifyZeroInteractions(kmeliaService); }
@Test public void validatePublicationValidationIsRequiredShouldPerformValidation() { PublicationDetail publication = createPublication(TO_VALIDATE_STATUS); kmeliaValidation.validate(publication); verify(kmeliaService, times(1)) .validatePublication(publication.getPK(), VALIDATOR_ID, false, false); verifyNoMoreInteractions(kmeliaService); }
@Test public void validateSamePublicationValidationIsRequiredShouldPerformOneTimeOnlyTheValidation() { PublicationDetail publication = createPublication(TO_VALIDATE_STATUS); kmeliaValidation.validate(Arrays.asList(publication, publication, publication, publication)); kmeliaValidation.validate(publication); kmeliaValidation.validate(publication); verify(kmeliaService, times(1)) .validatePublication(publication.getPK(), VALIDATOR_ID, false, false); verifyNoMoreInteractions(kmeliaService); }
@Test public void validateClonedPublicationValidationIsRequiredShouldPerformValidation() { Pair<PublicationDetail, PublicationDetail> publications = createClonedPublication( TO_VALIDATE_STATUS); PublicationDetail orig = publications.getLeft(); PublicationDetail clone = publications.getRight(); when(kmeliaService.getPublicationDetail(clone.getPK())).thenReturn(clone); kmeliaValidation.validate(clone); verify(kmeliaService, times(1)).getPublicationDetail(clone.getPK()); verify(kmeliaService, times(1)).validatePublication(orig.getPK(), VALIDATOR_ID, false, false); verifyNoMoreInteractions(kmeliaService); }
@Test public void validateClonedPublicationValidationIsNotRequiredShouldNotPerformValidation() { Pair<PublicationDetail, PublicationDetail> publications = createClonedPublication(DRAFT_STATUS); PublicationDetail clone = publications.getRight(); when(kmeliaService.getPublicationDetail(clone.getPK())).thenReturn(clone); kmeliaValidation.validate(clone); verify(kmeliaService, times(1)).getPublicationDetail(clone.getPK()); verifyNoMoreInteractions(kmeliaService); }