HistoricalMetric { public JSONObject toJSONObject() { Stream<HistogramMetric> stream = _histogramMetrics.stream(); JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); stream.forEach( histogramMetric -> jsonArray.put(histogramMetric.toJSONObject())); return JSONUtil.put( "histogram", jsonArray ).put( "value", _value ); } HistoricalMetric();  HistoricalMetric(
		List<HistogramMetric> histogramMetrics, double value); @Override boolean equals(Object object); List<HistogramMetric> getHistogramMetrics(); Double getValue(); @Override int hashCode(); void setHistogramMetrics(List<HistogramMetric> histogramMetrics); void setValue(double value); JSONObject toJSONObject();  }
@Test public void testToJSONObject() { HistogramMetric histogramMetric = new HistogramMetric( new Date(), RandomTestUtil.randomDouble()); HistoricalMetric historicalMetric = new HistoricalMetric( Collections.singletonList(histogramMetric), RandomTestUtil.randomDouble()); JSONObject jsonObject = historicalMetric.toJSONObject(); Assert.assertEquals( JSONUtil.put( "histogram", JSONUtil.put( JSONUtil.put( "key", _formatDate(histogramMetric.getKey()) ).put( "value", histogramMetric.getValue() )) ).put( "value", historicalMetric.getValue() ).toJSONString(), jsonObject.toJSONString()); }