DeleteFromCachedCollectionTask implements IDatabaseTask { @Override public void prepare(final IObject query) throws TaskPrepareException { try { isActiveField.out(query, false); updateTask = IOC.resolve( Keys.getOrAdd("db.collection.upsert"), connection, collectionNameField.in(query), documentField.in(query) ); } catch (InvalidArgumentException | ReadValueException | ChangeValueException | ResolutionException e) { throw new TaskPrepareException("Can't prepare query for delete from cached collection", e); } } DeleteFromCachedCollectionTask(final IStorageConnection connection); @Override void prepare(final IObject query); @Override void execute();  }
@Test public void ShouldCorrectPrepareObjectForDeleting() throws Exception { IObject query = mock(IObject.class); IObject doc = mock(IObject.class); when(collectionNameField.in(query)).thenReturn("collectionName"); when(documentField.in(query)).thenReturn(doc); task.prepare(query); verify(isActiveField).out(query, false); verifyStatic(); IOC.resolve( Keys.getOrAdd("db.collection.upsert"), connection, "collectionName", doc ); }
@Test(expected = TaskPrepareException.class) public void ShouldInCorrectPrepareObjectForDeletingWhenNestedExceptionIsGiven() throws Exception { IObject srcQuery = mock(IObject.class); doThrow(new ChangeValueException("")).when(isActiveField).out(srcQuery, false); task.prepare(srcQuery); }