use of com.google.firebase.perf.transport.TransportManager in project firebase-android-sdk by firebase.
the class InstrumentApacheHttpResponseHandlerTest method testHandleResponse.
@Test
public void testHandleResponse() throws IOException {
// mocks what an app developer would use. Need to verify that the app's response handler
// is also called
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
@Override
public String handleResponse(HttpResponse httpResponse) throws IOException {
return "testString";
}
};
TransportManager transportManager = mock(TransportManager.class);
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);
InstrumentApacheHttpResponseHandler<String> instrumentResponseHandler = new InstrumentApacheHttpResponseHandler<>(responseHandler, mockTimer(), builder);
String response = instrumentResponseHandler.handleResponse(mockHttpResponse());
// Verify that TransportManager is called with correct argument
ArgumentCaptor<NetworkRequestMetric> argument = ArgumentCaptor.forClass(NetworkRequestMetric.class);
verify(transportManager, times(1)).log(argument.capture(), ArgumentMatchers.any(ApplicationProcessState.class));
NetworkRequestMetric metric = argument.getValue();
assertThat(metric.getHttpResponseCode()).isEqualTo(200);
assertThat(metric.getTimeToResponseCompletedUs()).isEqualTo(2000);
assertThat(metric.getResponseContentType()).isEqualTo("text/html");
assertThat(metric.getResponsePayloadBytes()).isEqualTo(256);
// Verify that the app developer's response handler is also called
assertThat(response).isEqualTo("testString");
}
Aggregations