@Override
    public double read() {
        return gaugeSource.read();
    }
@Test
    public void whenCacheDynamicMetricValueReplacedWithCachedMetricSource() {
        DoubleGauge doubleGauge = metricsRegistry.newDoubleGauge("foo.doubleField");

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

        assertEquals(142.42D, doubleGauge.read(), 10E-6);

        metricsRegistry.deregisterDynamicMetricsProvider(concreteProvider);

        // provide metric source to be cached
        SomeObject someObject = new SomeObject();
        someObject.doubleField = 42.42D;
        metricsRegistry.registerDynamicMetricsProvider(someObject);

        // needed to collect dynamic metrics and update the gauge created from them
        metricsRegistry.collect(mock(MetricsCollector.class));
        assertEquals(42.42D, doubleGauge.read(), 10E-6);
    }