### Question:
ZipkinSpanExporter implements SpanExporter { @Override public CompletableResultCode export(final Collection<SpanData> spanDataList) { List<byte[]> encodedSpans = new ArrayList<>(spanDataList.size()); for (SpanData spanData : spanDataList) { encodedSpans.add(encoder.encode(generateSpan(spanData, localEndpoint))); } final CompletableResultCode result = new CompletableResultCode(); sender .sendSpans(encodedSpans) .enqueue( new Callback<Void>() { @Override public void onSuccess(Void value) { result.succeed(); } @Override public void onError(Throwable t) { logger.log(Level.WARNING, "Failed to export spans", t); result.fail(); } }); return result; } ZipkinSpanExporter(BytesEncoder<Span> encoder, Sender sender, String serviceName); @Override CompletableResultCode export(final Collection<SpanData> spanDataList); @Override CompletableResultCode flush(); @Override CompletableResultCode shutdown(); static Builder newBuilder(); static final String DEFAULT_ENDPOINT; static final String DEFAULT_SERVICE_NAME; }### Answer:
@Test void testExport() { ZipkinSpanExporter zipkinSpanExporter = new ZipkinSpanExporter(mockEncoder, mockSender, "tweetiebird"); byte[] someBytes = new byte[0]; when(mockEncoder.encode(buildZipkinSpan(Span.Kind.SERVER))).thenReturn(someBytes); when(mockSender.sendSpans(Collections.singletonList(someBytes))).thenReturn(mockZipkinCall); doAnswer( invocation -> { Callback<Void> callback = invocation.getArgument(0); callback.onSuccess(null); return null; }) .when(mockZipkinCall) .enqueue(any()); CompletableResultCode resultCode = zipkinSpanExporter.export(Collections.singleton(buildStandardSpan().build())); assertThat(resultCode.isSuccess()).isTrue(); }
@Test void testExport_failed() { ZipkinSpanExporter zipkinSpanExporter = new ZipkinSpanExporter(mockEncoder, mockSender, "tweetiebird"); byte[] someBytes = new byte[0]; when(mockEncoder.encode(buildZipkinSpan(Span.Kind.SERVER))).thenReturn(someBytes); when(mockSender.sendSpans(Collections.singletonList(someBytes))).thenReturn(mockZipkinCall); doAnswer( invocation -> { Callback<Void> callback = invocation.getArgument(0); callback.onError(new IOException()); return null; }) .when(mockZipkinCall) .enqueue(any()); CompletableResultCode resultCode = zipkinSpanExporter.export(Collections.singleton(buildStandardSpan().build())); assertThat(resultCode.isSuccess()).isFalse(); }