Search in sources :

Example 1 with NotesDao

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));
}
Also used : ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) Note(de.westnordost.osmapi.notes.Note) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) NotesDao(de.westnordost.osmapi.notes.NotesDao) Collection(java.util.Collection)

Aggregations

BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)1 Note (de.westnordost.osmapi.notes.Note)1 NotesDao (de.westnordost.osmapi.notes.NotesDao)1 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)1 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)1 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1