Search in sources :

Example 1 with TestLogHandler

use of okhttp3.TestLogHandler in project okhttp by square.

the class WebSocketHttpTest method throwingOnFailLogs.

@Ignore("AsyncCall currently lets runtime exceptions propagate.")
@Test
public void throwingOnFailLogs() throws InterruptedException {
    TestLogHandler logs = new TestLogHandler();
    Logger logger = Logger.getLogger(OkHttpClient.class.getName());
    logger.addHandler(logs);
    webServer.enqueue(new MockResponse().setResponseCode(200).setBody("Body"));
    final RuntimeException e = new RuntimeException();
    clientListener.setNextEventDelegate(new WebSocketListener() {

        @Override
        public void onFailure(WebSocket webSocket, Throwable t, Response response) {
            throw e;
        }
    });
    newWebSocket();
    assertEquals("", logs.take());
    logger.removeHandler(logs);
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) WebSocketListener(okhttp3.WebSocketListener) OkHttpClient(okhttp3.OkHttpClient) TestLogHandler(okhttp3.TestLogHandler) Logger(java.util.logging.Logger) WebSocket(okhttp3.WebSocket) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Logger (java.util.logging.Logger)1 OkHttpClient (okhttp3.OkHttpClient)1 Response (okhttp3.Response)1 TestLogHandler (okhttp3.TestLogHandler)1 WebSocket (okhttp3.WebSocket)1 WebSocketListener (okhttp3.WebSocketListener)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1