FileDocCategorySizeDatePackage
CompositeCursorAdapterTest.javaAPI DocAndroid 5.1 API8864Thu Mar 12 22:22:48 GMT 2015com.android.common.widget

CompositeCursorAdapterTest

public class CompositeCursorAdapterTest extends android.test.AndroidTestCase
Tests for {@link CompositeCursorAdapter}. To execute, run:
adb shell am instrument -e class com.android.common.widget.CompositeCursorAdapterTest \
-w com.android.common.tests/android.test.InstrumentationTestRunner

Fields Summary
Constructors Summary
Methods Summary
private android.database.CursormakeCursor(java.lang.String name, int count)

        MatrixCursor cursor = new MatrixCursor(new String[]{name});
        for (int i = 0; i < count; i++) {
            cursor.addRow(new Object[]{i});
        }
        return cursor;
    
public voidtestAreAllItemsEnabledFalse()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, false);
        adapter.addPartition(true, true);

        assertFalse(adapter.areAllItemsEnabled());
    
public voidtestAreAllItemsEnabledTrue()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, false);
        adapter.addPartition(true, false);

        assertTrue(adapter.areAllItemsEnabled());
    
public voidtestGetCountNoEmptySections()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(false, false);
        adapter.addPartition(false, false);

        adapter.changeCursor(0, makeCursor("a", 2));
        adapter.changeCursor(1, makeCursor("b", 3));

        assertEquals(5, adapter.getCount());
    
public voidtestGetCountWithHeadersAndNoEmptySections()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(false, true);
        adapter.addPartition(false, true);

        adapter.changeCursor(0, makeCursor("a", 2));
        adapter.changeCursor(1, makeCursor("b", 3));

        assertEquals(7, adapter.getCount());
    
public voidtestGetCountWithHiddenEmptySection()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(false, true);
        adapter.addPartition(false, true);

        adapter.changeCursor(1, makeCursor("a", 2));

        assertEquals(3, adapter.getCount());
    
public voidtestGetCountWithShownEmptySection()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, true);
        adapter.addPartition(true, true);

        adapter.changeCursor(1, makeCursor("a", 2));

        assertEquals(4, adapter.getCount());
    
public voidtestGetOffsetForPosition()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, false);
        adapter.addPartition(true, true);

        adapter.changeCursor(0, makeCursor("a", 1));
        adapter.changeCursor(1, makeCursor("b", 2));

        assertEquals(0, adapter.getOffsetInPartition(0));
        assertEquals(-1, adapter.getOffsetInPartition(1));
        assertEquals(0, adapter.getOffsetInPartition(2));
        assertEquals(1, adapter.getOffsetInPartition(3));
    
public voidtestGetPartitionForPosition()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, false);
        adapter.addPartition(true, true);

        adapter.changeCursor(0, makeCursor("a", 1));
        adapter.changeCursor(1, makeCursor("b", 2));

        assertEquals(0, adapter.getPartitionForPosition(0));
        assertEquals(1, adapter.getPartitionForPosition(1));
        assertEquals(1, adapter.getPartitionForPosition(2));
        assertEquals(1, adapter.getPartitionForPosition(3));
    
public voidtestGetPositionForPartition()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, true);
        adapter.addPartition(true, true);

        adapter.changeCursor(0, makeCursor("a", 1));
        adapter.changeCursor(1, makeCursor("b", 2));

        assertEquals(0, adapter.getPositionForPartition(0));
        assertEquals(2, adapter.getPositionForPartition(1));
    
public voidtestGetViewNoEmptySections()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(false, false);
        adapter.addPartition(false, false);

        adapter.changeCursor(0, makeCursor("a", 1));
        adapter.changeCursor(1, makeCursor("b", 2));

        for (int i = 0; i < adapter.getCount(); i++) {
            adapter.getView(i, null, null);
        }

        assertEquals("0a[0] 1b[0] 1b[1]", adapter.toString());
    
public voidtestGetViewWithHeadersNoEmptySections()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(false, true);
        adapter.addPartition(false, true);

        adapter.changeCursor(0, makeCursor("a", 1));
        adapter.changeCursor(1, makeCursor("b", 2));

        for (int i = 0; i < adapter.getCount(); i++) {
            adapter.getView(i, null, null);
        }

        assertEquals("0a[H] 0a[0] 1b[H] 1b[0] 1b[1]", adapter.toString());
    
public voidtestGetViewWithHiddenEmptySections()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(false, false);
        adapter.addPartition(false, false);

        adapter.changeCursor(1, makeCursor("b", 2));

        for (int i = 0; i < adapter.getCount(); i++) {
            adapter.getView(i, null, null);
        }

        assertEquals("1b[0] 1b[1]", adapter.toString());
    
public voidtestGetViewWithShownEmptySections()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, true);
        adapter.addPartition(true, true);

        adapter.changeCursor(1, makeCursor("b", 2));

        for (int i = 0; i < adapter.getCount(); i++) {
            adapter.getView(i, null, null);
        }

        assertEquals("0[H] 1b[H] 1b[0] 1b[1]", adapter.toString());
    
public voidtestIsEnabled()

        TestCompositeCursorAdapter adapter = new TestCompositeCursorAdapter();
        adapter.addPartition(true, false);
        adapter.addPartition(true, true);

        adapter.changeCursor(0, makeCursor("a", 1));
        adapter.changeCursor(1, makeCursor("b", 2));

        assertTrue(adapter.isEnabled(0));
        assertFalse(adapter.isEnabled(1));
        assertTrue(adapter.isEnabled(2));
        assertTrue(adapter.isEnabled(3));