Search in sources :

Example 1 with ListAdapterWrapper

use of org.holoeverywhere.widget.ListAdapterWrapper in project mobile-android by photo.

the class GalleryActivityTest method testLoadsImages.

public void testLoadsImages() throws ClientProtocolException, IllegalStateException, IOException, JSONException, InterruptedException {
    // Setup mock calls and their responses
    PowerMock.reset(getApiMock());
    getApiMock().getPhotos((ReturnSizes) EasyMock.anyObject(), (Collection<String>) EasyMock.anyObject(), (String) EasyMock.anyObject(), null, (String) EasyMock.anyObject(), (Paging) EasyMock.anyObject(), null);
    PowerMock.expectLastCall().andReturn(new PhotosResponse(JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photos_get))).times(2);
    getApiMock().getPhoto((String) EasyMock.anyObject(), (ReturnSizes) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
    PowerMock.expectLastCall().andReturn(new PhotoResponse(RequestType.UNKNOWN, JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo_get))).anyTimes();
    PowerMock.replayAll();
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            getActivity().selectTab(0);
        }
    });
    getInstrumentation().waitForIdleSync();
    CountDownLatch signal = new CountDownLatch(1);
    signal.await(5, TimeUnit.SECONDS);
    // Actual test
    Solo solo = new Solo(getInstrumentation(), getActivity());
    Assert.assertTrue(solo.getCurrentListViews().size() == 1);
    ListView listView = solo.getCurrentListViews().get(0);
    Assert.assertNotNull(listView.getAdapter());
    ListAdapter adapter = listView.getAdapter();
    Assert.assertTrue(adapter instanceof ListAdapterWrapper);
    adapter = ((ListAdapterWrapper) adapter).getWrappedAdapter();
    Assert.assertTrue(adapter instanceof GalleryAdapterExt);
    GalleryAdapterExt gadapter = (GalleryAdapterExt) adapter;
    CommonUtils.debug(GalleryActivityTest.class.getSimpleName(), "start compare");
    assertEquals(2, gadapter.getSuperCount());
    // check if the mock calls were called correctly
    PowerMock.verifyAll();
}
Also used : ListView(android.widget.ListView) PhotoResponse(com.trovebox.android.common.net.PhotoResponse) Solo(com.jayway.android.robotium.solo.Solo) GalleryAdapterExt(com.trovebox.android.common.fragment.gallery.GalleryFragment.GalleryAdapterExt) PhotosResponse(com.trovebox.android.common.net.PhotosResponse) ListAdapterWrapper(org.holoeverywhere.widget.ListAdapterWrapper) CountDownLatch(java.util.concurrent.CountDownLatch) ListAdapter(android.widget.ListAdapter)

Aggregations

ListAdapter (android.widget.ListAdapter)1 ListView (android.widget.ListView)1 Solo (com.jayway.android.robotium.solo.Solo)1 GalleryAdapterExt (com.trovebox.android.common.fragment.gallery.GalleryFragment.GalleryAdapterExt)1 PhotoResponse (com.trovebox.android.common.net.PhotoResponse)1 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ListAdapterWrapper (org.holoeverywhere.widget.ListAdapterWrapper)1