FileDocCategorySizeDatePackage
ListEmptyViewTest.javaAPI DocAndroid 5.1 API4772Thu Mar 12 22:22:12 GMT 2015android.widget.listview

ListEmptyViewTest

public class ListEmptyViewTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private ListWithEmptyView
mActivity
private android.widget.ListView
mListView
Constructors Summary
public ListEmptyViewTest()

        super("com.android.frameworks.coretests", ListWithEmptyView.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mListView = getActivity().getListView();
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mListView);
        
        assertTrue("Empty view not shown", mListView.getVisibility() == View.GONE);
    
public voidtestZeroToManyToZero()

        Instrumentation inst = getInstrumentation();
       
        int i;

        for (i = 0; i < 10; i++) {
            inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
            inst.waitForIdleSync();
            assertTrue("Empty view still shown",
                    mActivity.getEmptyView().getVisibility() == View.GONE);
            assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
        }

        for (i = 0; i < 10; i++) {
            inst.invokeMenuActionSync(mActivity, mActivity.MENU_REMOVE, 0);
            inst.waitForIdleSync();
            if (i < 9) {
                assertTrue("Empty view still shown",
                        mActivity.getEmptyView().getVisibility() == View.GONE);
                assertTrue("List not shown",
                        mActivity.getListView().getVisibility() == View.VISIBLE);
            } else {
                assertTrue("Empty view not shown",
                        mActivity.getEmptyView().getVisibility() == View.VISIBLE);
                assertTrue("List still shown",
                        mActivity.getListView().getVisibility() == View.GONE);
            }
        }
        
        // Navigate forward
        Intent intent = new Intent();
        intent.setClass(mActivity, ListWithEmptyView.class);
        mActivity.startActivity(intent);
        
        // Navigate backward
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
        assertTrue("Empty view not shown", mActivity.getEmptyView().getVisibility() == View.VISIBLE);
        assertTrue("List still shown", mActivity.getListView().getVisibility() == View.GONE);
    
public voidtestZeroToOne()

        Instrumentation inst = getInstrumentation();
       
        inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
        inst.waitForIdleSync();
        assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
        assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
    
public voidtestZeroToOneForwardBack()

        Instrumentation inst = getInstrumentation();
       
        inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
        inst.waitForIdleSync();
        assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
        assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
        
        // Navigate forward
        Intent intent = new Intent();
        intent.setClass(mActivity, ListWithEmptyView.class);
        mActivity.startActivity(intent);
        
        // Navigate backward
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
        assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
        assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);