MatrixCursor extras = new MatrixCursor(new String[] { "_id", "title" }); extras.addRow(new String[] { "-1", "New Template" }); extras.addRow(new String[] { "-2", "Empty Template" }); Cursor[] cursors = { extras, cursor }; Cursor extendedCursor = new MergeCursor(cursors);
private void updateCursor(final long trackId) { MusicInfo info = mPlaylistInfo.get(trackId); if (mPlaylistInfo.get(trackId) != null) { MatrixCursor cursor = new MatrixCursor(PROJECTION); cursor.addRow(new Object[]{info.songId, info.artist, info.albumName, info.musicName , info.data, info.albumData, info.albumId, info.artistId}); cursor.moveToFirst(); mCursor = cursor; cursor.close(); } }
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { operations.add("query"); MatrixCursor cursor = new MatrixCursor(new String[] {"a"}); cursor.addRow(new Object[] {"b"}); return cursor; }
@Override public Cursor run() { MatrixCursor cursor = new MatrixCursor(new String[] { "col1" }); cursor.addRow(new Object[] { "value1" }); return cursor; } };
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { MatrixCursor result = new MatrixCursor(new String[] { KEY, VALUE }); for (Map.Entry<String, String> entry : storage.entrySet()) { result.addRow(new Object[] { entry.getKey(), entry.getValue() }); } return result; } }
@Test(expected = IllegalArgumentException.class) public void shouldDefineGetColumnNameOrThrow() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.getColumnIndexOrThrow("z"); }
@Test(expected = CursorIndexOutOfBoundsException.class) public void shouldThrowIndexOutOfBoundsExceptionWithoutData() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.getString(0); }
@Test public void testReturnsNullIfCursorIsEmpty() throws FileNotFoundException { when(harness.query.query(eq(harness.uri))).thenReturn(new MatrixCursor(new String[1])); assertNull(harness.get().open(harness.uri)); }
@Test public void testReturnsNullIfCursorHasEmptyPath() throws FileNotFoundException { MatrixCursor cursor = new MatrixCursor(new String[1]); cursor.addRow(new Object[] { "" }); when(harness.query.query(eq(harness.uri))).thenReturn(cursor); assertNull(harness.get().open(harness.uri)); }
private void setupContactProvider(String queriedAddress, String[]... contacts) { MatrixCursor cursor = new MatrixCursor(PROJECTION); for (String[] contact : contacts) { cursor.addRow(contact); } when(contentResolver .query(eq(Email.CONTENT_URI), aryEq(PROJECTION), nullable(String.class), aryEq(new String[] { queriedAddress, queriedAddress }), nullable(String.class))).thenReturn(cursor); }
private void setupQueryCryptoProvider(String queriedAddress, Address... contactAddresses) { MatrixCursor cursor = new MatrixCursor(PROJECTION_CRYPTO_ADDRESSES); for (Address contactAddress : contactAddresses) { cursor.addRow(new String[] { queriedAddress, contactAddress.toString() }); } when(contentResolver .query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")), aryEq(PROJECTION_CRYPTO_ADDRESSES), nullable(String.class), aryEq(new String[] { queriedAddress }), nullable(String.class))).thenReturn(cursor); }
@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); }
@Before public void setUp() throws Exception { singleColumnSingleNullValueMatrixCursor = new MatrixCursor(new String[]{"a"}); singleColumnSingleNullValueMatrixCursor.addRow(new Object[]{null}); singleColumnSingleNullValueMatrixCursor.moveToFirst(); }
private void setupCryptoProviderStatus(Address address, String uidStatus, String autocryptStatus) { MatrixCursor cursorCryptoStatus = new MatrixCursor(PROJECTION_CRYPTO_STATUS); cursorCryptoStatus.addRow(new String[] { address.getAddress(), uidStatus, autocryptStatus }); when(contentResolver .query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")), aryEq(PROJECTION_CRYPTO_STATUS), nullable(String.class), aryEq(new String[] { address.getAddress() }), nullable(String.class))).thenReturn(cursorCryptoStatus); }
@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); }
@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); }
@Test public void asRowsEmpty() { MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES); Query query = new CursorQuery(cursor); List<Name> names = query.asRows(Name.MAP).toList().blockingGet(); assertThat(names).isEmpty(); }
@Test(expected = CursorIndexOutOfBoundsException.class) public void shouldThrowIndexOutOfBoundsExceptionForInvalidColumnLastRow() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{"foo", 10L, 0.1f}); cursor.moveToFirst(); cursor.moveToNext(); cursor.getString(0); }
@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()); }
@Test public void asRows() { MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES); cursor.addRow(new Object[] { "Alice", "Allison" }); cursor.addRow(new Object[] { "Bob", "Bobberson" }); Query query = new CursorQuery(cursor); List<Name> names = query.asRows(Name.MAP).toList().blockingGet(); assertThat(names).containsExactly(new Name("Alice", "Allison"), new Name("Bob", "Bobberson")); }