public static void maybeMeasureLatency(final Runnable actionToMeasure,
                                           final Time time,
                                           final Sensor sensor) {
        if (sensor.shouldRecord() && sensor.hasMetrics()) {
            final long startNs = time.nanoseconds();
            try {
                actionToMeasure.run();
            } finally {
                sensor.record(time.nanoseconds() - startNs);
            }
        } else {
            actionToMeasure.run();
        }
    }
@Test
    public void shouldNotMeasureLatencyBecauseSensorHasNoMetrics() {
        final Sensor sensor = mock(Sensor.class);
        when(sensor.shouldRecord()).thenReturn(true);
        when(sensor.hasMetrics()).thenReturn(false);
        final Time time = mock(Time.class);

        StreamsMetricsImpl.maybeMeasureLatency(() -> { }, time, sensor);
    }