### Question:
DBStackService { public DBStack getByNameAndEnvironmentCrn(String name, String environmentCrn) { return findByNameAndEnvironmentCrn(name, environmentCrn) .orElseThrow(() -> new NotFoundException(String.format("Stack [%s] in environment [%s] not found", name, environmentCrn))); }  DBStack getById(Long id); Optional<DBStack> findById(Long id); DBStack getByNameAndEnvironmentCrn(String name, String environmentCrn); Optional<DBStack> findByNameAndEnvironmentCrn(String name, String environmentCrn); DBStack getByCrn(String crn); Optional<DBStack> getByCrn(Crn crn); Set<Long> findAllDeleting(); Set<Long> findAllDeletingById(Set<Long> dbStackIds); Set<DBStack> findAllForAutoSync(); DBStack save(DBStack dbStack); @Transactional void delete(DBStack dbStack); @Transactional void delete(Long dbStackId);  }### Answer:
@Test public void testGetByNameAndEnvironmentId() { when(dbStackRepository.findByNameAndEnvironmentId("mystack", "myenv")).thenReturn(Optional.of(dbStack)); assertEquals(dbStack, underTest.getByNameAndEnvironmentCrn("mystack", "myenv")); }
@Test public void testGetByNameAndEnvironmentIdNotFound() { thrown.expect(NotFoundException.class); when(dbStackRepository.findByNameAndEnvironmentId("mystack", "myenv")).thenReturn(Optional.empty()); underTest.getByNameAndEnvironmentCrn("mystack", "myenv"); }