Search in sources :

Example 1 with ResponseHandler

use of com.facebook.stetho.inspector.network.ResponseHandler in project stetho by facebook.

the class StethoInterceptorTest method hookAlmostRealInterpretResponseStream.

/**
   * Provide a suitably "real" implementation of
   * {@link NetworkEventReporter#interpretResponseStream} for our mock to test that
   * events are properly delegated.
   */
private static ByteArrayOutputStream hookAlmostRealInterpretResponseStream(final NetworkEventReporter mockEventReporter) {
    final ByteArrayOutputStream capturedOutput = new ByteArrayOutputStream();
    Mockito.when(mockEventReporter.interpretResponseStream(anyString(), anyString(), anyString(), any(InputStream.class), any(ResponseHandler.class))).thenAnswer(new Answer<InputStream>() {

        @Override
        public InputStream answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String requestId = (String) args[0];
            String contentEncoding = (String) args[2];
            InputStream responseStream = (InputStream) args[3];
            ResponseHandler responseHandler = (ResponseHandler) args[4];
            return DecompressionHelper.teeInputWithDecompression(null, /* networkPeerManager */
            requestId, responseStream, capturedOutput, contentEncoding, responseHandler);
        }
    });
    return capturedOutput;
}
Also used : ResponseHandler(com.facebook.stetho.inspector.network.ResponseHandler) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with ResponseHandler

use of com.facebook.stetho.inspector.network.ResponseHandler in project stetho by facebook.

the class StethoInterceptorTest method hookAlmostRealInterpretResponseStream.

/**
   * Provide a suitably "real" implementation of
   * {@link NetworkEventReporter#interpretResponseStream} for our mock to test that
   * events are properly delegated.
   */
private static ByteArrayOutputStream hookAlmostRealInterpretResponseStream(final NetworkEventReporter mockEventReporter) {
    final ByteArrayOutputStream capturedOutput = new ByteArrayOutputStream();
    Mockito.when(mockEventReporter.interpretResponseStream(anyString(), anyString(), anyString(), any(InputStream.class), any(ResponseHandler.class))).thenAnswer(new Answer<InputStream>() {

        @Override
        public InputStream answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            String requestId = (String) args[0];
            String contentEncoding = (String) args[2];
            InputStream responseStream = (InputStream) args[3];
            ResponseHandler responseHandler = (ResponseHandler) args[4];
            return DecompressionHelper.teeInputWithDecompression(null, /* networkPeerManager */
            requestId, responseStream, capturedOutput, contentEncoding, responseHandler);
        }
    });
    return capturedOutput;
}
Also used : ResponseHandler(com.facebook.stetho.inspector.network.ResponseHandler) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ResponseHandler (com.facebook.stetho.inspector.network.ResponseHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2