/** * Gets the most recent timestamp for given datatype. * @param dataType the data type * @return timestamp * @throws SecurityException if app does not hold necessary permissions */ public long getMostRecentTimestamp(DataType dataType) { return getMostRecentTimestampForQuery(queryBuilder.buildMostRecentQueryForDataType(dataType)); }
private void mockMostRecentTimestampForType(DataType type, long max) { MatrixCursor cursor = new MatrixCursor(new String[]{"date"}); cursor.addRow(new Object[] { max }); BackupQueryBuilder.Query query = mock(BackupQueryBuilder.Query.class); when(queryBuilder.buildMostRecentQueryForDataType(type)).thenReturn(query); when(resolver.query(any(Uri.class), any(String[].class), any(String.class), any(String[].class), any(String.class))).thenReturn(cursor); }
@Test public void shouldBuildMostRecentQueryForMMS() throws Exception { BackupQueryBuilder.Query query = builder.buildMostRecentQueryForDataType(MMS); assertThat(query.uri).isEqualTo(Uri.parse("content://mms")); assertThat(query.projection).asList().containsExactly("date"); assertThat(query.selection).isNull(); assertThat(query.selectionArgs).isNull(); assertThat(query.sortOrder).isEqualTo("date DESC LIMIT 1"); }
@Test public void shouldBuildMostRecentQueryForCallLog() throws Exception { BackupQueryBuilder.Query query = builder.buildMostRecentQueryForDataType(CALLLOG); assertThat(query.uri).isEqualTo(Uri.parse("content://call_log/calls")); assertThat(query.projection).asList().containsExactly("date"); assertThat(query.selection).isNull(); assertThat(query.selectionArgs).isNull(); assertThat(query.sortOrder).isEqualTo("date DESC LIMIT 1"); } }
@Test public void shouldBuildMostRecentQueryForSMS() throws Exception { BackupQueryBuilder.Query query = builder.buildMostRecentQueryForDataType(SMS); assertThat(query.uri).isEqualTo(Uri.parse("content://sms")); assertThat(query.projection).asList().containsExactly("date"); assertThat(query.selection).isEqualTo("type <> ?"); assertThat(query.selectionArgs).asList().containsExactly("3"); assertThat(query.sortOrder).isEqualTo("date DESC LIMIT 1"); }