Skip to content

Commit

Permalink
Fix accidental coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
guperrot committed Oct 17, 2019
1 parent 9cf334e commit 2ae32a2
Showing 1 changed file with 15 additions and 6 deletions.
Expand Up @@ -74,8 +74,7 @@ public void setUp() throws Exception {
doReturn(mHttpClient).when(HttpUtils.class, "createHttpClient", any(Context.class));
}

@Test
public void sendAsync() throws Exception {
private void sendAuthToken(String authToken) throws Exception {

/* Build some payload. */
LogContainer container = new LogContainer();
Expand All @@ -102,21 +101,21 @@ public ServiceCall answer(InvocationOnMock invocation) {
AppCenterIngestion ingestion = new AppCenterIngestion(mock(Context.class), serializer);
ingestion.setLogUrl("http://mock");
String appSecret = UUID.randomUUID().toString();
String authToken = UUID.randomUUID().toString();
UUID installId = UUID.randomUUID();
ServiceCallback serviceCallback = mock(ServiceCallback.class);
assertEquals(call, ingestion.sendAsync(authToken, appSecret, installId, container, serviceCallback));

/* Verify call to http client. */
HashMap<String, String> expectedHeaders = new HashMap<>();
expectedHeaders.put(Constants.APP_SECRET, appSecret);
expectedHeaders.put(Constants.AUTHORIZATION_HEADER, String.format(Constants.AUTH_TOKEN_FORMAT, authToken));
if (authToken != null) {
expectedHeaders.put(Constants.AUTHORIZATION_HEADER, String.format(Constants.AUTH_TOKEN_FORMAT, authToken));
}
expectedHeaders.put(AppCenterIngestion.INSTALL_ID, installId.toString());
verify(mHttpClient).callAsync(eq("http://mock" + AppCenterIngestion.API_PATH), eq(METHOD_POST), eq(expectedHeaders), notNull(HttpClient.CallTemplate.class), eq(serviceCallback));
assertNotNull(callTemplate.get());
assertEquals("mockPayload", callTemplate.get().buildRequestBody());
assertEquals(authToken, authToken);


/* Verify close. */
ingestion.close();
verify(mHttpClient).close();
Expand All @@ -126,6 +125,16 @@ public ServiceCall answer(InvocationOnMock invocation) {
verify(mHttpClient).reopen();
}

@Test
public void sendAsyncWithoutAuthToken() throws Exception {
sendAuthToken(null);
}

@Test
public void sendAsyncWithAuthToken() throws Exception {
sendAuthToken(UUID.randomUUID().toString());
}

@Test
public void failedSerialization() throws Exception {

Expand Down

0 comments on commit 2ae32a2

Please sign in to comment.