### Question:
DropwizardRequestMetrics implements RequestMetrics { @Override public Context startCrudRequest(String operation, String entity, String version) { return new DropwizardContext(metricNamer.crud(operation, entity, version)); } DropwizardRequestMetrics(MetricRegistry metricRegistry);  DropwizardRequestMetrics(MetricRegistry metricRegistry, MetricNamer metricNamer); static DropwizardRequestMetrics withDefaultMBeans(MetricRegistry registry); @Override Context startCrudRequest(String operation, String entity, String version); @Override Context startStreamingCrudRequest(String operation, String entity, String version); @Override Context startLockRequest(String lockOperation, String domain); @Override Context startHealthRequest(); @Override Context startDiagnosticsRequest(); @Override Context startSavedSearchRequest(String searchName, String entity, String version); @Override Context startBulkRequest(); @Override Context startGenerateRequest(String entity, String version, String field);  }### Answer:
@Test public void testStartRequestMonitoring() { requestMetrics.startCrudRequest("save", "name", null); Assert.assertNotNull(metricsRegistry.getCounters()); Assert.assertNotNull(metricsRegistry.getTimers()); Counter activeRequestCounter = metricsRegistry.counter("request.crud.save.name.default.active"); Timer completedRequestTimer = metricsRegistry.timer("request.crud.save.name.default"); Assert.assertEquals(1, activeRequestCounter.getCount()); Assert.assertEquals(0, completedRequestTimer.getCount()); }
@Test public void testEndRequestMonitoring() { DropwizardRequestMetrics.Context context = requestMetrics.startCrudRequest("explain", "name", "1.0.0"); context.endRequestMonitoring(); Counter activeRequestCounter = metricsRegistry.counter("request.crud.explain.name.1_0_0.active"); Timer completedRequestTimer = metricsRegistry.timer("request.crud.explain.name.1_0_0"); Assert.assertEquals(0, activeRequestCounter.getCount()); Assert.assertEquals(1, completedRequestTimer.getCount()); }
@Test public void testStartRequestMonitoringNullVersion() { DropwizardRequestMetrics.Context context = requestMetrics.startCrudRequest("delete", "name", "1.2.3"); Assert.assertNotNull(metricsRegistry.getCounters()); Assert.assertNotNull(metricsRegistry.getTimers()); Counter activeRequestCounter = metricsRegistry.counter("request.crud.delete.name.1_2_3.active"); Timer completedRequestTimer = metricsRegistry.timer("request.crud.delete.name.1_2_3"); Assert.assertEquals(1, activeRequestCounter.getCount()); Assert.assertEquals(0, completedRequestTimer.getCount()); context.endRequestMonitoring(); Assert.assertEquals(1, completedRequestTimer.getCount()); }