### Question:
MongoStore implements ToDoStore { @Override public Collection<ToDo> getAll() { List<ToDo> todos = new ArrayList<ToDo>(); DBCursor cursor = coll.find(); while(cursor.hasNext()) { todos.add(createToDo(cursor.next())); } cursor.close(); return todos; } 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();  }### Answer:
@Test public void testGetAll() { 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); Collection<ToDo> todos = store.getAll(); List<ToDo> testToDos = new ArrayList<ToDo>(); ToDo td1 = new ToDo(); td1.setId("aaaaaaaaaaaaaaaaaaaaaaa1"); td1.setTitle("This is todo 1"); td1.setOrder(1); ToDo td2 = new ToDo(); td2.setId("aaaaaaaaaaaaaaaaaaaaaaa2"); td2.setTitle("This is todo 2"); td2.setOrder(2); testToDos.add(td1); testToDos.add(td2); assertEquals(testToDos, todos); verify(cursor); verify(coll); }