### Question:
MBDevApiErrorDecoder extends ErrorDecoder.Default { @Override public Exception decode(String methodKey, Response response) { Exception exception = super.decode(methodKey, response); switch (response.status()) { case 401: return new UnauthorizedException(getUnauthorizedMessage(methodKey, response, exception), exception); case 429: return new QuotaExceededException(getQuotaExceededMessage(methodKey, response, exception), exception); default: return new MBDevApiException(getDefaultMessage(methodKey, response, exception), exception); } }  @Override Exception decode(String methodKey, Response response);  }### Answer:
@Test public void testDecode_whenResponseStatusIs401_shouldThrowUnauthorizedException() throws Exception { Response response = Response.builder().status(401).headers(Collections.EMPTY_MAP).build(); Exception exception = apiErrorDecoder.decode("api#vehicles", response); assertThat(exception).isInstanceOf(UnauthorizedException.class); UnauthorizedException unauthorizedException = (UnauthorizedException) exception; assertThat(unauthorizedException.getCause()).isInstanceOf(FeignException.class); }
@Test public void testDecode_whenResponseStatusIs429_shouldThrowQuotaExceededExeption() throws Exception { Response response = Response.builder().status(429).headers(Collections.EMPTY_MAP).build(); Exception exception = apiErrorDecoder.decode("api#vehicles", response); assertThat(exception).isInstanceOf(QuotaExceededException.class); QuotaExceededException quotaExceededException = (QuotaExceededException) exception; assertThat(quotaExceededException.getCause()).isInstanceOf(FeignException.class); }
@Test public void testDecode_shouldWrapFeignExceptionWithGenericMBDevApiException() throws Exception { Request request = Request.create("method", "url", Collections.EMPTY_MAP, null, Charset.defaultCharset()); Response response = Response.builder().status(400).body("test", Charset.defaultCharset()) .request(request).headers(Collections.EMPTY_MAP).build(); Exception exception = apiErrorDecoder.decode("api#vehicles", response); assertThat(exception).isInstanceOf(MBDevApiException.class); MBDevApiException mbDevApiException = (MBDevApiException) exception; assertThat(mbDevApiException.getCause()).isInstanceOf(FeignException.class); assertThat(mbDevApiException.getMessage()).isNotBlank(); }