PhrServiceImpl implements PhrService { @Override public PatientDto findPatientProfileById(Long patientId) { return findPatientProfileById(patientId, false); }  @Override PatientDto findPatientProfileById(Long patientId); @Override PatientDto findPatientProfileById(Long patientId, boolean useClientCredentials);  }
@Test public void testFindPatientProfileById_Use_Client_Credentials_False_Throws_PhrPatientNotFoundException() throws Exception { final boolean useClientCredentials = false; final Long patientId = 5L; final PatientDto patientDto = mock(PatientDto.class); FeignException e = mock(FeignException.class); when(e.status()).thenReturn(HttpStatus.NOT_FOUND.value()); when(phrServiceDefault.findPatientProfileById(patientId)).thenThrow(e); thrown.expect(PhrPatientNotFoundException.class); final PatientDto response = sut.findPatientProfileById(patientId, useClientCredentials); assertEquals(patientDto, response); verify(phrServiceDefault, times(1)).findPatientProfileById(patientId); verify(phrServiceClientCredentials, times(0)).findPatientProfileById(patientId); }
@Test public void testFindPatientProfileById_Use_Client_Credentials_False_Throws_FeignException() throws Exception { final boolean useClientCredentials = false; final Long patientId = 5L; final PatientDto patientDto = mock(PatientDto.class); FeignException e = mock(FeignException.class); when(e.status()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR.value()); when(phrServiceDefault.findPatientProfileById(patientId)).thenThrow(e); thrown.expect(FeignException.class); final PatientDto response = sut.findPatientProfileById(patientId, useClientCredentials); assertEquals(patientDto, response); verify(phrServiceDefault, times(1)).findPatientProfileById(patientId); verify(phrServiceClientCredentials, times(0)).findPatientProfileById(patientId); }
@Test public void testFindPatientProfileById_Use_Client_Credentials_False_Throws_RuntimeException() throws Exception { final boolean useClientCredentials = false; final Long patientId = 5L; final PatientDto patientDto = mock(PatientDto.class); when(phrServiceDefault.findPatientProfileById(patientId)).thenThrow(RuntimeException.class); thrown.expect(RuntimeException.class); final PatientDto response = sut.findPatientProfileById(patientId, useClientCredentials); assertEquals(patientDto, response); verify(phrServiceDefault, times(1)).findPatientProfileById(patientId); verify(phrServiceClientCredentials, times(0)).findPatientProfileById(patientId); }
@Test public void testFindPatientProfileById_Use_Client_Credentials_True() throws Exception { final boolean useClientCredentials = true; final Long patientId = 5L; final PatientDto patientDto = mock(PatientDto.class); when(phrServiceClientCredentials.findPatientProfileById(patientId)).thenReturn(patientDto); final PatientDto response = sut.findPatientProfileById(patientId, useClientCredentials); assertEquals(patientDto, response); verify(phrServiceDefault, times(0)).findPatientProfileById(patientId); verify(phrServiceClientCredentials, times(1)).findPatientProfileById(patientId); }
@Test public void testFindPatientProfileById() throws Exception { final Long patientId = 5L; final PatientDto patientDto = mock(PatientDto.class); when(phrServiceDefault.findPatientProfileById(patientId)).thenReturn(patientDto); final PatientDto response = sut.findPatientProfileById(patientId); assertEquals(patientDto, response); verify(phrServiceDefault, times(1)).findPatientProfileById(patientId); verify(phrServiceClientCredentials, times(0)).findPatientProfileById(patientId); }
@Test public void testFindPatientProfileById_Use_Client_Credentials_False() throws Exception { final boolean useClientCredentials = false; final Long patientId = 5L; final PatientDto patientDto = mock(PatientDto.class); when(phrServiceDefault.findPatientProfileById(patientId)).thenReturn(patientDto); final PatientDto response = sut.findPatientProfileById(patientId, useClientCredentials); assertEquals(patientDto, response); verify(phrServiceDefault, times(1)).findPatientProfileById(patientId); verify(phrServiceClientCredentials, times(0)).findPatientProfileById(patientId); }