@Test public void shouldRecordExtendedRequestData() throws Exception { Robolectric.addPendingHttpResponse(200, "a happy response body"); HttpGet httpGet = new HttpGet("http://example.com"); requestDirector.execute(null, httpGet, null); assertSame(Robolectric.getSentHttpRequestInfo(0).getHttpRequest(), httpGet); ConnectionKeepAliveStrategy strategy = shadowOf( (DefaultRequestDirector) Robolectric.getSentHttpRequestInfo(0).getRequestDirector()) .getConnectionKeepAliveStrategy(); assertSame(strategy, connectionKeepAliveStrategy); }
@Test public void testAsyncTasks() { Robolectric.getBackgroundScheduler().pause(); TestRequest request = new TestRequest(); api.makeCall(request, responseCallbacks); // setting pending http response Robolectric.addPendingHttpResponse(200, "Test Response"); // executing task Robolectric.getBackgroundScheduler().runOneTask(); HttpRequestInfo sentHttpRequestData = Robolectric.getSentHttpRequestInfo(0); HttpRequest sentHttpRequest = sentHttpRequestData.getHttpRequest(); // Testing URL assertThat(sentHttpRequest.getRequestLine().getUri(), equalTo("www.disney.com")); // Testing Headers assertThat(sentHttpRequest.getHeaders("mickey")[0].getValue(), equalTo("mouse")); }