InMemoryDBUpsertTask implements IDatabaseTask { @Override public void execute() throws TaskExecutionException { try { IDatabase dataBase = IOC.resolve(Keys.getOrAdd(InMemoryDatabase.class.getCanonicalName())); dataBase.upsert(document, collectionName); } catch (ResolutionException e) { throw new TaskExecutionException("Failed to resolve InMemoryDatabase", e); } catch (IDatabaseException e) { throw new TaskExecutionException("Failed to upsert document into " + collectionName, e); } } InMemoryDBUpsertTask(); @Override void prepare(final IObject query); @Override void execute();  }
@Test public void testExecute() throws InvalidArgumentException, ChangeValueException, TaskPrepareException, TaskExecutionException, IDatabaseException { InMemoryDBUpsertTask upsertTask = new InMemoryDBUpsertTask(); IObject query = new DSObject("{\"collectionName\": \"collection_name\"}"); IObject document = new DSObject("{\"hello\": \"world\"}"); IFieldName documentFieldName = new FieldName("document"); query.setValue(documentFieldName, document); upsertTask.prepare(query); upsertTask.execute(); verify(inMemoryDatabase).upsert(document, "collection_name"); }