ConsulRateLimiter extends AbstractRateLimiter { @Override protected Rate getRate(String key) { Rate rate = null; GetValue value = this.consulClient.getKVValue(key).getValue(); if (value != null && value.getDecodedValue() != null) { try { rate = this.objectMapper.readValue(value.getDecodedValue(), Rate.class); } catch (IOException e) { log.error("Failed to deserialize Rate", e); } } return rate; } ConsulRateLimiter(RateLimiterErrorHandler rateLimiterErrorHandler,
        ConsulClient consulClient, ObjectMapper objectMapper);   }
@Test public void testGetRateException() throws IOException { GetValue getValue = new GetValue(); getValue.setValue(""); when(consulClient.getKVValue(any())).thenReturn(new Response<>(getValue, 1L, true, 1L)); when(objectMapper.readValue(anyString(), eq(Rate.class))).thenAnswer(invocation -> { throw new IOException(); }); ConsulRateLimiter consulRateLimiter = new ConsulRateLimiter(rateLimiterErrorHandler, consulClient, objectMapper); Rate rate = consulRateLimiter.getRate(""); assertThat(rate).isNull(); }