ArchiveQuery { public ArchivedMessages execute() throws XMLSemanticError { ArchiveFilter archiveFilter = new ArchiveFilter(archiveId, query.getX()); QuerySet querySet = query.getSet(); if (querySet.lastPage()) { long pageSize = querySet.pageSize().orElseThrow( () -> new IllegalArgumentException("Page size must be defined when requesting last page")); return archive.fetchLastPageSortedByOldestFirst(archiveFilter, pageSize); } else { return archive.fetchSortedByOldestFirst(archiveFilter, querySet); } } ArchiveQuery(MessageArchive archive, Entity archiveId, Query query); ArchivedMessages execute();  }
@Test public void executeWithoutWith() throws XMLSemanticError { when(x.getWith()).thenReturn(Optional.empty()); ArchivedMessages archivedMessages = mock(ArchivedMessages.class); when(archive.fetchSortedByOldestFirst(any(), any())).thenReturn(archivedMessages); assertEquals(archivedMessages, tested.execute()); }
@Test public void executeWithWith() throws XMLSemanticError { when(x.getWith()).thenReturn(Optional.of(JULIET)); ArchivedMessages archivedMessages = mock(ArchivedMessages.class); when(archive.fetchSortedByOldestFirst(any(), any())).thenReturn(archivedMessages); assertEquals(archivedMessages, tested.execute()); }