ReportCollector { public void collectData() { try { long lastSystemTimeMillis = bucketIdProvider.getLastSystemTimeMillis(); ImmutableTable.Builder<String, Map<String, String>, Object> builder = ImmutableTable.builder(); int numAttributes = 0; for (RegistrationInfo registrationInfo : reportedBeanRegistry.getReportedBeans()) { for (ReportedBeanAttribute attribute : registrationInfo.getReportedBean().getAttributes()) { Object value = null; try { value = attribute.getValue(null); } catch (MBeanException | ReflectionException ignored) { } if (value != null && isReportable(value)) { if (!(value instanceof Number)) { value = value.toString(); } ++numAttributes; StringBuilder stringBuilder = new StringBuilder(); if (registrationInfo.isApplicationPrefix()) { stringBuilder.append(applicationPrefix); } String name = stringBuilder .append(registrationInfo.getNamePrefix()) .append('.') .append(attribute.getName()) .toString(); builder.put(name, registrationInfo.getTags(), value); } } } builder.put("ReportCollector.NumMetrics", versionTags, numAttributes); reportSink.report(lastSystemTimeMillis, builder.build()); } catch (Throwable e) { log.error(e, "Unexpected exception from report collection"); } } @Inject  ReportCollector(
            NodeInfo nodeInfo,
            MinuteBucketIdProvider bucketIdProvider,
            ReportedBeanRegistry reportedBeanRegistry,
            ReportSink reportSink); void collectData();  }
@Test public void testUnreportedValues() throws Exception { when(bucketIdProvider.getLastSystemTimeMillis()).thenReturn(12345L); Object reported = new Object() { @Reported public double getDoubleMetric() { return 0; } @Reported public double getNanDouble() { return Double.NaN; } @Reported public double getInfiniteDouble() { return Double.NEGATIVE_INFINITY; } @Reported public float getFloatMetric() { return 0F; } @Reported public float getNanFloat() { return Float.NaN; } @Reported public float getInfiniteFloat() { return Float.POSITIVE_INFINITY; } @Reported public long getLongMetric() { return 0L; } @Reported public long getMaxLongMetric() { return Long.MAX_VALUE; } @Reported public long getMinLongMetric() { return Long.MIN_VALUE; } @Reported public int getIntegerMetric() { return 0; } @Reported public int getMaxIntegerMetric() { return Integer.MAX_VALUE; } @Reported public int getMinIntegerMetric() { return Integer.MIN_VALUE; } @Reported public short getShortMetric() { return 0; } @Reported public short getMaxShortMetric() { return Short.MAX_VALUE; } @Reported public short getMinShortMetric() { return Short.MIN_VALUE; } @Reported public byte getByteMetric() { return 0; } @Reported public byte getMaxByteMetric() { return Byte.MAX_VALUE; } @Reported public byte getMinByteMetric() { return Byte.MIN_VALUE; } @Reported public boolean getFalseBooleanMetric() { return false; } @Reported public Boolean getTrueBooleanMetric() { return true; } @Reported public Boolean getNullBooleanMetric() { return null; } @Reported public TestingValue getTestingValueMetric() { return new TestingValue(); } @Reported public Integer getNullMetric() { return null; } @Reported public int getExceptionMetric() { throw new UnsupportedOperationException(); } }; reportedBeanRegistry.register(reported, ReportedBean.forTarget(reported, bucketIdProvider), false, "TestObject", ImmutableMap.of()); reportCollector.collectData(); verify(reportSink).report(eq(12345L), tableCaptor.capture()); verifyNoMoreInteractions(reportSink); Table<String, Map<String, String>, Object> table = tableCaptor.getValue(); assertEqualsIgnoreOrder(table.cellSet(), ImmutableTable.<String, Map<String, String>, Object>builder() .put("TestObject.DoubleMetric", ImmutableMap.of(), 0.0) .put("TestObject.FloatMetric", ImmutableMap.of(), 0F) .put("TestObject.LongMetric", ImmutableMap.of(), 0L) .put("TestObject.IntegerMetric", ImmutableMap.of(), 0) .put("TestObject.ShortMetric", ImmutableMap.of(), (short) 0) .put("TestObject.ByteMetric", ImmutableMap.of(), (byte) 0) .put("TestObject.MaxByteMetric", ImmutableMap.of(), Byte.MAX_VALUE) .put("TestObject.MinByteMetric", ImmutableMap.of(), Byte.MIN_VALUE) .put("TestObject.FalseBooleanMetric", ImmutableMap.of(), 0) .put("TestObject.TrueBooleanMetric", ImmutableMap.of(), 1) .put("TestObject.TestingValueMetric", ImmutableMap.of(), "testing toString value") .put("ReportCollector.NumMetrics", EXPECTED_VERSION_TAGS, 11) .build() .cellSet()); }