diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java index 30d3d0d5..bcf811fc 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java @@ -157,7 +157,7 @@ public void saveTokenWithAttachment(OnboardingAttachment onboardingAttachment) { private boolean checkTokenExist(Onboarding onboarding) { // Skip if token already exists - Optional optToken = tokenRepository.findByOnboardingId(onboarding.getId()); + Optional optToken = tokenRepository.findByIdOptional(onboarding.getId()); if (optToken.isPresent()) { log.debug("Token has already exists for onboarding {}", onboarding.getId()); return true; diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java index d7dd033c..0f43dba3 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java @@ -258,11 +258,11 @@ void saveToken_shouldSkipIfTokenExists() { Token token = createDummyToken(); onboardingWorkflow.setOnboarding(onboarding); - when(tokenRepository.findByOnboardingId(onboarding.getId())).thenReturn(Optional.of(token)); + when(tokenRepository.findByIdOptional(onboarding.getId())).thenReturn(Optional.of(token)); onboardingService.saveTokenWithContract(onboardingWorkflow); - Mockito.verify(tokenRepository, Mockito.times(1)).findByOnboardingId(onboarding.getId()); + Mockito.verify(tokenRepository, Mockito.times(1)).findByIdOptional(onboarding.getId()); Mockito.verifyNoMoreInteractions(tokenRepository); }