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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations