Search in sources :

Example 16 with Client

use of com.optimizely.ab.android.shared.Client in project android-sdk by optimizely.

the class EventClientTest method sendEvents300.

@Test
public void sendEvents300() throws IOException {
    when(client.openConnection(event.getURL())).thenReturn(urlConnection);
    when(urlConnection.getResponseCode()).thenReturn(300);
    InputStream inputStream = mock(InputStream.class);
    when(urlConnection.getInputStream()).thenReturn(inputStream);
    eventClient.sendEvent(event);
    ArgumentCaptor<Client.Request> captor1 = ArgumentCaptor.forClass(Client.Request.class);
    ArgumentCaptor<Integer> captor2 = ArgumentCaptor.forClass(Integer.class);
    ArgumentCaptor<Integer> captor3 = ArgumentCaptor.forClass(Integer.class);
    verify(client).execute(captor1.capture(), captor2.capture(), captor3.capture());
    assertEquals(Integer.valueOf(2), captor2.getValue());
    assertEquals(Integer.valueOf(5), captor3.getValue());
    Object response = captor1.getValue().execute();
    assertEquals(Boolean.FALSE, response);
    verify(logger).info("Dispatching event: {}", event);
    verify(logger).error("Unexpected response from event endpoint, status: 300");
}
Also used : InputStream(java.io.InputStream) Client(com.optimizely.ab.android.shared.Client) Test(org.junit.Test)

Aggregations

Client (com.optimizely.ab.android.shared.Client)16 Test (org.junit.Test)10 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)7 URL (java.net.URL)6 Cache (com.optimizely.ab.android.shared.Cache)5 OptlyStorage (com.optimizely.ab.android.shared.OptlyStorage)5 InputStream (java.io.InputStream)3 Context (android.content.Context)2 Logger (org.slf4j.Logger)2 Intent (android.content.Intent)1 IBinder (android.os.IBinder)1 ServiceScheduler (com.optimizely.ab.android.shared.ServiceScheduler)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1