Browse Source

Added subMenu function for class Menu with test

feature-menu
Nick Stolbov 3 years ago
parent
commit
647eb68fef
  1. 12
      src/main/java/Application/Menu.java
  2. 14
      src/test/java/Application/MenuTest.java

12
src/main/java/Application/Menu.java

@ -1,11 +1,19 @@
package Application; package Application;
import java.util.ArrayList;
public class Menu { public class Menu {
private String name; private String name;
private ArrayList<Menu> subMenuList;
public Menu(String name){ public Menu(String name){
setName(name); setName(name);
subMenuList = new ArrayList<>();
}
public void addMenu(Menu menu){
subMenuList.add(menu);
} }
public String getName() { public String getName() {
@ -15,4 +23,8 @@ public class Menu {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public ArrayList<Menu> getSubMenuList() {
return this.subMenuList;
}
} }

14
src/test/java/Application/MenuTest.java

@ -4,6 +4,8 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class MenuTest { class MenuTest {
@ -21,4 +23,16 @@ class MenuTest {
Menu menu = new Menu("Item 1"); Menu menu = new Menu("Item 1");
assertTrue(menu.getName().equals("Item 1")); assertTrue(menu.getName().equals("Item 1"));
} }
@Test
void testAddMenuFunction(){
ArrayList<Menu> menus = new ArrayList<>();
Menu menu1 = new Menu("Menu 1");
Menu menu2 = new Menu("Menu 2");
Menu menu1_1 = new Menu("Menu 1.1");
menu1.addMenu(menu1_1);
menus.add(menu1);
menus.add(menu2);
assertTrue(menus.get(0).equals(menu1) && menus.get(1).equals(menu2) && menus.get(0).getSubMenuList().get(0).equals(menu1_1));
}
} }
Loading…
Cancel
Save