RemoveArtifactsProcessor implements Processor { static Set<String> getArtifactsIdsToRemove(ArtifactsDAO artifactsDAO, ReferencedArtifactsMessageBody messageBody) { Set<String> artifactsToRemove = artifactsDAO.getArtifactsIds(messageBody.getDbKey()); artifactsToRemove.removeAll(messageBody.getArtifactsToKeep()); return artifactsToRemove; } RemoveArtifactsProcessor();  RemoveArtifactsProcessor(ArtifactsDAO artifactsDAO); @Override @SuppressWarnings("unchecked") void process(Exchange exchange);  }
@Test public void check_substractArtifactsSets_expectSetOfTwoVariables() throws Exception { when(artifactDAO.getArtifactsIds(any(DBKey.class))) .thenReturn(new HashSet<>(ONE_TO_SEVEN_ARTIFACTS_ID_SET)); setArtifactsIdToKeep(ONE_TO_FIVE_ARTIFACTS_ID_SET); ReferencedArtifactsMessageBody messageBody = (ReferencedArtifactsMessageBody) exchange.getIn() .getBody(); assertEquals(SIX_TO_SEVEN_ARTIFACTS_ID_SET, removeArtifactsProcessor.getArtifactsIdsToRemove(artifactDAO, messageBody)); }
@Test public void check_substractArtifactsSets_expectEmptySet() throws Exception { when(artifactDAO.getArtifactsIds(any(DBKey.class))) .thenReturn(new HashSet<>(ONE_TO_FIVE_ARTIFACTS_ID_SET)); setArtifactsIdToKeep(ONE_TO_SEVEN_ARTIFACTS_ID_SET); ReferencedArtifactsMessageBody messageBody = (ReferencedArtifactsMessageBody) exchange.getIn() .getBody(); assertTrue(removeArtifactsProcessor.getArtifactsIdsToRemove(artifactDAO, messageBody).isEmpty()); }
@Test public void check_substractArtifactsSets_expectSetOfFiveVariables() throws Exception { when(artifactDAO.getArtifactsIds(any(DBKey.class))) .thenReturn(new HashSet<>(ONE_TO_SEVEN_ARTIFACTS_ID_SET)); setArtifactsIdToKeep(SIX_TO_SEVEN_ARTIFACTS_ID_SET); ReferencedArtifactsMessageBody messageBody = (ReferencedArtifactsMessageBody) exchange.getIn() .getBody(); assertEquals(ONE_TO_FIVE_ARTIFACTS_ID_SET, removeArtifactsProcessor.getArtifactsIdsToRemove(artifactDAO, messageBody)); }
@Test public void check_substractArtifactsSetsWhenDbIsEmpty_expectEmptySet() throws Exception { when(artifactDAO.getArtifactsIds(any(DBKey.class))) .thenReturn(new HashSet<>()); setArtifactsIdToKeep(SIX_TO_SEVEN_ARTIFACTS_ID_SET); ReferencedArtifactsMessageBody messageBody = (ReferencedArtifactsMessageBody) exchange.getIn() .getBody(); assertTrue(removeArtifactsProcessor.getArtifactsIdsToRemove(artifactDAO, messageBody).isEmpty()); }