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(); } }
@Before public void setUp() throws Exception { singleColumnSingleNullValueMatrixCursor = new MatrixCursor(new String[]{"a"}); singleColumnSingleNullValueMatrixCursor.addRow(new Object[]{null}); singleColumnSingleNullValueMatrixCursor.moveToFirst(); }
@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 shouldAllowTypeFlexibility() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{42, 3.3, 'a'}); assertTrue(cursor.moveToFirst()); assertThat(cursor.getString(0)).isEqualTo("42"); assertThat(cursor.getShort(0)).isEqualTo((short) 42); assertThat(cursor.getInt(0)).isEqualTo(42); assertThat(cursor.getLong(0)).isEqualTo(42L); assertThat(cursor.getFloat(0)).isEqualTo(42.0F); assertThat(cursor.getDouble(0)).isEqualTo(42.0); assertThat(cursor.getString(1)).isEqualTo("3.3"); assertThat(cursor.getShort(1)).isEqualTo((short) 3); assertThat(cursor.getInt(1)).isEqualTo(3); assertThat(cursor.getLong(1)).isEqualTo(3L); assertThat(cursor.getFloat(1)).isEqualTo(3.3F); assertThat(cursor.getDouble(1)).isEqualTo(3.3); assertThat(cursor.getString(2)).isEqualTo("a"); }
@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()); }
public void testCursorToTrayItem() throws Exception { final MatrixCursor matrixCursor = new MatrixCursor(new String[]{ TrayContract.Preferences.Columns.KEY, TrayContract.Preferences.Columns.VALUE, TrayContract.Preferences.Columns.MODULE, TrayContract.Preferences.Columns.CREATED, TrayContract.Preferences.Columns.UPDATED, TrayContract.Preferences.Columns.MIGRATED_KEY }); final Date created = new Date(); final Date updated = new Date(); matrixCursor.addRow(new Object[]{ "key", "value", "module", created.getTime(), updated.getTime(), "migratedKey" }); assertTrue(matrixCursor.moveToFirst()); final TrayItem item = TrayProviderHelper.cursorToTrayItem(matrixCursor); assertEquals("key", item.key()); assertEquals("value", item.value()); assertEquals("migratedKey", item.migratedKey()); assertEquals("module", item.module()); assertEquals(updated, item.updateTime()); assertEquals(created, item.created()); }
@Test public void testConvertMessagesSeenFlagUnreadWithSMS() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[] {Telephony.TextBasedSmsColumns.ADDRESS, Telephony.TextBasedSmsColumns.READ} ); cursor.addRow(new Object[]{ "foo", "0" }); cursor.addRow(new Object[]{ "foo", "1" }); cursor.moveToFirst(); PersonRecord record = mock(PersonRecord.class); when(personLookup.lookupPerson(any(String.class))).thenReturn(record); when(record.getAddress(any(AddressStyle.class))).thenReturn(new Address("foo")); when(preferences.getMarkAsReadType()).thenReturn(MarkAsReadTypes.UNREAD); messageConverter = new MessageConverter(RuntimeEnvironment.application, preferences, "foo@example.com", personLookup, contactAccessor); ConversionResult res = messageConverter.convertMessages(cursor, DataType.SMS); assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isFalse(); cursor.moveToNext(); res = messageConverter.convertMessages(cursor, DataType.SMS); assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isFalse(); }
@Test public void testConvertMessagesSeenFlagReadWithSMS() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[] {Telephony.TextBasedSmsColumns.ADDRESS, Telephony.TextBasedSmsColumns.READ} ); cursor.addRow(new Object[]{ "foo", "0" }); cursor.addRow(new Object[]{ "foo", "1" }); cursor.moveToFirst(); PersonRecord record = mock(PersonRecord.class); when(personLookup.lookupPerson(any(String.class))).thenReturn(record); when(record.getAddress(any(AddressStyle.class))).thenReturn(new Address("foo")); when(preferences.getMarkAsReadType()).thenReturn(MarkAsReadTypes.READ); messageConverter = new MessageConverter(RuntimeEnvironment.application, preferences, "foo@example.com", personLookup, contactAccessor); ConversionResult res = messageConverter.convertMessages(cursor, DataType.SMS); assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isTrue(); cursor.moveToNext(); res = messageConverter.convertMessages(cursor, DataType.SMS); assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isTrue(); }
@Test public void testConvertMessagesSeenFlagFromMessageStatusWithSMS() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[] {Telephony.TextBasedSmsColumns.ADDRESS, Telephony.TextBasedSmsColumns.READ} ); cursor.addRow(new Object[]{ "foo", "0" }); cursor.addRow(new Object[]{ "foo", "1" }); cursor.moveToFirst(); PersonRecord record = mock(PersonRecord.class); when(personLookup.lookupPerson(any(String.class))).thenReturn(record); when(record.getAddress(any(AddressStyle.class))).thenReturn(new Address("foo")); when(preferences.getMarkAsReadType()).thenReturn(MarkAsReadTypes.MESSAGE_STATUS); messageConverter = new MessageConverter(RuntimeEnvironment.application, preferences, "foo@example.com", personLookup, contactAccessor); ConversionResult res = messageConverter.convertMessages(cursor, DataType.SMS); assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isFalse(); cursor.moveToNext(); res = messageConverter.convertMessages(cursor, DataType.SMS); assertThat(res.getMessages().get(0).isSet(Flag.SEEN)).isTrue(); }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
public Cursor query(@NonNull Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) { MatrixCursor cursor = new MatrixCursor(new String[]{"string"}); try { if (getContext() == null) return cursor; final String path = paramUri.getPath().substring(1); final String[] items = getContext().getAssets().list(path); for (String s : items) { cursor.newRow().add(s); cursor.moveToNext(); } cursor.moveToFirst(); } catch (Exception e) { cursor.close(); throw new RuntimeException(e); } return cursor; }
private static MatrixCursor getRecordedProgramCursor(ContentValues contentValues) { String[] rows = RecordedProgram.PROJECTION; MatrixCursor cursor = new MatrixCursor(rows); MatrixCursor.RowBuilder builder = cursor.newRow(); for (String row : rows) { builder.add(row, contentValues.get(row)); } cursor.moveToFirst(); return cursor; } }
private static MatrixCursor getChannelCursor(ContentValues contentValues) { String[] rows = Channel.PROJECTION; MatrixCursor cursor = new MatrixCursor(rows); MatrixCursor.RowBuilder builder = cursor.newRow(); for(String row: rows) { if (row != null) { builder.add(row, contentValues.get(row)); } } cursor.moveToFirst(); return cursor; } }
private static MatrixCursor getProgramCursor(ContentValues contentValues) { String[] rows = Program.PROJECTION; MatrixCursor cursor = new MatrixCursor(rows); MatrixCursor.RowBuilder builder = cursor.newRow(); for(String row: rows) { if (row != null) { builder.add(row, contentValues.get(row)); } } cursor.moveToFirst(); return cursor; } }