From 7ca9c1d0024ed53c68e3de78c1bc34437b799f85 Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Thu, 13 Jan 2022 14:35:42 +0100 Subject: [PATCH] Added MenuManager class with select function with test. --- src/main/java/Application/MenuManager.java | 22 +++++++++++ .../java/Application/MenuManagerTest.java | 38 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/Application/MenuManager.java create mode 100644 src/test/java/Application/MenuManagerTest.java diff --git a/src/main/java/Application/MenuManager.java b/src/main/java/Application/MenuManager.java new file mode 100644 index 0000000..54402cc --- /dev/null +++ b/src/main/java/Application/MenuManager.java @@ -0,0 +1,22 @@ +package Application; + +public class MenuManager { + + private Menu rootMenu; + private Menu currentMenu; + + public MenuManager(Menu rootMenu){ + this.rootMenu = rootMenu; + this.currentMenu = rootMenu; + } + + public void select(int i){ + this.currentMenu = currentMenu.getMenu(i); + } + + public Menu getCurrentMenu(){ + return this.currentMenu; + } + + +} diff --git a/src/test/java/Application/MenuManagerTest.java b/src/test/java/Application/MenuManagerTest.java new file mode 100644 index 0000000..4355748 --- /dev/null +++ b/src/test/java/Application/MenuManagerTest.java @@ -0,0 +1,38 @@ +package Application; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +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); + } + + @AfterEach + void tearDown() { + } + + @Test + void testSelectFunction(){ + assertEquals(mm.getCurrentMenu(), rootMenu); + mm.select(0); + assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0)); + mm.select(0); + assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0).getMenu(0)); + } +} \ No newline at end of file