Search in sources :

Example 26 with MatrixCursor

use of android.database.MatrixCursor in project robolectric by robolectric.

the class ShadowMatrixCursorTest method shouldDefineColumnNames.

@Test
public void shouldDefineColumnNames() throws Exception {
    MatrixCursor cursor = new MatrixCursor(new String[] { "a", "b", "c" });
    assertThat(cursor.getColumnCount()).isEqualTo(3);
    assertThat(cursor.getColumnName(0)).isEqualTo("a");
    assertThat(cursor.getColumnName(1)).isEqualTo("b");
    assertThat(cursor.getColumnName(2)).isEqualTo("c");
    assertThat(cursor.getColumnNames()).isEqualTo(new String[] { "a", "b", "c" });
    assertThat(cursor.getColumnIndex("b")).isEqualTo(1);
    assertThat(cursor.getColumnIndex("z")).isEqualTo(-1);
}
Also used : MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Example 27 with MatrixCursor

use of android.database.MatrixCursor in project robolectric by robolectric.

the class ShadowMatrixCursorTest method shouldAddIterablesAsRows.

@Test
public void shouldAddIterablesAsRows() throws Exception {
    MatrixCursor cursor = new MatrixCursor(new String[] { "a", "b", "c" });
    cursor.addRow(Arrays.asList(new Object[] { "foo", 10L, 0.1f }));
    cursor.addRow(Arrays.asList(new Object[] { "baz", 20L, null }));
    assertThat(cursor.getCount()).isEqualTo(2);
    assertTrue(cursor.moveToFirst());
    assertThat(cursor.getString(0)).isEqualTo("foo");
    assertThat(cursor.getLong(1)).isEqualTo(10L);
    assertThat(cursor.getFloat(2)).isEqualTo(0.1f);
    assertTrue(cursor.moveToNext());
    assertThat(cursor.getString(0)).isEqualTo("baz");
    assertThat(cursor.getLong(1)).isEqualTo(20L);
    assertTrue(cursor.isNull(2));
    assertFalse(cursor.moveToNext());
}
Also used : MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Example 28 with MatrixCursor

use of android.database.MatrixCursor in project robolectric by robolectric.

the class ShadowMatrixCursorTest method shouldThrowIndexOutOfBoundsExceptionWithoutData.

@Test(expected = CursorIndexOutOfBoundsException.class)
public void shouldThrowIndexOutOfBoundsExceptionWithoutData() throws Exception {
    MatrixCursor cursor = new MatrixCursor(new String[] { "a", "b", "c" });
    cursor.getString(0);
}
Also used : MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Example 29 with MatrixCursor

use of android.database.MatrixCursor in project robolectric by robolectric.

the class ShadowMatrixCursorTest method shouldThrowIndexOutOfBoundsExceptionForInvalidColumn.

@Test(expected = CursorIndexOutOfBoundsException.class)
public void shouldThrowIndexOutOfBoundsExceptionForInvalidColumn() throws Exception {
    MatrixCursor cursor = new MatrixCursor(new String[] { "a", "b", "c" });
    cursor.addRow(new Object[] { "foo", 10L, 0.1f });
    cursor.getString(3);
}
Also used : MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Example 30 with MatrixCursor

use of android.database.MatrixCursor in project robolectric by robolectric.

the class ShadowMatrixCursorTest method shouldDefineGetBlob.

@Test
public void shouldDefineGetBlob() throws Exception {
    byte[] blob = { 1, 2, 3, 4 };
    MatrixCursor cursor = new MatrixCursor(new String[] { "a" });
    cursor.addRow(new Object[] { blob });
    assertTrue(cursor.moveToFirst());
    assertThat(cursor.getBlob(0)).isEqualTo(blob);
}
Also used : MatrixCursor(android.database.MatrixCursor) Test(org.junit.Test)

Aggregations

MatrixCursor (android.database.MatrixCursor)259 Cursor (android.database.Cursor)37 DirectoryResult (com.android.documentsui.DirectoryResult)35 RowBuilder (android.database.MatrixCursor.RowBuilder)30 File (java.io.File)30 MergeCursor (android.database.MergeCursor)18 Uri (android.net.Uri)18 Test (org.junit.Test)17 Setting (com.android.providers.settings.SettingsState.Setting)15 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)10 BitSet (java.util.BitSet)10 Random (java.util.Random)10 IOException (java.io.IOException)7 LinkedList (java.util.LinkedList)7 ContentValues (android.content.ContentValues)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)5