@Test public void available_items_text_includes_only_visible_items() { final Item visibleItem = mockery.mock(Item.class, "visible item"); final Item invisibleItem = mockery.mock(Item.class, "invisible item"); mockery.checking( new Expectations() { { allowing(visibleItem).visible(); will(returnValue(true)); allowing(visibleItem).countableNounPrefix(); will(returnValue("a")); allowing(visibleItem).midSentenceCasedName(); will(returnValue("visible item")); ignoring(visibleItem); allowing(invisibleItem).visible(); will(returnValue(false)); allowing(invisibleItem).midSentenceCasedName(); will(returnValue("invisible item")); ignoring(invisibleItem); } }); Location l = new Location("", "Location description.", null, null); l.addItem(visibleItem); l.addItem(invisibleItem); assertEquals("There is a visible item here.\n", l.availableItemsText()); }
@Test public void names_without_a_countable_noun_prefix_have_no_prefix_added() { Location l = new Location("", "Location description.", null, null); Item item = makeMockItem("Elvis"); when(item.countableNounPrefix()).thenReturn(""); l.addItem(item); assertThat(l.availableItemsText(), containsString("is Elvis here")); }
@Test public void added_items_are_added_to_available_items_text() { Location l = new Location("", "Location description.", null, null); l.addItem(makeMockItem("name")); l.addItem(makeMockItem("name2")); l.addItem(makeMockItem("name3")); assertEquals("There is a name, a name2 and a name3 here.\n", l.availableItemsText()); }
@Test public void when_first_item_in_list_plural_use_There_are() { Location l = new Location("", "Location description.", null, null); Item item1 = makeMockItem("names"); when(item1.countableNounPrefix()).thenReturn("some"); when(item1.plural()).thenReturn(true); l.addItem(item1); l.addItem(makeMockItem("name2")); assertEquals("There are some names and a name2 here.\n", l.availableItemsText()); }
@Test public void item_must_be_visible_to_effect_choice_of_There_are() { Location l = new Location("", "Location description.", null, null); Item invisibleSingularItem = makeMockItem("invisible singular item"); when(invisibleSingularItem.visible()).thenReturn(false); when(invisibleSingularItem.plural()).thenReturn(false); l.addItem(invisibleSingularItem); Item pluralItem = makeMockItem("plural items"); when(pluralItem.countableNounPrefix()).thenReturn("some"); when(pluralItem.visible()).thenReturn(true); when(pluralItem.plural()).thenReturn(true); l.addItem(pluralItem); assertThat(l.availableItemsText(), containsString("There are ")); }
@Test public void available_items_text_is_empty_on_construction() { Location l = new Location("", "", null, null); assertEquals("", l.availableItemsText()); }