|
|
@ -10,18 +10,16 @@ import static org.junit.jupiter.api.Assertions.*; |
|
|
|
class MenuManagerTest { |
|
|
|
|
|
|
|
MenuManager mm; |
|
|
|
Menu rootMenu; |
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
void setUp() { |
|
|
|
rootMenu = new Menu("Root"); |
|
|
|
Menu menu1 = new Menu("Menu1"); |
|
|
|
Menu menu2 = new Menu("Menu2"); |
|
|
|
Menu menu1_1 = new Menu("Menu1.1"); |
|
|
|
menu1.addMenu(menu1_1); |
|
|
|
rootMenu.addMenu(menu1); |
|
|
|
rootMenu.addMenu(menu2); |
|
|
|
mm = new MenuManager(rootMenu); |
|
|
|
mm = new MenuManager(); |
|
|
|
mm.addMenu(menu1); |
|
|
|
mm.addMenu(menu2); |
|
|
|
} |
|
|
|
|
|
|
|
@AfterEach |
|
|
@ -29,23 +27,33 @@ class MenuManagerTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testSelectFunction() { |
|
|
|
assertEquals(mm.getCurrentMenu(), rootMenu); |
|
|
|
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(), rootMenu.getMenu(0)); |
|
|
|
assertEquals(mm.getCurrentMenu().getName(), "Menu1.1"); |
|
|
|
mm.select(0); |
|
|
|
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0).getMenu(0)); |
|
|
|
assertEquals(mm.getCurrentMenu().getName(), "Menu1.1"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testIsRootMenuFunction() { |
|
|
|
void inRootMenu() { |
|
|
|
assertTrue(mm.inRootMenu()); |
|
|
|
mm.select(0); |
|
|
|
assertFalse(mm.inRootMenu()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testBackFunction() { |
|
|
|
void back() { |
|
|
|
try { |
|
|
|
mm.back(); |
|
|
|
Assertions.fail("Test failed: shouldn't be able to go back in rootMenu"); |
|
|
@ -55,7 +63,7 @@ class MenuManagerTest { |
|
|
|
mm.select(0); |
|
|
|
try { |
|
|
|
mm.back(); |
|
|
|
assertEquals(mm.getCurrentMenu(), rootMenu); |
|
|
|
assertTrue(mm.inRootMenu()); |
|
|
|
} catch (Exception e) { |
|
|
|
Assertions.fail("Test failed: " + e.getMessage()); |
|
|
|
} |
|
|
@ -63,9 +71,25 @@ class MenuManagerTest { |
|
|
|
mm.select(0); |
|
|
|
try { |
|
|
|
mm.back(); |
|
|
|
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0)); |
|
|
|
assertEquals(mm.getCurrentMenu().getName(), "Menu1"); |
|
|
|
} catch (Exception e) { |
|
|
|
Assertions.fail("Test failed: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void getFormattedMenuList(){ |
|
|
|
assertEquals(mm.getFormattedMenuList(), "1: Menu1\n2: Menu2\n"); |
|
|
|
mm.select(0); |
|
|
|
assertEquals(mm.getFormattedMenuList(), "1: Menu1.1\n"); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void getSize() { |
|
|
|
assertEquals(mm.getSize(), 2); |
|
|
|
mm.select(0); |
|
|
|
assertEquals(mm.getSize(), 1); |
|
|
|
mm.select(0); |
|
|
|
assertEquals(mm.getSize(), 0); |
|
|
|
} |
|
|
|
} |