Lab 7: JUnit Testing


Having thorough tests can ensure the behavior of a class matches its specification, but writing thorough tests can be challenging. In this assignment you will gain experience writing unit tests for an AutoCompleter interface and use it to test your own implementation of the interface.

Video introduction for the lab


AutoCompleter interface

The AutoCompleter interface has the following methods:

You must implement the static format() method and write complete javadocs for all the methods in AutoCompleter.

Unordered List Implementation

You must create a class, UnorderedList, that implements the AutoCompleter interface using an unordered list. Your class must have only one private attribute: private final List<String> items that is assigned via a one-argument constructor. Note: the constructor should ensure that no duplicates are in the list passed to the constructor.

To ensure there are no duplicates, you can make use of a HashSet. If you have a list called list you can do the following to remove duplicates:
Set<String> unique = new HashSet<>(list);


You must create JUnit tests for all of the methods in the AutoCompleter interface. These tests should be rigorous and ensure all methods behave as specified in the requirements. If the behavior of specific methods are not completely specified, please ask your instructor for clarification.

Use the tests to ensure your UnorderedList implementation conforms to the requirements.

Your instructor may verify your tests by providing multiple faulty implementations to see if your tests catch the errors embedded in the faulty implementations.


This laboratory assignment, developed by Dr. Chris Taylor.

See your professor's instructions for details on submission guidelines and due dates.