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 testCreatesBlockamonMenuCorrectly() { Blockamon blockamon = new Blockamon(ElementType.BUG); _player.addToParty(blockamon); JMenu menu = _constructor.createBlockamonMenu(); assertNameAndText(menu, "Blockamon", "Blockamon"); assertEquals("Number of menu items was not correct", 2, menu.getItemCount()); JMenuItem blockamonMenuItem = menu.getItem(0); assertNameAndText( blockamonMenuItem, blockamon.elementType() + "0", blockamon.name() + ", " + blockamon.level() + ", " + blockamon.currentHp() + "/" + blockamon.maxHp()); assertNotNull("Blockamon menu action not set", blockamonMenuItem.getAction()); assertEquals(BlockamonAction.class, blockamonMenuItem.getAction().getClass()); JMenuItem backItemMenu = menu.getItem(1); assertNotNull("Back item menu was not added", backItemMenu); assertEquals("Back item text was not right", "Back", backItemMenu.getText()); assertNotNull("Back action was not set", backItemMenu.getAction()); assertEquals(BackAction.class, backItemMenu.getAction().getClass()); }
public void testCreatesItemMenuWithItemsCorrectly() { _player.addItem(Item.BLOCKABALL); _player.addItem(Item.HEALVIAL); JMenu menu = _constructor.createItemMenu(); assertNameAndText(menu, "Items", "Items"); assertEquals("Number of menus was not correct", 3, menu.getItemCount()); assertAllItemsHaveNames(menu); JMenuItem blockaballItemMenu = getWithName(menu, "BLOCKABALL"); assertNotNull("Blockaball item menu was not added", blockaballItemMenu); assertEquals("Blockaball text was not right", "Blockaball", blockaballItemMenu.getText()); assertNotNull("Blockaball action was not set", blockaballItemMenu.getAction()); assertEquals(ItemAction.class, blockaballItemMenu.getAction().getClass()); JMenuItem healVialItemMenu = getWithName(menu, "HEALVIAL"); assertNotNull("HealVial item menu was not added", healVialItemMenu); assertEquals("HealVial text was not right", "Heal Vial", healVialItemMenu.getText()); assertNotNull("HealVial action was not set", healVialItemMenu.getAction()); assertEquals(ItemAction.class, healVialItemMenu.getAction().getClass()); JMenuItem backItemMenu = getWithName(menu, "Back"); assertNotNull("Back item menu was not added", backItemMenu); assertEquals("Back item text was not right", "Back", backItemMenu.getText()); assertNotNull("Back action was not set", backItemMenu.getAction()); assertEquals(BackAction.class, backItemMenu.getAction().getClass()); }
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()); } }
public void testCreatesItemMenuWithNoItemsCorrectly() { JMenu menu = _constructor.createItemMenu(); assertNameAndText(menu, "Items", "Items"); assertEquals("Number of menus was not correct", 1, menu.getItemCount()); JMenuItem backButton = menu.getItem(0); assertNameAndText(backButton, "Back", "Back"); assertNotNull("Back button was not added", backButton); assertNotNull("Back button action was not set", backButton.getAction()); assertEquals(BackAction.class, backButton.getAction().getClass()); }
public void testCreatesBattleMenu() { JMenu menu = _constructor.createBattleMenu(); assertNameAndText(menu, "Battle", "Actions"); Assert.assertEquals(4, menu.getItemCount()); assertNameAndText(menu.getItem(0), "Attack", "Attack"); assertNameAndText(menu.getItem(1), "Bag", "Bag"); assertNameAndText(menu.getItem(2), "Blockamon", "Blockamon"); assertNameAndText(menu.getItem(3), "Flee", "Flee"); }
public void testCreatesOutOfBattleMenu() { JMenu menu = _constructor.createOutOfBattleMenu(); assertNameAndText(menu, "OutOfBattle", "Actions"); Assert.assertEquals(5, menu.getItemCount()); assertNameAndText(menu.getItem(0), "Blockamon", "Blockamon"); assertNameAndText(menu.getItem(1), "Bag", "Bag"); assertNameAndText(menu.getItem(2), "Money", "Money"); JMenuItem saveMenuItem = menu.getItem(3); Action saveMenuAction = saveMenuItem.getAction(); Assert.assertNotNull(saveMenuAction); Assert.assertEquals(saveMenuAction.getClass(), SaveAction.class); assertNameAndText(saveMenuItem, "Save", "Save"); assertNameAndText(menu.getItem(4), "Load", "Load"); }
private JMenuItem getWithName(JMenu menu, String name) { int numOfItems = menu.getItemCount(); JMenuItem menuItem = null; for (int i = 0; i < numOfItems; i++) { JMenuItem item = menu.getItem(i); if (item == null) { continue; } if (item.getName() == null) { continue; } if (item.getName().equals(name)) { menuItem = item; i = numOfItems; } } return menuItem; }
private void assertAllItemsHaveNames(JMenu menu) { for (int i = 0; i < menu.getItemCount(); i++) { assertNotNull("Item at position " + i + " did not have a name", menu.getItem(i).getName()); } }