### Question:
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs + b.heldTimeMs; output.acquiredCount = acquiredCount + b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); output.tagTimeMs.put( tag, tagTimeMs.valueAt(i) + (currentTimeMs == null ? 0 : currentTimeMs)); } for (int i = 0, size = b.tagTimeMs.size(); i < size; i++) { String tag = b.tagTimeMs.keyAt(i); if (tagTimeMs.get(tag) == null) { output.tagTimeMs.put(tag, b.tagTimeMs.valueAt(i)); } } } } return output; } WakeLockMetrics();  WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }### Answer:
@Test public void testSumWithAttribution() { WakeLockMetrics metricsA = new WakeLockMetrics(true); metricsA.heldTimeMs = 20l; metricsA.acquiredCount = 4; metricsA.tagTimeMs.put("TestWakeLock1", 10l); metricsA.tagTimeMs.put("TestWakeLock3", 10l); WakeLockMetrics metricsB = new WakeLockMetrics(true); metricsB.heldTimeMs = 20l; metricsB.acquiredCount = 5; metricsB.tagTimeMs.put("TestWakeLock2", 10l); metricsB.tagTimeMs.put("TestWakeLock3", 10l); WakeLockMetrics output = new WakeLockMetrics(true); output.tagTimeMs.put("Test", 1L); output.heldTimeMs = 100L; output.acquiredCount = 442; metricsA.sum(metricsB, output); WakeLockMetrics expectedOutput = new WakeLockMetrics(true); expectedOutput.heldTimeMs = 40l; expectedOutput.acquiredCount = 9; expectedOutput.tagTimeMs.put("TestWakeLock1", 10l); expectedOutput.tagTimeMs.put("TestWakeLock2", 10l); expectedOutput.tagTimeMs.put("TestWakeLock3", 20l); assertThat(output).isEqualTo(expectedOutput); }