ConfirmationService { public Confirmation addConfirmation(@NotNull final String username, final long encounterId) { Confirmation newConfirmation = new Confirmation(); newConfirmation.setUser(userService.getDukeEncountersUser(username)); newConfirmation.setDate(new Date()); newConfirmation.setEncounter(encounterService.getEncounterById(encounterId)); Confirmation confirmation = repository.save(newConfirmation); log.info("User {} created new {}", username, confirmation); return confirmation; }  List<Confirmation> getConfirmationsByUsername(@NonNull final String username); Confirmation getConfirmationByUsernameAndEncounterId(@NonNull final String username,
                                                                final long encounterId); Confirmation addConfirmation(@NotNull final String username, final long encounterId); void deleteConfirmation(@NonNull final String username, final long confirmationId); boolean hasConfirmedEncounter(@NonNull final String username, final long encounterId); List<Confirmation> getConfirmations(final String type);  }
@Test public void addConfirmationWithValidDataShouldSucceed() { given(userService.getDukeEncountersUser(anyString())).willReturn(testUser()); given(encounterService.getEncounterById(anyLong())).willReturn(testEncounter(1)); given(repository.save(any(Confirmation.class))).willReturn(testConfirmation()); Confirmation confirmation = service.addConfirmation("test", 1); assertThat(confirmation.getEncounter().getId()).isEqualTo(1); assertThat(confirmation.getUser().getUsername()).isEqualTo("test"); }