InMemoryDBCountTask implements IDatabaseTask { @Override public void execute() throws TaskExecutionException { try { IDatabase dataBase = IOC.resolve(Keys.getOrAdd(InMemoryDatabase.class.getCanonicalName())); Long result = dataBase.count(criteria, collection); callback.execute(result); } catch (ResolutionException e) { throw new TaskExecutionException("Failed to resolve InMemoryDatabase", e); } catch (Exception e) { try { throw new TaskExecutionException("Count failed: criteria = " + criteria.serialize(), e); } catch (SerializeException | NullPointerException e1) { throw new TaskExecutionException("Count failed", e); } } } InMemoryDBCountTask(); @Override void prepare(final IObject query); @Override void execute();  }
@Test public void testExecute() throws InvalidArgumentException, ChangeValueException, TaskPrepareException, TaskExecutionException, IDatabaseException, ActionExecuteException { InMemoryDBCountTask selectTask = new InMemoryDBCountTask(); IObject query = new DSObject("{\"collectionName\": \"collection_name\"}"); IObject criteria = new DSObject("{\"hello\": \"world\"}"); IAction<Long> callback = mock(IAction.class); IFieldName criteriaFieldName = new FieldName("criteria"); IFieldName callbackFieldName = new FieldName("callback"); query.setValue(criteriaFieldName, criteria); query.setValue(callbackFieldName, callback); selectTask.prepare(query); selectTask.execute(); verify(inMemoryDatabase).count(criteria, "collection_name"); verify(callback).execute(any(Long.class)); }