ApiResponseCounter implements MeterBinder { public void handleStatus(int status) { status = status / 100; switch (status) { case 1: informationalResponseCounter.increment(); break; case 2: successResponseCounter.increment(); break; case 3: redirectResponseCounter.increment(); break; case 4: clientErrorResponseCounter.increment(); break; case 5: serverErrorResponseCounter.increment(); break; default: LOG.warn("Unhandled HTTP status ", status); } }  @Override void bindTo(MeterRegistry registry); void handleStatus(int status);  }
@Test(dataProvider = "information") public void shouldCount1xxResponses(int status) { apiResponseCounter.handleStatus(status); assertEquals(apiResponseCounter.informationalResponseCounter.count(), 1.0); assertEquals(apiResponseCounter.successResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.redirectResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.clientErrorResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.serverErrorResponseCounter.count(), 0.0); }
@Test(dataProvider = "success") public void shouldCount2xxResponses(int status) { apiResponseCounter.handleStatus(status); assertEquals(apiResponseCounter.informationalResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.successResponseCounter.count(), 1.0); assertEquals(apiResponseCounter.redirectResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.clientErrorResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.serverErrorResponseCounter.count(), 0.0); }
@Test(dataProvider = "redirect") public void shouldCount3xxResponses(int status) { apiResponseCounter.handleStatus(status); assertEquals(apiResponseCounter.informationalResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.successResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.redirectResponseCounter.count(), 1.0); assertEquals(apiResponseCounter.clientErrorResponseCounter.count(), .0); assertEquals(apiResponseCounter.serverErrorResponseCounter.count(), 0.0); }
@Test(dataProvider = "clientError") public void shouldCount4xxResponses(int status) { apiResponseCounter.handleStatus(status); assertEquals(apiResponseCounter.informationalResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.successResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.redirectResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.clientErrorResponseCounter.count(), 1.0); assertEquals(apiResponseCounter.serverErrorResponseCounter.count(), 0.0); }
@Test(dataProvider = "serverError") public void shouldCount5xxResponses(int status) { apiResponseCounter.handleStatus(status); assertEquals(apiResponseCounter.informationalResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.successResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.redirectResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.clientErrorResponseCounter.count(), 0.0); assertEquals(apiResponseCounter.serverErrorResponseCounter.count(), 1.0); }