### Question:
DefaultResultProcessor implements ResultProcessor,
        ReferenceProvider { @Override public Buckets<IHasShortcut> processResults() throws IOException, ClassNotFoundException, BadExpressionException { initialize(); for (MetricSpecification metricSpecification : queries) { preProcessQuerySpecifications(metricSpecification); } List<MetricSpecification> calculatedValues = MetricService.calculatedValueFilter(queries); long dataPointTimeStamp = 0l; Tags curTags = null; for (OpenTSDBQueryResult result : this.results) { curTags = Tags.fromOpenTsdbTags(result.tags); MetricKey key = keyCache.get(result.metric, result.metricSpecName, result.metricSpecId, curTags); QueryStatus status = result.getStatus(); log.debug(String.format("Adding QueryStatus %s for key %s (hashcode: %d)", status.getMessage(), key.toString(), key.hashCode())); buckets.addQueryStatus(key, status); for (Map.Entry<Long, Double> dataPointEntry : result.dps.entrySet()) { double dataPointValue = dataPointEntry.getValue(); dataPointTimeStamp = dataPointEntry.getKey(); buckets.add(key, dataPointTimeStamp, dataPointValue); } } interpolateValues(buckets); calculateValues(calculatedValues, buckets); return buckets; } DefaultResultProcessor(Iterable<OpenTSDBQueryResult> results, List<MetricSpecification> queries, long bucketSize); @Override double lookup(String name, Closure closure); @Override Buckets<IHasShortcut> processResults();  }### Answer:
@Test public void testProcessResultsWithConstantSeries() throws Exception { Collection<OpenTSDBQueryResult> qResults = makeResults(); List<MetricSpecification> queries = makeQueries(); DefaultResultProcessor victim = new DefaultResultProcessor(qResults, queries, BUCKET_SIZE); Buckets<IHasShortcut> results = victim.processResults(); assertNotNull("Result of processing query should not be null", results); assertEquals("Seconds per bucket should match specified bucket size.", BUCKET_SIZE, results.getSecondsPerBucket()); for (Long timestamp : results.getTimestamps()) { Buckets.Bucket bucket = results.getBucket(timestamp); assertNotNull(String.format("Null bucket found at timestamp %d.", timestamp), bucket); for (MetricSpecification query : queries) { String nameOrMetric = query.getNameOrMetric(); Value value = bucket.getValueByShortcut(nameOrMetric); String pointDescriptor = String.format("series %s at timestamp %d", nameOrMetric, timestamp); assertNotNull(String.format("Missing value for %s.", pointDescriptor), value); if (query.getNameOrMetric().equals(CALCULATED_VALUE_SERIES_NAME)) { System.out.println(String.format("value of %s at %d is %f", nameOrMetric, timestamp, value.getValue())); assertEquals(String.format("Value of %s not correct.", pointDescriptor), CONST_VALUE + CONST_VALUE, value.getValue(), EPSILON); } } } }
@Test public void testProcessResultsWithYEqualsXSeries() throws Exception { Collection<OpenTSDBQueryResult> qResults = makeYEqualsXResults(); List<MetricSpecification> queries = makeQueries(); DefaultResultProcessor victim = new DefaultResultProcessor(qResults, queries, BUCKET_SIZE); Buckets<IHasShortcut> results = victim.processResults(); assertNotNull("Result of processing query should not be null", results); assertEquals("Seconds per bucket should match specified bucket size.", BUCKET_SIZE, results.getSecondsPerBucket()); for (Long timestamp : results.getTimestamps()) { Buckets.Bucket bucket = results.getBucket(timestamp); assertNotNull(String.format("Null bucket found at timestamp %d.", timestamp), bucket); for (MetricSpecification query : queries) { String nameOrMetric = query.getNameOrMetric(); Value value = bucket.getValueByShortcut(nameOrMetric); String pointDescriptor = String.format("series %s at timestamp %d", nameOrMetric, timestamp); assertNotNull(String.format("Missing value for %s.", pointDescriptor), value); if (query.getNameOrMetric().equals(CALCULATED_VALUE_SERIES_NAME)) { System.out.println(String.format("value of %s at %d is %f", nameOrMetric, timestamp, value.getValue())); assertEquals(String.format("Value of %s not correct.", pointDescriptor), timestamp + timestamp, value.getValue(), EPSILON); } } } }