### Question:
StackService implements ResourceBasedCrnProvider { public Stack getStackById(Long id) { return stackRepository.findById(id).orElseThrow(() -> new NotFoundException(String.format("Stack [%s] not found", id))); }  List<Stack> findAllRunning(); List<Stack> findAllForAutoSync(); Stack getByIdWithListsInTransaction(Long id); Stack getStackById(Long id); Stack save(Stack stack); Stack getByEnvironmentCrnAndAccountId(String environmentCrn, String accountId); Optional<Stack> findByEnvironmentCrnAndAccountId(String environmentCrn, String accountId); Stack getByEnvironmentCrnAndAccountIdEvenIfTerminated(String environmentCrn, String accountId); Optional<Stack> findByEnvironmentCrnAndAccountIdEvenIfTerminated(String environmentCrn, String accountId); List<Stack> getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(Collection<String> environmentCrns, String accountId); List<Stack> findAllByEnvironmentCrnAndAccountId(String environmentCrn, String accountId); List<Long> findAllIdByEnvironmentCrnAndAccountId(String environmentCrn, String accountId); Stack getByEnvironmentCrnAndAccountIdWithLists(String environmentCrn, String accountId); Stack getByOwnEnvironmentCrnAndAccountIdWithLists(String environmentCrn, String accountId); List<Stack> getAllByAccountId(String accountId); List<StackIdWithStatus> getStatuses(Set<Long> stackIds); List<Stack> findAllWithStatuses(Collection<Status> statuses); List<Stack> findAllByAccountIdWithStatuses(String accountId, Collection<Status> statuses); List<Stack> findMultipleByEnvironmentCrnAndAccountIdWithStatuses(Collection<String> environmentCrns, String accountId, Collection<Status> statuses); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType();  }### Answer:
@Test void getStackByIdNotFound() { when(stackRepository.findById(STACK_ID)).thenReturn(Optional.empty()); NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> underTest.getStackById(STACK_ID)); assertEquals("Stack [" + STACK_ID + "] not found", notFoundException.getMessage()); }
@Test void getStackById() { when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack)); Stack stackById = underTest.getStackById(STACK_ID); assertEquals(stack, stackById); }