SofaTracerCompositeDigestReporterImpl extends AbstractReporter { public synchronized boolean addReporter(Reporter reporter) { if (reporter == null) { return false; } String reporterType = reporter.getReporterType(); if (compositedReporters.containsKey(reporterType)) { return false; } this.compositedReporters.put(reporterType, reporter); return true; }  synchronized boolean addReporter(Reporter reporter); @Override String getReporterType(); @Override void doReport(SofaTracerSpan span);  }
@Test public void testAddReporter() throws Exception { SofaTracerCompositeDigestReporterImpl sofaTracerCompositeDigestReporter = new SofaTracerCompositeDigestReporterImpl(); assertEquals(Reporter.COMPOSITE_REPORTER, sofaTracerCompositeDigestReporter.getReporterType()); Reporter reporterMock1 = mock(Reporter.class); when(reporterMock1.getReporterType()).thenReturn("mock1"); Reporter reporterMock2 = mock(Reporter.class); when(reporterMock2.getReporterType()).thenReturn("mock2"); sofaTracerCompositeDigestReporter.addReporter(reporterMock1); sofaTracerCompositeDigestReporter.addReporter(reporterMock2); SofaTracerSpan span = mock(SofaTracerSpan.class); sofaTracerCompositeDigestReporter.report(span); verify(reporterMock1, times(1)).report(span); verify(reporterMock2, times(1)).report(span); }