
Case 2 – JUnit tests, Collections, and JavaBeans
Think-Design-Write Test-Code
5 Days
- Description
Congratulations! You have just been hired for a junior programming position with Mighty Corp.
Your boss comes to you and gives you your first assignment. It includes a UML class diagram describing two new classes, Chat and Message. See Figure 1 – 2.

Figure 1-2: The class diagram for case 2
She explains that your assignment is to implement the ability to store , in memory, all messages that are sent. These messages are to be grouped by to whom they are sent and then sorted by when they are sent, earliest to latest.
Messages should be able to be added one at a time via the addMessage method of the Chat class and all messages for an individual must be retrievable by making one method call to the Chat class getMessagesFor method.
Each message is to be stored as a JavaBean called Message as seen in the UML Class diagram.
She then says,”I’ll come back tomorrow morning and see how you are doing.” You dig in and start to work.
- Deliverables
- Test matrices that show how the Chat class is being tested in the JUnit test.
- A JUnit test to test the Chat class
- A working Chat solution
- An assessment case
- A presentation of your teams solution to the problem
- Resources
- What are JavaBeans?
- Wikipedia JavaBeans Entry
- UML
- UML Class Diagrams
- JUnit Definition
- JUnit Home Page
- Unit Testing
- An example of a JUnit test
- The Collections tutorial
- Java API: Double, Integer, Number, Collection, Iterator, HashMap, LinkedHashMap, ArrayList, Vector, Set, TreeSet, Stack, Queue
- Visual Paradigm