### Question:
TaskFinder { public IItem find(final APIID taskId) { try { return journal.get(taskId); } catch (final APIItemNotFoundException e) { final Map<String, String> filters = new HashMap<String, String>(); filters.put(ArchivedActivityItem.ATTRIBUTE_SOURCE_OBJECT_ID, taskId.toString()); final ItemSearchResult<ArchivedTaskItem> result = archives.search(0, 1, null, ArchivedActivityItem.ATTRIBUTE_ARCHIVED_DATE + " " + Order.DESC, filters); if (result.getResults().isEmpty()) { throw new APIItemNotFoundException(ArchivedTaskDefinition.TOKEN, taskId); } return result.getResults().get(0); } } TaskFinder(final DatastoreHasGet<TaskItem> journal, final DatastoreHasSearch<ArchivedTaskItem> archives); IItem find(final APIID taskId);  }### Answer:
@Test public void should_return_task_from_the_journal_when_it_belong_to_the_journal() throws Exception { final TaskItem task = new TaskItem(); task.setId(id); when(journal.get(id)).thenReturn(task); final IItem item = taskFinder.find(id); assertThat(item.getId()).isEqualTo(task.getId()); }
@Test public void should_return_task_from_the_archives_when_not_found_in_the_journal() throws Exception { final ArchivedTaskItem task = new ArchivedTaskItem(); task.setId(id); when(journal.get(id)).thenThrow(new APIItemNotFoundException("type", id)); final Map<String, String> filters = new HashMap<String, String>(); filters.put(ArchivedActivityInstanceSearchDescriptor.SOURCE_OBJECT_ID, id.toString()); final ItemSearchResult<ArchivedTaskItem> result = mock(ItemSearchResult.class); when(result.getResults()).thenReturn(Arrays.asList(task)); when(archives.search(0, 1, null, ArchivedActivityItem.ATTRIBUTE_ARCHIVED_DATE + " " + Order.DESC, filters)).thenReturn(result); final IItem item = taskFinder.find(id); assertThat(item.getId()).isEqualTo(task.getId()); }
@Test(expected = APIItemNotFoundException.class) public void should_throw_an_exception_when_the_task_does_not_exist() throws Exception { when(journal.get(id)).thenThrow(new APIItemNotFoundException("type", id)); final Map<String, String> filters = new HashMap<String, String>(); filters.put(ArchivedActivityInstanceSearchDescriptor.SOURCE_OBJECT_ID, id.toString()); when(archives.search(0, 1, null, ArchivedActivityItem.ATTRIBUTE_ARCHIVED_DATE + " " + Order.DESC, filters)).thenThrow(new APIItemNotFoundException("type", id)); taskFinder.find(id); }