GraphiteResult { public Datapoint getDatapoint() throws MissingDatapointException { Double value; long timestamp; for (int i = 0; i < this.datapoints.length; i++) { if (datapoints[i][0] == null) continue; value = Double.parseDouble(datapoints[i][0]); timestamp = Long.parseLong(datapoints[i][1]); return new Datapoint(value, timestamp); } throw new MissingDatapointException(); }  Datapoint getDatapoint();  }
@Test public void testGetGraphiteQueryResultFromJson() { List<GraphiteResult> graphiteResults = readGraphiteFile("tests/validGraphiteResponse.json"); for (GraphiteResult graphiteResult : graphiteResults) { Datapoint datapoint = graphiteResult.getDatapoint(); assertEquals(datapoint.getTimestamp(), 1583039100); assertEquals(String.valueOf(datapoint.getValue()), "12.0"); } }
@Test public void testGetGraphiteQueryWithOneNullResultFromJson() { List<GraphiteResult> graphiteResults = readGraphiteFile("tests/validGraphiteResponseWithNull.json"); for (GraphiteResult graphiteResult : graphiteResults) { Datapoint datapoint = graphiteResult.getDatapoint(); assertEquals(datapoint.getTimestamp(), 1583125500); assertEquals(String.valueOf(datapoint.getValue()), "155.0"); } }
@Test public void testGetGraphiteQueryWithOnlyNullResultFromJson() throws MissingDatapointException { List<GraphiteResult> graphiteResults = readGraphiteFile("tests/invalidGraphiteResponse.json"); for (GraphiteResult graphiteResult : graphiteResults) { try { graphiteResult.getDatapoint(); } catch (MissingDatapointException e) { assertTrue(true); } } }