AuctionSearcher { public void searchFor(Set<String> keywords) { for (Auction auction : auctions) { announceIfAuctionMatches(auction, keywords); } searchListener.searchFinished(); } AuctionSearcher(AuctionSearchListener searchListener, Collection<Auction> auctions); void searchFor(Set<String> keywords);  }
@Test public void announcesMatchForTwoAuctions_Sequence() { final AuctionSearcher auctionSearch = new AuctionSearcher(searchListener, asList(STUB_AUCTION1, STUB_AUCTION2)); context.checking(new Expectations() {{ Sequence events = context.sequence("events"); oneOf(searchListener).searchMatched(STUB_AUCTION1); inSequence(events); oneOf(searchListener).searchMatched(STUB_AUCTION2); inSequence(events); oneOf(searchListener).searchFinished(); inSequence(events); }}); auctionSearch.searchFor(KEYWORDS); }
@Test public void announcesMatchForTwoAuctions_States() { final AuctionSearcher auctionSearch = new AuctionSearcher(searchListener, asList(STUB_AUCTION1, STUB_AUCTION2)); context.checking(new Expectations() {{ States searching = context.states("searching"); oneOf(searchListener).searchMatched(STUB_AUCTION1); when(searching.isNot("finished")); oneOf(searchListener).searchMatched(STUB_AUCTION2); when(searching.isNot("finished")); oneOf(searchListener).searchFinished(); then(searching.is("finished")); }}); auctionSearch.searchFor(KEYWORDS); }
@Test public void announcesMatchForOneAuction_NoOrdering() { final AuctionSearcher auctionSearch = new AuctionSearcher(searchListener, asList(STUB_AUCTION1)); context.checking(new Expectations() {{ oneOf(searchListener).searchMatched(STUB_AUCTION1); oneOf(searchListener).searchFinished(); }}); auctionSearch.searchFor(KEYWORDS); }
@Test public void announcesMatchForOneAuction_Sequence() { final AuctionSearcher auctionSearch = new AuctionSearcher(searchListener, asList(STUB_AUCTION1)); context.checking(new Expectations() {{ Sequence events = context.sequence("events"); oneOf(searchListener).searchMatched(STUB_AUCTION1); inSequence(events); oneOf(searchListener).searchFinished(); inSequence(events); }}); auctionSearch.searchFor(KEYWORDS); }