### Question:
HttpCollectorClient extends BaseHttpClient implements Client<Span> { @Override public boolean send(Span span) throws ClientException { final byte[] spanBytes = format.format(span).toByteArray(); return super.send(spanBytes); } HttpCollectorClient(String endpoint, Map<String, String> headers);  HttpCollectorClient(String endpoint);  HttpCollectorClient(final String endpoint,
                               final Map<String, String> headers,
                               final CloseableHttpClient httpClient); @Override boolean send(Span span);  }### Answer:
@Test public void testDispatch() throws Exception { final Span span = tracer.buildSpan("happy-path").asChildOf(spanContext).start(); span.finish(); final ArgumentCaptor<HttpPost> httpPostCapture = ArgumentCaptor.forClass(HttpPost.class); final CloseableHttpClient http = Mockito.mock(CloseableHttpClient.class); final CloseableHttpResponse httpResponse = Mockito.mock(CloseableHttpResponse.class); final BasicStatusLine statusLine = new BasicStatusLine(new ProtocolVersion("v", 1, 1), 200, ""); when(http.execute(httpPostCapture.capture())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(statusLine); final Map<String, String> headers = new HashMap<>(); headers.put("client-id", "my-client"); final HttpCollectorClient client = new HttpCollectorClient("http: final boolean isSuccess = client.send(span); client.close(); verify(http, times(1)).execute(httpPostCapture.capture()); verify(httpResponse, times(1)).close(); verify(http, times(1)).close(); verifyCapturedHttpPost(httpPostCapture.getValue()); assertEquals(isSuccess, true); }
@Test(expected = ClientException.class) public void testFailedDispatch() throws Exception { final Span span = tracer.buildSpan("sad-path").start(); span.finish(); final ArgumentCaptor<HttpPost> httpPostCapture = ArgumentCaptor.forClass(HttpPost.class); final CloseableHttpClient http = Mockito.mock(CloseableHttpClient.class); final CloseableHttpResponse httpResponse = Mockito.mock(CloseableHttpResponse.class); final BasicStatusLine statusLine = new BasicStatusLine(new ProtocolVersion("v", 1, 1), 404, ""); when(http.execute(httpPostCapture.capture())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(statusLine); final HttpCollectorClient client = new HttpCollectorClient("http: client.send(span); }
@Test(expected = ClientException.class) public void testAnotherFailedDispatch() throws Exception { final Span span = tracer.buildSpan("sad-path").start(); span.finish(); final ArgumentCaptor<HttpPost> httpPostCapture = ArgumentCaptor.forClass(HttpPost.class); final CloseableHttpClient http = Mockito.mock(CloseableHttpClient.class); when(http.execute(httpPostCapture.capture())).thenThrow(new IOException()); final HttpCollectorClient client = new HttpCollectorClient("http: client.send(span); }