### Question:
RestResponseHandler { public void handleBadResponse(@NotNull Exception exception, ErrorType errorType, String genericLogErrorMessage, Object... logParameters) { if (exception instanceof HttpClientErrorException) { handleHttpClientError(exception, errorType, genericLogErrorMessage, logParameters); } else if (exception instanceof ResourceAccessException) { throw new GatewayNotAvailableException(ErrorType.GATEWAY_NOT_AVAILABLE.getDefaultMessage(), exception); } else if (exception instanceof HttpServerErrorException) { HttpServerErrorException hseException = (HttpServerErrorException) exception; if (hseException.getStatusCode().equals(HttpStatus.SERVICE_UNAVAILABLE)) { throw new ServiceNotAccessibleException(ErrorType.SERVICE_UNAVAILABLE.getDefaultMessage(), exception); } else { throw hseException; } } }  void handleBadResponse(@NotNull Exception exception, ErrorType errorType, String genericLogErrorMessage, Object... logParameters);  }### Answer:
@Test(expected = BadCredentialsException.class) public void handleBadResponseWithBadCredentials() { handler.handleBadResponse(unauthorizedException, ErrorType.BAD_CREDENTIALS, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = TokenNotValidException.class) public void handleBadResponseWithTokenNotValid() { handler.handleBadResponse(unauthorizedException, ErrorType.TOKEN_NOT_VALID, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = TokenNotProvidedException.class) public void handleBadResponseWithTokenNotProvided() { handler.handleBadResponse(unauthorizedException, ErrorType.TOKEN_NOT_PROVIDED, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = BadCredentialsException.class) public void handleBadResponseWithAuthGeneral() { handler.handleBadResponse(unauthorizedException, ErrorType.AUTH_GENERAL, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = AuthenticationCredentialsNotFoundException.class) public void handleBadResponseWithCredentialsNotFound() { HttpClientErrorException badRequestException = new HttpClientErrorException(HttpStatus.BAD_REQUEST); handler.handleBadResponse(badRequestException, null, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = AuthMethodNotSupportedException.class) public void handleBadResponseWithAuthMethodNotSupported() { HttpClientErrorException methodNotAllowedException = new HttpClientErrorException(HttpStatus.METHOD_NOT_ALLOWED); handler.handleBadResponse(methodNotAllowedException, null, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = AuthenticationServiceException.class) public void handleBadResponseWithNoLogMessage() { handler.handleBadResponse(forbiddenException, null, GENERIC_LOG_MESSAGE); }
@Test(expected = AuthenticationServiceException.class) public void handleBadResponseWithLogMessage() { handler.handleBadResponse(forbiddenException, null, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = GatewayNotAvailableException.class) public void handleBadResponseWithGatewayNotAvailable() { ResourceAccessException raException = new ResourceAccessException("Resource Access Exception"); handler.handleBadResponse(raException, null, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = GatewayNotAvailableException.class) public void handleBadResponseWithGatewayNotAvailableWithCause() { ResourceAccessException raException = new ResourceAccessException("Resource Access Exception"); handler.handleBadResponse(raException, ErrorType.BAD_CREDENTIALS, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = ServiceNotAccessibleException.class) public void handleBadResponseWithServiceUnavailable() { HttpServerErrorException exception = new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE, "Authentication service unavailable"); handler.handleBadResponse(exception, null, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }
@Test(expected = HttpServerErrorException.class) public void handleBadResponseWithHttpServerError() { HttpServerErrorException exception = new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Some server error"); handler.handleBadResponse(exception, null, GENERIC_LOG_MESSAGE, LOG_PARAMETERS); }