// I have 3 views on my adapter, name, number and photo public void testGetView_fills_list_item_view_with_data_and_executes_request() throws IOException, InterruptedException { // given; byte[] data = IOUtils.toByteArray( getInstrumentation().getContext().getResources().openRawResource(R.raw.binary)); mockWebServer.enqueue(new MockResponse().setBody(data)); mockWebServer.play(); // when View view = adapter.getView(0, null, null); adapter.await(ADAPTER_UPDATE_TIME_OUT); assertTrue(adapter.isLoadBitmapHasBeenCalled()); // then TextView nameView = (TextView) view.findViewById(R.id.user_name_textview); ImageView photoView = (ImageView) view.findViewById(R.id.thumbnail_imageview); assertNotNull("View is null. ", view); assertNotNull("Name TextView is null. ", nameView); assertNotNull("Photo ImageView is null. ", photoView); assertEquals("Names doesn't match.", data1.getFoo(), nameView.getText()); // could we get notified of this request ? assertEquals(1, mockWebServer.getRequestCount()); RecordedRequest first = mockWebServer.takeRequest(); assertEquals("GET /" + data1.getImageUrl() + " HTTP/1.1", first.getRequestLine()); InputStream cacheInputStream = new FileInputStream(cacheFile); assertTrue( IOUtils.contentEquals( cacheInputStream, getInstrumentation().getContext().getResources().openRawResource(R.raw.binary))); }
@Config(reportSdk = GINGERBREAD) @Test public void allowExpiredSetsCacheControl() throws Exception { server.enqueue(new MockResponse()); loader.load(URL, false); RecordedRequest request1 = server.takeRequest(); assertThat(request1.getHeader("Cache-Control")).isNull(); server.enqueue(new MockResponse()); loader.load(URL, true); RecordedRequest request2 = server.takeRequest(); assertThat(request2.getHeader("Cache-Control")) // .isEqualTo("only-if-cached,max-age=" + Integer.MAX_VALUE); }