Browse Source

Added MenuManager class with select function with test.

feature-menu
Nick Stolbov 3 years ago
parent
commit
7ca9c1d002
  1. 22
      src/main/java/Application/MenuManager.java
  2. 38
      src/test/java/Application/MenuManagerTest.java

22
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;
}
}

38
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));
}
}
Loading…
Cancel
Save