CreateCachedCollectionTask implements IDatabaseTask { @Override public void prepare(final IObject query) throws TaskPrepareException { try { Map<String, String> indexes = new HashMap<>(); indexes.put(keyNameField.in(query), ORDERED_INDEX); indexes.put("isActive", ORDERED_INDEX); indexes.put("startDateTime", DATE_TIME_INDEX); indexesField.out(query, indexes); createCollectionTask.prepare(query); } catch (InvalidArgumentException | ReadValueException | ChangeValueException e) { throw new TaskPrepareException("Can't prepare query for create cached collection", e); } } CreateCachedCollectionTask(final IDatabaseTask createCollectionTask); @Override void prepare(final IObject query); @Override void execute();  }
@Test public void MustCorrectPrepareQueryForCreateCollection() throws Exception { IObject startQuery = mock(IObject.class); String key = "key"; when(keyNameField.in(startQuery)).thenReturn(key); Map<String, String> indexes = new HashMap<>(); indexes.put(key, ORDERED_INDEX); indexes.put("isActive", ORDERED_INDEX); indexes.put("startDateTime", DATE_TIME_INDEX); testTask.prepare(startQuery); verify(indexesField).out(startQuery, indexes); verify(task).prepare(startQuery); }
@Test(expected = TaskPrepareException.class) public void MustIncorrectPrepareQueryForCreateCollectionWhenIOCResolveThrowException() throws Exception { IObject startQuery = mock(IObject.class); when(keyNameField.in(startQuery)).thenThrow(new ReadValueException()); testTask.prepare(startQuery); }