@Test public void only_visible_items_can_be_spoken_to() { Item visibleItem = mock(Item.class); when(visibleItem.canTalkTo()).thenReturn(true); when(visibleItem.visible()).thenReturn(true); Item notVisibleItem = mock(Item.class); when(notVisibleItem.canTalkTo()).thenReturn(true); when(notVisibleItem.visible()).thenReturn(false); TalkToAction talkToAction = mock(TalkToAction.class); ActionFactory actionFactory = mock(ActionFactory.class); when(actionFactory.createTalkToAction(visibleItem)).thenReturn(talkToAction); Location l = new Location("", "", null, actionFactory); l.addItem(visibleItem); l.addItem(notVisibleItem); assertThat(l.actions(), hasItem(talkToAction)); verify(actionFactory, never()).createTalkToAction(notVisibleItem); }
@Test public void actions_uses_action_factory_to_create_TalkTo_action_for_all_canTalkTo_items() { Item talkableItem = mock(Item.class); when(talkableItem.canTalkTo()).thenReturn(true); when(talkableItem.visible()).thenReturn(true); Item notTalkPhraseSourceItem = mock(Item.class); when(notTalkPhraseSourceItem.canTalkTo()).thenReturn(false); when(notTalkPhraseSourceItem.visible()).thenReturn(true); TalkToAction talkToAction = mock(TalkToAction.class); ActionFactory actionFactory = mock(ActionFactory.class); when(actionFactory.createTalkToAction(talkableItem)).thenReturn(talkToAction); Location l = new Location("", "", null, actionFactory); l.addItem(talkableItem); l.addItem(notTalkPhraseSourceItem); assertThat(l.actions(), hasItem(talkToAction)); verify(actionFactory, never()).createTalkToAction(notTalkPhraseSourceItem); }