BackupQueryBuilder { public @Nullable Query buildMostRecentQueryForDataType(DataType type) { switch (type) { case MMS: return new Query( Consts.MMS_PROVIDER, new String[] {Telephony.BaseMmsColumns.DATE }, null, null, Telephony.BaseMmsColumns.DATE + DESC_LIMIT_1); case SMS: return new Query( Consts.SMS_PROVIDER, new String[]{Telephony.TextBasedSmsColumns.DATE}, Telephony.TextBasedSmsColumns.TYPE + " <> ?", new String[]{String.valueOf(Telephony.TextBasedSmsColumns.MESSAGE_TYPE_DRAFT)}, Telephony.TextBasedSmsColumns.DATE + DESC_LIMIT_1); case CALLLOG: return new Query( Consts.CALLLOG_PROVIDER, new String[]{CallLog.Calls.DATE}, null, null, CallLog.Calls.DATE + DESC_LIMIT_1); default: return null; } } BackupQueryBuilder(DataTypePreferences preferences); @Nullable Query buildQueryForDataType(DataType type, @Nullable ContactGroupIds groupIds, int max); @Nullable Query buildMostRecentQueryForDataType(DataType type);  }
@Test public void shouldBuildMostRecentQueryForSMS() throws Exception { BackupQueryBuilder.Query query = builder.buildMostRecentQueryForDataType(SMS); assertThat(query.uri).isEqualTo(Uri.parse("content: 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"); }
@Test public void shouldBuildMostRecentQueryForMMS() throws Exception { BackupQueryBuilder.Query query = builder.buildMostRecentQueryForDataType(MMS); assertThat(query.uri).isEqualTo(Uri.parse("content: 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: assertThat(query.projection).asList().containsExactly("date"); assertThat(query.selection).isNull(); assertThat(query.selectionArgs).isNull(); assertThat(query.sortOrder).isEqualTo("date DESC LIMIT 1"); }