MoreThanImmediateNeighbours2 { public void allUnresolvedIssues(IssueHandler handler) throws Failure { TicketManager ticketManager = connections.getTicketManager(); ticketManager.lock(); try { retrieveUnresolvedIssues(ticketManager.getIssueManager(), handler); } finally { ticketManager.unlock(); } } MoreThanImmediateNeighbours2(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)); allowing(issueManager).allIssuesIterator(); will(returnIterator(allIssues)); oneOf(ticketManager).lock(); when(locking.is("unlocked")); then(locking.is("locked")); oneOf(ticketManager).getIssueManager(); when(locking.is("locked")); will(returnValue(issueManager)); 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); }