### Question:
EnvironmentViewService { public Long getIdByCrn(String crn, String accountId) { return Optional.ofNullable(environmentViewRepository .getIdByResourceCrnAndAccountIdAndArchivedIsFalse(crn, accountId)) .orElseThrow(notFound("Environment with CRN", crn)); } EnvironmentViewService(EnvironmentViewRepository environmentViewRepository, ConversionService conversionService); Set<EnvironmentView> findByNamesInAccount(Set<String> names, @NotNull String accountid); Set<EnvironmentView> findByResourceCrnsInAccount(Set<String> resourceCrns, @NotNull String accountid); Set<SimpleEnvironmentResponse> listByAccountId(String accountId); Set<EnvironmentView> findAllByAccountId(String accountId); Set<EnvironmentView> findAllByCredentialId(Long credentialId); Long getIdByName(String environmentName, String accountId); Long getIdByCrn(String crn, String accountId);  }### Answer:
@Test void getIdByCrn() { long value = 1L; when(environmentViewRepository .getIdByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(value); assertEquals(value, environmentViewServiceUnderTest.getIdByCrn(CRN, ACCOUNT_ID)); }
@Test void getIdByCrnNotFound() { when(environmentViewRepository .getIdByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(null); assertThrows(NotFoundException.class, () -> environmentViewServiceUnderTest.getIdByCrn(CRN, ACCOUNT_ID)); }