We are going to rewrite RemApp to fill out to do the “bigger” scenario from the test-driven development notes. I have re-organized the code again a little to help support using the Model-View separation concept based on the Model-View-Controller architecture. You will also write your first JUnit test cases:
- Download the files for the lab and put them into a new project.
- Add a new JUnit test class to the project, consoleKit.TestMenuStack:
o If you are using NetBeans, check the Test Initializer box when creating the class
o Declare a MenuStack (the files include a skeleton of the class) variable and two Menu variables. The first will be the “parent” menu of the 2nd.
o In an initializer function (annotated by @Before)
- Initialize the MenuStack
- Then initialize the Menu’s using this MenuStack
- When you write MenuStack, you will be pushing the Menu’s onto a stack inside the constructor of the Menu
o Define a test function (include the @Test annotation) that uses assertEquals() to confirm that the current menu for the MenuStack equals the 2nd menu initialized
o Fill in MenuStack so that this test case passes.
- It is recommended that you use an ArrayDeque<Menu> to store the stack of Menu’s. The functions for push, pop and top are addFirst(), removeFirst() and getFirst(). The API documentation is at: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Deque.html
- Hint: each missing method can be done in one line, though you might use 2-3 lines for run()
o Define a second test case checks for returning to the previous menu:
- Create a ReturnFromMenumenu item, initializing it with the name of the first Menu and the MenuStack
- Add this menu item to the 2ndMenu
- Call the menu item’s execute() function
- Use assertEquals() to confirm the current menu is now the parent menu
o Fill in the missing elements of MenuStack and ReturnFromMenu to get this case to pass
- Run RemAppto see that the program is now functioning correctly. See below for an additional scenario to check the proper return from a nested menu
- Submit your work – because you want TestMenuStackto be included, it is easiest to zip up the whole project folder so that both src and test folders are included
Grading:
40% TestMenuStack
40% MenuStack
20% ReturnFromMenu
(no need to add comments)
- Here is the additional scenario:
Reminders, version 0.1
Options:
- Quit
- List today’s reminders
- Add a new category of reminders
- Choose a category to work with
Enter an option (0-3): 3
Options:
- Personal
Enter an option (0-0): 0
Options:
- Quit
- Return to main menu
- List all reminders
- Add a reminder
Enter an option (0-3): 1
Options:
- Quit
- List today’s reminders
- Add a new category of reminders
- Choose a category to work with
Enter an option (0-3): 0