### Question:
SpaceWalker { public void walk(Space space) { doBegin(); walkingQueue.offer(space); while (!walkingQueue.isEmpty()) { Space curSpace = walkingQueue.remove(); walkingQueue.addAll(curSpace.getSpaces()); doVisit(curSpace); } doEnd(); }  void walk(Space space);  }### Answer:
@Test public void testWalk() { Space spaceTree = space(0).addSpaces(space(1).addSpaces(space(4), space(5)), space(2).addSpaces(space(6)), space(3).addSpaces(space(7), space(8), space(9))); List<String> expectedWalkSequence = getIdList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); final List<String> idsInOrderWalked = new ArrayList<String>(); final AtomicBoolean beginRan = new AtomicBoolean(false); final AtomicBoolean endRan = new AtomicBoolean(false); SpaceWalker walker = new SpaceWalker() { @Override protected void doBegin() { assertFalse(beginRan.get()); assertFalse(endRan.get()); assertTrue(idsInOrderWalked.isEmpty()); beginRan.set(true); } @Override protected void doEnd() { assertTrue(beginRan.get()); assertFalse(endRan.get()); assertFalse(idsInOrderWalked.isEmpty()); endRan.set(true); } @Override protected void doVisit(Space space) { assertTrue(beginRan.get()); assertFalse(endRan.get()); idsInOrderWalked.add(space.getName()); } }; walker.walk(spaceTree); assertTrue(beginRan.get()); assertTrue(endRan.get()); assertEquals(expectedWalkSequence, idsInOrderWalked); }