use of de.westnordost.osmapi.notes.NotesDao in project StreetComplete by westnordost.
the class OsmNotesDownloadTest method testDeleteObsoleteQuests.
public void testDeleteObsoleteQuests() {
when(preferences.getBoolean(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS, false)).thenReturn(true);
// in the quest database mock, there are quests for note 4 and note 5
List<OsmNoteQuest> quests = new ArrayList<>();
Note note1 = createANote();
note1.id = 4L;
quests.add(new OsmNoteQuest(12L, note1, QuestStatus.NEW, null, new Date(), new OsmNoteQuestType(), null));
Note note2 = createANote();
note2.id = 5L;
quests.add(new OsmNoteQuest(13L, note2, QuestStatus.NEW, null, new Date(), new OsmNoteQuestType(), null));
when(noteQuestDB.getAll(any(BoundingBox.class), any(QuestStatus.class))).thenReturn(quests);
doAnswer(invocation -> {
Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
assertEquals(1, deletedQuests.size());
assertEquals(13L, (long) deletedQuests.iterator().next());
return 1;
}).when(noteQuestDB).deleteAll(any(Collection.class));
// note dao mock will only "find" the note #4
List<Note> notes = new ArrayList<>();
notes.add(note1);
NotesDao noteServer = new TestListBasedNotesDao(notes);
OsmNotesDownload dl = new OsmNotesDownload(noteServer, noteDB, noteQuestDB, createNoteDB, preferences, new OsmNoteQuestType());
VisibleQuestListener listener = mock(VisibleQuestListener.class);
dl.setQuestListener(listener);
dl.download(new BoundingBox(0, 0, 1, 1), null, 1000);
verify(noteQuestDB).deleteAll(any(Collection.class));
verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Aggregations