MoreThanImmediateNeighbours { public void allUnresolvedIssues(IssueHandler handler) throws Failure { TicketManager ticketManager = connections.getTicketManager(); ticketManager.lock(); try { IssueManager issueManager = ticketManager.getIssueManager(); Iterator<Issue> issues = issueManager.allIssuesIterator(); while (issues.hasNext()) { Issue issue = issues.next(); if (issue.isUnresolved()) { handler.accept(issue); } } } finally { ticketManager.unlock(); } } MoreThanImmediateNeighbours(Connections connections); void allUnresolvedIssues(IssueHandler handler);  }
@Test public void filtersUnresolvedIssuesFromIssueManager() throws Failure { final ArrayList<Issue> allIssues = new ArrayList<Issue>() {{ add(issue1Unresolved); add(issue2); add(issue3Unresolved); }}; final States locking = context.states("locking").startsAs("unlocked"); context.checking(new Expectations() {{ allowing(connections).getTicketManager(); will(returnValue(ticketManager)); oneOf(ticketManager).lock(); then(locking.is("locked")); oneOf(ticketManager).getIssueManager(); when(locking.is("locked")); will(returnValue(issueManager)); oneOf(issueManager).allIssuesIterator(); when(locking.is("locked")); will(returnValue(allIssues.iterator())); oneOf(issueHandler).accept(issue1Unresolved); when(locking.is("locked")); oneOf(issueHandler).accept(issue3Unresolved); when(locking.is("locked")); oneOf(ticketManager).unlock(); when(locking.is("locked")); then(locking.is("unlocked")); }}); moreThanImmediateNeighbours.allUnresolvedIssues(issueHandler); }