### Question:
CollectorProxy implements Collector { @Override public void collectTrace(TraceReader traceReader) throws Exception { if (instance == null) { earlyTraceReaders.offer(traceReader); if (instance != null) { earlyTraceReaders.remove(traceReader); instance.collectTrace(traceReader); } } else { instance.collectTrace(traceReader); } }  @Override void init(File confDir, @Nullable File sharedConfDir, Environment environment,
            AgentConfig agentConfig, AgentConfigUpdater agentConfigUpdater); @Override void collectAggregates(AggregateReader aggregateReader); @Override void collectGaugeValues(List<GaugeValue> gaugeValues); @Override void collectTrace(TraceReader traceReader); @Override void log(LogEvent logEvent); @VisibleForTesting void setInstance(Collector instance);  }### Answer:
@Test public void testCollectTrace() throws Exception { CollectorProxy collectorProxy = new CollectorProxy(); TraceReader traceReader1 = mock(TraceReader.class); TraceReader traceReader2 = mock(TraceReader.class); TraceReader traceReader3 = mock(TraceReader.class); collectorProxy.collectTrace(traceReader1); collectorProxy.collectTrace(traceReader2); Collector collector = mock(Collector.class); collectorProxy.setInstance(collector); collectorProxy.collectTrace(traceReader3); InOrder inOrder = Mockito.inOrder(collector); inOrder.verify(collector).collectTrace(traceReader1); inOrder.verify(collector).collectTrace(traceReader2); inOrder.verify(collector).collectTrace(traceReader3); }