EncounterService { public boolean isOwnEncounter(@NotNull final long encounterId, @NotNull final String username) { Encounter encounter = repository.findByIdAndUsername(encounterId, username); boolean owner = encounter != null; log.info("User {} is {} owner of encounter {}", username, owner ? "the" : "not the", encounterId); return owner; }  List<Encounter> getLatestEncounters(); List<Encounter> getEncounters(@NotNull final SearchFilter filter); Encounter getEncounterById(@NotNull final long encounterId); List<Encounter> getEncountersByUsername(@NotNull final String username); List<Encounter> getEncountersByEvent(@NotNull final String event); List<Encounter> getEncounters(final String type); @Transactional void deleteEncounter(@NotNull final long encounterId); @Transactional Encounter createEncounter(@NotNull final Encounter newEncounter); boolean isOwnEncounter(@NotNull final long encounterId, @NotNull final String username);  }
@Test public void isOwnEncountersForOwnEncounterShouldReturnTrue() { given(repository.findByIdAndUsername(anyLong(), anyString())).willReturn(testEncounter(1)); boolean ownEncounter = service.isOwnEncounter(1, "test"); assertThat(ownEncounter).isTrue(); }
@Test public void isOwnEncountersForOtherEncounterShouldReturnFalse() { given(repository.findByIdAndUsername(anyLong(), anyString())).willReturn(null); boolean ownEncounter = service.isOwnEncounter(1, "test"); assertThat(ownEncounter).isFalse(); }