Browse Source

Added back function to MenuManager.

feature-menu
Nick Stolbov 3 years ago
parent
commit
87459dab50
  1. 7
      src/main/java/Application/MenuManager.java
  2. 30
      src/test/java/Application/MenuManagerTest.java

7
src/main/java/Application/MenuManager.java

@ -14,6 +14,13 @@ public class MenuManager {
this.currentMenu = currentMenu.getMenu(i);
}
public void back() throws Exception {
if(!this.inRootMenu())
this.currentMenu = this.currentMenu.getPreviousMenu();
else
throw new Exception("Menu is a root menu, a previous menu doesn't exist");
}
public Menu getCurrentMenu(){
return this.currentMenu;
}

30
src/test/java/Application/MenuManagerTest.java

@ -1,6 +1,7 @@
package Application;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -28,7 +29,7 @@ class MenuManagerTest {
}
@Test
void testSelectFunction(){
void testSelectFunction() {
assertEquals(mm.getCurrentMenu(), rootMenu);
mm.select(0);
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0));
@ -37,9 +38,34 @@ class MenuManagerTest {
}
@Test
void testIsRootMenuFunction(){
void testIsRootMenuFunction() {
assertTrue(mm.inRootMenu());
mm.select(0);
assertFalse(mm.inRootMenu());
}
@Test
void testBackFunction() {
try {
mm.back();
Assertions.fail("Test failed: shouldn't be able to go back in rootMenu");
} catch (Exception e) {
//Should throw Exception because currently in rootMenu
}
mm.select(0);
try {
mm.back();
assertEquals(mm.getCurrentMenu(), rootMenu);
} catch (Exception e) {
Assertions.fail("Test failed: " + e.getMessage());
}
mm.select(0);
mm.select(0);
try {
mm.back();
assertEquals(mm.getCurrentMenu(), rootMenu.getMenu(0));
} catch (Exception e) {
Assertions.fail("Test failed: " + e.getMessage());
}
}
}
Loading…
Cancel
Save