@Override
    public long read() {
        return gaugeSource.read();
    }
@Test
    public void whenCacheDynamicMetricValueReplacedWithCachedMetricSource() {
        LongGaugeImpl longGauge = metricsRegistry.newLongGauge("foo.longField");

        // provide concrete value
        DynamicMetricsProvider concreteProvider = (descriptor, context) ->
                context.collect(descriptor.withPrefix("foo"), "longField", INFO, COUNT, 142);
        metricsRegistry.registerDynamicMetricsProvider(concreteProvider);
        // needed to collect dynamic metrics and update the gauge created from them
        metricsRegistry.collect(mock(MetricsCollector.class));

        assertEquals(142, longGauge.read());

        metricsRegistry.deregisterDynamicMetricsProvider(concreteProvider);

        // provide metric source to be cached
        SomeObject someObject = new SomeObject();
        someObject.longField = 42;
        metricsRegistry.registerDynamicMetricsProvider(someObject);

        // needed to collect dynamic metrics and update the gauge created from them
        metricsRegistry.collect(mock(MetricsCollector.class));
        assertEquals(42, longGauge.read());
    }