Testing Multiple Implementations

The List ADT has two implementations, ArrayList<Integer> and LinkedList<Integer>. Both must behave the same way through the List interface, and we want to test both.

Solution

Put every @Test in an abstract class ListTest, written only against the List interface. The class declares protected abstract List<Integer> createList();, and its @BeforeEach method calls createList() to build the fresh list. Each implementation gets a small subclass that overrides createList() and inherits all the tests in ListTest.

Solution
public class LinkedListTest extends ListTest {

  @Override
  protected List<Integer> createList() {
    return new LinkedList<>();
  }
}
Solution

Nothing more for the new test: it lives in ListTest, so every subclass already runs it. For CircularList, write one subclass of ListTest whose createList() returns a new CircularList.