### Question:
AuthorisationServiceInternal implements AuthorisationService { @Transactional @Override public CmsResponse<List<String>> getAuthorisationsByParentId(AuthorisationParentHolder parentHolder) { AuthService authService = authServiceResolver.getAuthService(parentHolder.getAuthorisationType()); Optional<Authorisable> authorisationParentOptional = authService.getAuthorisationParent(parentHolder.getParentId()); if (authorisationParentOptional.isEmpty()) { log.info("Parent ID: [{}]. Get the list of authorisation IDs has failed, because parent couldn't be found", parentHolder.getParentId()); return CmsResponse.<List<String>>builder() .error(LOGICAL_ERROR) .build(); } Authorisable authorisationParent = authorisationParentOptional.get(); Authorisable checkedParent = authService.checkAndUpdateOnConfirmationExpiration(authorisationParent); List<AuthorisationEntity> authorisations = authService.getAuthorisationsByParentId(checkedParent.getExternalId()); List<String> authorisationIds = authorisations.stream() .map(AuthorisationEntity::getExternalId) .collect(Collectors.toList()); return CmsResponse.<List<String>>builder() .payload(authorisationIds) .build(); }  @Transactional @Override CmsResponse<CreateAuthorisationResponse> createAuthorisation(AuthorisationParentHolder parentHolder, CreateAuthorisationRequest request); @Transactional(readOnly = true) @Override CmsResponse<Authorisation> getAuthorisationById(String authorisationId); @Transactional @Override CmsResponse<Authorisation> updateAuthorisation(String authorisationId, UpdateAuthorisationRequest request); @Transactional @Override CmsResponse<Boolean> updateAuthorisationStatus(String authorisationId, ScaStatus scaStatus); @Transactional @Override CmsResponse<List<String>> getAuthorisationsByParentId(AuthorisationParentHolder parentHolder); @Transactional @Override CmsResponse<ScaStatus> getAuthorisationScaStatus(String authorisationId, AuthorisationParentHolder parentHolder); @Transactional(readOnly = true) @Override CmsResponse<Boolean> isAuthenticationMethodDecoupled(String authorisationId, String authenticationMethodId); @Transactional @Override CmsResponse<Boolean> saveAuthenticationMethods(String authorisationId, List<CmsScaMethod> methods); @Transactional @Override CmsResponse<Boolean> updateScaApproach(String authorisationId, ScaApproach scaApproach); @Transactional(readOnly = true) @Override CmsResponse<AuthorisationScaApproachResponse> getAuthorisationScaApproach(String authorisationId);  }### Answer:
@Test void getAuthorisationsByParentId() { String parentId = "parent id"; AuthorisationParentHolder authorisationParentHolder = new AuthorisationParentHolder(AuthorisationType.CONSENT, parentId); List<String> expectedAuthorisations = Collections.singletonList(AUTHORISATION_ID); when(authServiceResolver.getAuthService(AuthorisationType.CONSENT)).thenReturn(authService); ConsentEntity consentEntity = new ConsentEntity(); consentEntity.setExternalId(parentId); when(authService.getAuthorisationParent(parentId)).thenReturn(Optional.of(consentEntity)); when(authService.checkAndUpdateOnConfirmationExpiration(consentEntity)).thenReturn(consentEntity); AuthorisationEntity authorisationEntity = new AuthorisationEntity(); authorisationEntity.setExternalId(AUTHORISATION_ID); when(authService.getAuthorisationsByParentId(parentId)).thenReturn(Collections.singletonList(authorisationEntity)); CmsResponse<List<String>> actualResponse = authorisationServiceInternal.getAuthorisationsByParentId(authorisationParentHolder); assertTrue(actualResponse.isSuccessful()); assertEquals(expectedAuthorisations, actualResponse.getPayload()); }
@Test void getAuthorisationsByParentId_wrongId() { String parentId = "wrong id"; AuthorisationParentHolder authorisationParentHolder = new AuthorisationParentHolder(AuthorisationType.CONSENT, parentId); when(authServiceResolver.getAuthService(AuthorisationType.CONSENT)).thenReturn(authService); when(authService.getAuthorisationParent(parentId)).thenReturn(Optional.empty()); CmsResponse<List<String>> actualResponse = authorisationServiceInternal.getAuthorisationsByParentId(authorisationParentHolder); assertTrue(actualResponse.hasError()); assertEquals(CmsError.LOGICAL_ERROR, actualResponse.getError()); }