AppCenterIngestion implements Ingestion { @Override public ServiceCall sendAsync(String appSecret, UUID installId, LogContainer logContainer, final ServiceCallback serviceCallback) throws IllegalArgumentException { Map<String, String> headers = new HashMap<>(); headers.put(INSTALL_ID, installId.toString()); headers.put(APP_SECRET, appSecret); HttpClient.CallTemplate callTemplate = new IngestionCallTemplate(mLogSerializer, logContainer); return mHttpClient.callAsync(mLogUrl + API_PATH, METHOD_POST, headers, callTemplate, serviceCallback); } AppCenterIngestion(@NonNull HttpClient httpClient, @NonNull LogSerializer logSerializer); @Override @SuppressWarnings("SameParameterValue") void setLogUrl(@NonNull String logUrl); @Override ServiceCall sendAsync(String appSecret, UUID installId, LogContainer logContainer, final ServiceCallback serviceCallback); @Override void close(); @Override void reopen(); @SuppressWarnings("WeakerAccess")
    static final String DEFAULT_LOG_URL; }
@Test public void sendAsync() throws Exception { LogContainer container = new LogContainer(); Log log = mock(Log.class); List<Log> logs = new ArrayList<>(); logs.add(log); container.setLogs(logs); LogSerializer serializer = mock(LogSerializer.class); when(serializer.serializeContainer(any(LogContainer.class))).thenReturn("mockPayload"); final ServiceCall call = mock(ServiceCall.class); final AtomicReference<HttpClient.CallTemplate> callTemplate = new AtomicReference<>(); when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).then(new Answer<ServiceCall>() { @Override public ServiceCall answer(InvocationOnMock invocation) { callTemplate.set((HttpClient.CallTemplate) invocation.getArguments()[3]); return call; } }); AppCenterIngestion ingestion = new AppCenterIngestion(mHttpClient, serializer); ingestion.setLogUrl("http: String appSecret = UUID.randomUUID().toString(); UUID installId = UUID.randomUUID(); ServiceCallback serviceCallback = mock(ServiceCallback.class); assertEquals(call, ingestion.sendAsync(appSecret, installId, container, serviceCallback)); HashMap<String, String> expectedHeaders = new HashMap<>(); expectedHeaders.put(Constants.APP_SECRET, appSecret); expectedHeaders.put(AppCenterIngestion.INSTALL_ID, installId.toString()); verify(mHttpClient).callAsync(eq("http: assertNotNull(callTemplate.get()); assertEquals("mockPayload", callTemplate.get().buildRequestBody()); ingestion.close(); verify(mHttpClient).close(); ingestion.reopen(); verify(mHttpClient).reopen(); }