From 647eb68fefcf00c3d1d14a709c8d8f7dd815c992 Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Thu, 13 Jan 2022 13:45:39 +0100 Subject: [PATCH] Added subMenu function for class Menu with test --- src/main/java/Application/Menu.java | 12 ++++++++++++ src/test/java/Application/MenuTest.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/Application/Menu.java b/src/main/java/Application/Menu.java index 9d898e0..95ea678 100644 --- a/src/main/java/Application/Menu.java +++ b/src/main/java/Application/Menu.java @@ -1,11 +1,19 @@ package Application; +import java.util.ArrayList; + public class Menu { private String name; + private ArrayList subMenuList; public Menu(String name){ setName(name); + subMenuList = new ArrayList<>(); + } + + public void addMenu(Menu menu){ + subMenuList.add(menu); } public String getName() { @@ -15,4 +23,8 @@ public class Menu { public void setName(String name) { this.name = name; } + + public ArrayList getSubMenuList() { + return this.subMenuList; + } } diff --git a/src/test/java/Application/MenuTest.java b/src/test/java/Application/MenuTest.java index f3cd75f..3ca3193 100644 --- a/src/test/java/Application/MenuTest.java +++ b/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.Test; +import java.util.ArrayList; + import static org.junit.jupiter.api.Assertions.*; class MenuTest { @@ -21,4 +23,16 @@ class MenuTest { Menu menu = new Menu("Item 1"); assertTrue(menu.getName().equals("Item 1")); } + + @Test + void testAddMenuFunction(){ + ArrayList 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)); + } } \ No newline at end of file