package com.codahale.metrics.jvm;

import com.codahale.metrics.Gauge;
import org.junit.Test;

import java.lang.management.ClassLoadingMXBean;

import static org.fest.assertions.api.Assertions.assertThat;

public class ClassLoadingGaugeSetTest {

    private final ClassLoadingMXBean cl = new ClassLoadingMXBean() {
        @Override
        public long getTotalLoadedClassCount() {
            return 2;
        }

        @Override
        public int getLoadedClassCount() {
            return 3;
        }

        @Override
        public long getUnloadedClassCount() {
            return 1;
        }

        @Override
        public boolean isVerbose() {
            return false;
        }

        @Override
        public void setVerbose(boolean value) {

        }
    };

    private final ClassLoadingGaugeSet gauges = new ClassLoadingGaugeSet(cl);

    @Test
    public void loadedGauge() throws Exception {
        final Gauge gauge = (Gauge) gauges.getMetrics().get("loaded");
        assertThat(gauge.getValue()).isEqualTo(2L);
    }

    @Test
    public void unLoadedGauge() throws Exception {
        final Gauge gauge = (Gauge) gauges.getMetrics().get("unloaded");
        assertThat(gauge.getValue()).isEqualTo(1L);
    }

}

@@ -63,16 +63,41 @@
 .Gauge;%0A
+import org.junit.Before;%0A
 import o
@@ -221,16 +221,96 @@
 ertThat;
+%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;
 %0A%0Apublic
@@ -386,20 +386,21 @@
 an cl = 
-new 
+mock(
 ClassLoa
@@ -413,558 +413,273 @@
 Bean
-() %7B%0A        @Override%0A        public long getTotalLoadedClassCount() %7B%0A            return 2;%0A        %7D%0A%0A        @Override%0A        public int getLoadedClassCount() %7B%0A            return 3;%0A        %7D%0A%0A        @Override%0A        public long getUnloadedClassCount() %7B%0A            return 1;%0A        %7D%0A%0A        @Override%0A        public boolean isVerbose() %7B%0A            return false;%0A        %7D%0A%0A        @Override%0A        public void setVerbose(boolean value) %7B%0A%0A        %7D%0A    %7D;%0A%0A    private final ClassLoadingGaugeSet gauges = new ClassLoadingGaugeSet(cl);
+.class);%0A    private final ClassLoadingGaugeSet gauges = new ClassLoadingGaugeSet(cl);%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        when(cl.getTotalLoadedClassCount()).thenReturn(2L);%0A        when(cl.getUnloadedClassCount()).thenReturn(1L);%0A    %7D
 %0A%0A  

Switch to a mocking way of testing.