Skip to content

Instantly share code, notes, and snippets.

@mgryszko
Last active February 12, 2022 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgryszko/d7223c25c7d436fe3d96f08414142bcb to your computer and use it in GitHub Desktop.
Save mgryszko/d7223c25c7d436fe3d96f08414142bcb to your computer and use it in GitHub Desktop.
@Test
void deleteDefault() {
var profile = ScoringProfile.builder().id(profileId).defaultProfile(true).build();
setupStubs(profile);
recalculateService.calculateAndPersist(profile);
verifyMocks(profile, inactiveScoresToKeep);
}
@Test
void deleteCustom() {
var profile = ScoringProfile.builder().id(profileId).defaultProfile(false).build();
setupStubs(profile);
recalculateService.calculateAndPersist(profile);
verifyMocks(profile, 0);
}
private void setupStubs(ScoringProfile profile) {
when(versioner.nextVersion(profile)).thenReturn(version);
when(scoresStorer.getPersister(profileId, version)).thenReturn(persister);
}
private void verifyMocks(ScoringProfile profile, int expectedScoresToKeep) {
var inOrder = inOrder(persister, calculator, versioner);
inOrder.verify(persister).deleteInactive(profileId, inactiveScoresToKeep);
inOrder.verify(versioner).deleteInactive(profileId, expectedScoresToKeep);
inOrder.verify(calculator).calculateScores(profile, persister);
inOrder.verify(versioner).calculationFinished(version);
inOrder.verify(versioner).activateVersion(profile, version);
inOrder.verify(persister).deleteInactive(profileId, expectedScoresToKeep);
inOrder.verify(versioner).deleteInactive(profileId, expectedScoresToKeep);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment