### Question:
TracezDataAggregator { Map<String, Integer> getErrorSpanCounts() { Map<String, TracezSpanBuckets> completedSpanCache = spanProcessor.getCompletedSpanCache(); Map<String, Integer> numErrorsPerName = new HashMap<>(); for (Map.Entry<String, TracezSpanBuckets> cacheEntry : completedSpanCache.entrySet()) { numErrorsPerName.put(cacheEntry.getKey(), cacheEntry.getValue().getErrorSpans().size()); } return numErrorsPerName; } TracezDataAggregator(TracezSpanProcessor spanProcessor);   }### Answer:
@Test void getErrorSpanCounts_noSpans() { Map<String, Integer> counts = dataAggregator.getErrorSpanCounts(); assertThat(counts).isEmpty(); }
@Test void getErrorSpanCounts_noCompletedSpans() { Span span = tracer.spanBuilder(SPAN_NAME_ONE).startSpan(); Map<String, Integer> counts = dataAggregator.getErrorSpanCounts(); span.setStatus(StatusCanonicalCode.ERROR); span.end(); assertThat(counts).isEmpty(); }
@Test void getErrorSpanCounts_oneSpanPerErrorCode() { for (StatusCanonicalCode errorCode : StatusCanonicalCode.values()) { if (errorCode.equals(StatusCanonicalCode.ERROR)) { Span span = tracer.spanBuilder(SPAN_NAME_ONE).startSpan(); span.setStatus(errorCode); span.end(); } } Map<String, Integer> errorCounts = dataAggregator.getErrorSpanCounts(); assertThat(errorCounts.get(SPAN_NAME_ONE)).isEqualTo(1); }
@Test void getErrorSpanCounts_twoSpanNames() { Span span1 = tracer.spanBuilder(SPAN_NAME_ONE).startSpan(); span1.setStatus(StatusCanonicalCode.ERROR); span1.end(); Span span2 = tracer.spanBuilder(SPAN_NAME_TWO).startSpan(); span2.setStatus(StatusCanonicalCode.ERROR); span2.end(); Map<String, Integer> errorCounts = dataAggregator.getErrorSpanCounts(); assertThat(errorCounts.get(SPAN_NAME_ONE)).isEqualTo(1); assertThat(errorCounts.get(SPAN_NAME_TWO)).isEqualTo(1); }