JmxAttributeGauge implements Gauge<Object> { @Override public Object getValue() { try { Object result = mBeanServerConn.getAttribute(objectName, attributeName); lastUpdate = System.currentTimeMillis(); return result; } catch (IOException e) { return null; } catch (JMException e) { return null; } } JmxAttributeGauge(ObjectName objectName, String attributeName);  JmxAttributeGauge(MBeanServerConnection mBeanServerConn, ObjectName objectName, String attributeName); @Override Object getValue(); @Override long lastUpdateTime();  }
@Test public void returnsAJmxAttribute() throws Exception { when(mBeanServer.getAttribute(objectName, "attr")).thenReturn(value); assertThat(gauge.getValue()) .isEqualTo(value); }
@Test public void returnsNullIfThereIsAnException() throws Exception { when(mBeanServer.getAttribute(objectName, "attr")).thenThrow(new AttributeNotFoundException()); assertThat(gauge.getValue()) .isNull(); }