|
@ -10,18 +10,16 @@ import static org.junit.jupiter.api.Assertions.*; |
|
|
class MenuManagerTest { |
|
|
class MenuManagerTest { |
|
|
|
|
|
|
|
|
MenuManager mm; |
|
|
MenuManager mm; |
|
|
Menu rootMenu; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
@BeforeEach |
|
|
void setUp() { |
|
|
void setUp() { |
|
|
rootMenu = new Menu("Root"); |
|
|
|
|
|
Menu menu1 = new Menu("Menu1"); |
|
|
Menu menu1 = new Menu("Menu1"); |
|
|
Menu menu2 = new Menu("Menu2"); |
|
|
Menu menu2 = new Menu("Menu2"); |
|
|
Menu menu1_1 = new Menu("Menu1.1"); |
|
|
Menu menu1_1 = new Menu("Menu1.1"); |
|
|
menu1.addMenu(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 |
|
|
@AfterEach |
|
@ -30,11 +28,11 @@ class MenuManagerTest { |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void testSelectFunction() { |
|
|
void testSelectFunction() { |
|
|
assertEquals(mm.getCurrentMenu(), rootMenu); |
|
|
|
|
|
|
|
|
assertNull(mm.getCurrentMenu()); |
|
|
mm.select(0); |
|
|
mm.select(0); |
|
|
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0)); |
|
|
|
|
|
|
|
|
assertEquals(mm.getCurrentMenu().getName(), "Menu1"); |
|
|
mm.select(0); |
|
|
mm.select(0); |
|
|
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0).getMenu(0)); |
|
|
|
|
|
|
|
|
assertEquals(mm.getCurrentMenu().getName(), "Menu1.1"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
@ -55,7 +53,7 @@ class MenuManagerTest { |
|
|
mm.select(0); |
|
|
mm.select(0); |
|
|
try { |
|
|
try { |
|
|
mm.back(); |
|
|
mm.back(); |
|
|
assertEquals(mm.getCurrentMenu(), rootMenu); |
|
|
|
|
|
|
|
|
assertTrue(mm.inRootMenu()); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
Assertions.fail("Test failed: " + e.getMessage()); |
|
|
Assertions.fail("Test failed: " + e.getMessage()); |
|
|
} |
|
|
} |
|
@ -63,7 +61,7 @@ class MenuManagerTest { |
|
|
mm.select(0); |
|
|
mm.select(0); |
|
|
try { |
|
|
try { |
|
|
mm.back(); |
|
|
mm.back(); |
|
|
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0)); |
|
|
|
|
|
|
|
|
assertEquals(mm.getCurrentMenu().getName(), "Menu1"); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
Assertions.fail("Test failed: " + e.getMessage()); |
|
|
Assertions.fail("Test failed: " + e.getMessage()); |
|
|
} |
|
|
} |
|
|