Search in sources :

Example 11 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project enroscar by stanfy.

the class AbstractImagesTest method startServer.

@Before
public void startServer() throws IOException {
    server = new MockWebServer();
    server.play();
}
Also used : MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) Before(org.junit.Before)

Example 12 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project enroscar by stanfy.

the class AbstractMockServerTest method runServer.

@Before
public void runServer() throws IOException {
    webServer = new MockWebServer();
    webServer.play();
}
Also used : MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) Before(org.junit.Before)

Example 13 with MockWebServer

use of com.squareup.okhttp.mockwebserver.MockWebServer in project enroscar by stanfy.

the class CacheSwitcherTest method testCacheSwitching.

@Test
public void testCacheSwitching() throws IOException {
    final String response1 = "<response to be cached by the FIRST testCache>";
    final String response2 = "<response to be cached by the SECOND testCache>";
    final MockWebServer webServer = getWebServer();
    // two responses
    webServer.enqueue(new MockResponse().setBody(response1));
    webServer.enqueue(new MockResponse().setBody(response2));
    // first request, first cache => not cached
    perform("/1/", cache1, response1, false);
    // second request, first cache => cached
    perform("/1/", cache1, response1, true);
    // first request, second cache => not cached
    perform("/2/", cache2, response2, false);
    // second request, second cache => cached
    perform("/2/", cache2, response2, true);
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) Test(org.junit.Test) AbstractMockServerTest(com.stanfy.enroscar.net.test.AbstractMockServerTest)

Aggregations

MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)13 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)6 Before (org.junit.Before)4 Test (org.junit.Test)4 Buffer (okio.Buffer)3 Request (com.squareup.okhttp.Request)2 Response (com.squareup.okhttp.Response)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Bitmap (android.graphics.Bitmap)1 RequestBody (com.squareup.okhttp.RequestBody)1 AbstractMockServerTest (com.stanfy.enroscar.net.test.AbstractMockServerTest)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 RestAdapter (retrofit.RestAdapter)1