### Question:
TokenValidationService { public BearerTokenTO validate(String bearerToken) { try { authInterceptor.setAccessToken(bearerToken); return ledgersUserMgmt.validate(bearerToken).getBody(); } catch (FeignException e) { log.error("Token validation is failed"); } finally { authInterceptor.setAccessToken(null); } return null; }  BearerTokenTO validate(String bearerToken);  }### Answer:
@Test void validate_withValidToken_shouldReturnValidToken() { String token = "some token"; BearerTokenTO expected = new BearerTokenTO(); when(userMgmtRestClient.validate(token)) .thenReturn(ResponseEntity.ok(expected)); BearerTokenTO actual = tokenValidationService.validate(token); assertEquals(expected, actual); InOrder inOrder = Mockito.inOrder(authRequestInterceptor, userMgmtRestClient); inOrder.verify(authRequestInterceptor).setAccessToken(token); inOrder.verify(userMgmtRestClient).validate(token); inOrder.verify(authRequestInterceptor).setAccessToken(null); }
@Test void validate_onFeignException_shouldReturnNull() { String token = "some token"; Response feignResponse = Response.builder() .status(HttpStatus.BAD_REQUEST.value()) .request(Request.create(Request.HttpMethod.GET, "", Collections.emptyMap(), null)) .headers(Collections.emptyMap()) .build(); FeignException feignException = FeignException.errorStatus("some message", feignResponse); when(userMgmtRestClient.validate(token)) .thenThrow(feignException); BearerTokenTO actual = tokenValidationService.validate(token); assertNull(actual); InOrder inOrder = Mockito.inOrder(authRequestInterceptor, userMgmtRestClient); inOrder.verify(authRequestInterceptor).setAccessToken(token); inOrder.verify(userMgmtRestClient).validate(token); inOrder.verify(authRequestInterceptor).setAccessToken(null); }