Browse Source

Changed select method with test for MenuManager to avoid ArrayIndexOutOfBoundsException

feature-menu
Nick Stolbov 3 years ago
parent
commit
55f173324a
  1. 2
      src/main/java/Application/MenuManager.java
  2. 10
      src/test/java/Application/MenuManagerTest.java

2
src/main/java/Application/MenuManager.java

@ -23,6 +23,8 @@ public class MenuManager {
}
public void select(int i) {
if(i < 0 || i >= this.getSize())
return;
if (currentMenu == null)
this.currentMenu = menuList.get(i);
else

10
src/test/java/Application/MenuManagerTest.java

@ -29,8 +29,18 @@ class MenuManagerTest {
@Test
void select() {
assertNull(mm.getCurrentMenu());
//Negative index
mm.select(-1);
assertNull(mm.getCurrentMenu());
mm.select(0);
assertEquals(mm.getCurrentMenu().getName(), "Menu1");
//Dose nothing when index to big
mm.select(1);
assertEquals(mm.getCurrentMenu().getName(), "Menu1");
mm.select(0);
assertEquals(mm.getCurrentMenu().getName(), "Menu1.1");
mm.select(0);
assertEquals(mm.getCurrentMenu().getName(), "Menu1.1");
}

Loading…
Cancel
Save