@Test
public void testRemoveSensor() {

    int size = metrics.metrics().size();
    Sensor parent1 = metrics.sensor("test.parent1");
    parent1.add(metrics.metricName("test.parent1.count", "grp1"), new Count());
    Sensor parent2 = metrics.sensor("test.parent2");
    parent2.add(metrics.metricName("test.parent2.count", "grp1"), new Count());
    Sensor child1 = metrics.sensor("test.child1", parent1, parent2);
    child1.add(metrics.metricName("test.child1.count", "grp1"), new Count());
    Sensor child2 = metrics.sensor("test.child2", parent2);
    child2.add(metrics.metricName("test.child2.count", "grp1"), new Count());
    Sensor grandChild1 = metrics.sensor("test.gchild2", child2);
    grandChild1.add(metrics.metricName("test.gchild2.count", "grp1"), new Count());
    Sensor sensor = metrics.getSensor("test.parent1");
    assertNotNull(sensor);
    metrics.removeSensor("test.parent1");
    assertNull(metrics.getSensor("test.parent1"));
    assertNull(metrics.metrics().get(metrics.metricName("test.parent1.count", "grp1")));
    assertNull(metrics.getSensor("test.child1"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.child1.count", "grp1")));
    sensor = metrics.getSensor("test.gchild2");
    assertNotNull(sensor);
    metrics.removeSensor("test.gchild2");
    assertNull(metrics.getSensor("test.gchild2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.gchild2.count", "grp1")));
    sensor = metrics.getSensor("test.child2");
    assertNotNull(sensor);
    metrics.removeSensor("test.child2");
    assertNull(metrics.getSensor("test.child2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.child2.count", "grp1")));
    sensor = metrics.getSensor("test.parent2");
    assertNotNull(sensor);
    metrics.removeSensor("test.parent2");
    assertNull(metrics.getSensor("test.parent2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.parent2.count", "grp1")));
    assertEquals(size, metrics.metrics().size());
}