ConsulRateLimiter extends AbstractRateLimiter { @Override protected void saveRate(Rate rate) { String value = ""; try { value = this.objectMapper.writeValueAsString(rate); } catch (JsonProcessingException e) { log.error("Failed to serialize Rate", e); } if (hasText(value)) { this.consulClient.setKVValue(rate.getKey(), value); } } ConsulRateLimiter(RateLimiterErrorHandler rateLimiterErrorHandler,
        ConsulClient consulClient, ObjectMapper objectMapper);   }
@Test public void testSaveRateException() throws IOException { JsonProcessingException jsonProcessingException = Mockito.mock(JsonProcessingException.class); when(objectMapper.writeValueAsString(any())).thenThrow(jsonProcessingException); ConsulRateLimiter consulRateLimiter = new ConsulRateLimiter(rateLimiterErrorHandler, consulClient, objectMapper); consulRateLimiter.saveRate(null); verifyNoInteractions(consulClient); }