@Test public void testCount() throws Exception { DBCollection coll = createMockCollection(); DBCursor cursor = createMockCursor(); expect(cursor.hasNext()).andAnswer(new IAnswer<Boolean>() { private int count = 0; @Override public Boolean answer() throws Throwable { count++; return count == 3 ? false : true; } }).anyTimes(); expect(cursor.next()).andAnswer(new IAnswer<DBObject>() { private int count = 0; @Override public DBObject answer() throws Throwable { count++; BasicDBObject dbObj = new BasicDBObject(); dbObj.put("title", "This is todo " + count); dbObj.put("completed", false); dbObj.put("order", count); dbObj.put("_id", new ObjectId("aaaaaaaaaaaaaaaaaaaaaaa" + count)); return dbObj; } }).anyTimes(); cursor.close(); expectLastCall(); replay(cursor); expect(coll.find()).andReturn(cursor); replay(coll); MongoStore store = new MongoStore(coll); assertEquals(2, store.count()); verify(cursor); verify(coll); }
@Override public int count() throws ToDoStoreException { return getAll().size(); }
MongoStore implements ToDoStore { @Override public int count() throws ToDoStoreException { return getAll().size(); } }
MongoStore implements ToDoStore { @Override public int count() throws ToDoStoreException { return getAll().size(); } MongoStore(DBCollection coll); }
MongoStore implements ToDoStore { @Override public int count() throws ToDoStoreException { return getAll().size(); } MongoStore(DBCollection coll); @Override Collection<ToDo> getAll(); @Override ToDo get(String id); @Override ToDo persist(ToDo td); @Override ToDo update(String id, ToDo td); @Override void delete(String id); @Override int count(); }
MongoStore implements ToDoStore { @Override public int count() throws ToDoStoreException { return getAll().size(); } MongoStore(DBCollection coll); @Override Collection<ToDo> getAll(); @Override ToDo get(String id); @Override ToDo persist(ToDo td); @Override ToDo update(String id, ToDo td); @Override void delete(String id); @Override int count();  }