### Question:
ValidationHelper { void recordResults(int numMeasurements, HttpResponse res) { if (res.status() == 200) { measurementsSent.increment(numMeasurements); } else if (res.status() < 500) { try { ValidationResponse vres = jsonMapper.readValue(res.entity(), ValidationResponse.class); measurementsDroppedInvalid.increment(vres.getErrorCount()); measurementsSent.increment(numMeasurements - vres.getErrorCount()); logger.warn("{} measurement(s) dropped due to validation errors: {}", vres.getErrorCount(), vres.errorSummary()); } catch (Exception e) { logger.trace("failed to parse response", e); logger.warn("{} measurement(s) dropped. Http status: {}", numMeasurements, res.status()); measurementsDroppedOther.increment(numMeasurements); } } else { measurementsDroppedHttp.increment(numMeasurements); } } ValidationHelper(Logger logger, ObjectMapper jsonMapper, Registry registry);   }### Answer:
@Test public void ok() { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); helper.recordResults(42, new HttpResponse(200, Collections.emptyMap())); check(registry, 42, 0, 0, 0); }
@Test public void validationErrorPartial() throws IOException { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); ValidationResponse vres = new ValidationResponse(); vres.setType("error"); vres.setErrorCount(3); vres.setMessage(Collections.singletonList("foo")); helper.recordResults(42, httpResponse(202, vres)); check(registry, 39, 0, 3, 0); }
@Test public void validationErrorAll() throws IOException { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); ValidationResponse vres = new ValidationResponse(); vres.setType("error"); vres.setErrorCount(42); vres.setMessage(Collections.singletonList("foo")); helper.recordResults(42, httpResponse(400, vres)); check(registry, 0, 0, 42, 0); }
@Test public void validationErrorNullMessages() throws IOException { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); ValidationResponse vres = new ValidationResponse(); vres.setType("error"); vres.setErrorCount(42); helper.recordResults(42, httpResponse(400, vres)); check(registry, 0, 0, 42, 0); }
@Test public void validationErrorEmptyMessages() throws IOException { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); ValidationResponse vres = new ValidationResponse(); vres.setType("error"); vres.setErrorCount(42); vres.setMessage(Collections.emptyList()); helper.recordResults(42, httpResponse(400, vres)); check(registry, 0, 0, 42, 0); }
@Test public void validationErrorBadJson() throws IOException { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); HttpResponse res = new HttpResponse(400, Collections.emptyMap()); helper.recordResults(42, res); check(registry, 0, 0, 0, 42); }
@Test public void serverError() { Registry registry = new DefaultRegistry(); ValidationHelper helper = new ValidationHelper(LOGGER, MAPPER, registry); helper.recordResults(42, new HttpResponse(500, Collections.emptyMap())); check(registry, 0, 42, 0, 0); }