@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(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 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()); }
@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(); }
@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(); }
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; }
@Test public void testCursor() { MatrixCursor cursor = new MatrixCursor(new String[] { "id" }); for (String s : new String[] { "1", "2", "3" }) { cursor.addRow(new String[] { s }); } cursor.moveToPosition(0); assertThat(cursor.moveToPrevious(), is(true)); cursor.moveToPosition(cursor.getCount()-1); assertThat(cursor.moveToNext(), is(true)); assertThat(cursor.moveToPosition(c.getCount()), is(true)); assertThat(cursor.moveToPosition(-1), is(true)); }
if (!cursorA.isLast()) cursorA.moveToNext(); if (!cursorB.isLast()) cursorB.moveToNext(); if (!cursorA.isAfterLast()) cursorA.moveToPrevious();