public void testCreatesTheItemShopMenu() { ItemShop building = new ItemShop(); building.stockItems(Item.BLOCKABALL, Item.HEALVIAL); JMenu menu = _constructor.createBuildingMenu(building, null); Assert.assertNotNull(menu); Assert.assertEquals(building.getName(), menu.getName()); Assert.assertEquals(building.getName(), menu.getText()); Assert.assertEquals(2, menu.getItemCount()); for (int i = 0; i < menu.getItemCount(); i++) { JMenuItem menuItem = menu.getItem(i); Action action = menuItem.getAction(); Assert.assertNotNull(action); Assert.assertEquals(ItemAction.class, action.getClass()); String name = menuItem.getName(); if (name.equals(Item.BLOCKABALL.toString())) { Assert.assertEquals(Item.BLOCKABALL.getWellFormattedString(), menuItem.getText()); } else if (name.equals(Item.HEALVIAL.toString())) { Assert.assertEquals(Item.HEALVIAL.getWellFormattedString(), menuItem.getText()); } else { Assert.fail("Name: " + name + " Text: " + menuItem.getText()); } } }
public void testCreatesTheHealingCenterMenu() { Building building = new HealingCenter(); JMenu menu = _constructor.createBuildingMenu(building, null); Assert.assertNotNull(menu); Assert.assertEquals(building.getName(), menu.getName()); Assert.assertEquals(building.getName(), menu.getText()); Assert.assertEquals(1, menu.getItemCount()); for (int i = 0; i < menu.getItemCount(); i++) { JMenuItem menuItem = menu.getItem(i); Action action = menuItem.getAction(); Assert.assertNotNull(action); Assert.assertEquals(HealAction.class, action.getClass()); Assert.assertEquals("Heal", menuItem.getName()); Assert.assertEquals("Heal", menuItem.getText()); } }
private void assertNameAndText(JMenu menu, String name, String text) { Assert.assertEquals("Name of the Menu should be " + name, name, menu.getName()); Assert.assertEquals("Text of the Menu should be " + text, text, menu.getText()); }