// Create a MatrixCursor filled with the rows you want to add. MatrixCursor matrixCursor = new MatrixCursor(new String[] { colName1, colName2 }); matrixCursor.addRow(new Object[] { value1, value2 }); // Merge your existing cursor with the matrixCursor you created. MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, cursor }); // Use your the mergeCursor as you would use your cursor.
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(); } }
public Harness() { cursor.addRow(new String[] { file.getAbsolutePath() }); when(query.query(eq(uri))).thenReturn(cursor); when(service.get(eq(file.getAbsolutePath()))).thenReturn(file); when(service.exists(eq(file))).thenReturn(true); when(service.length(eq(file))).thenReturn(1L); }
@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 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 setupNicknameContactProvider(String[]... contactsWithNickname) { MatrixCursor cursor = new MatrixCursor(PROJECTION_NICKNAME); for (String[] contact : contactsWithNickname) { cursor.addRow(contact); } when(contentResolver .query(eq(ContactsContract.Data.CONTENT_URI), aryEq(PROJECTION_NICKNAME), nullable(String.class), nullable(String[].class), 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); }
private void setupContactProviderForId(String id, 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[] { id }), 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 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")); }
@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(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 shouldAddObjectArraysAsRows() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{"foo", 10L, 0.1f}); cursor.addRow(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()); }