FixedStack implements IStack<T> { @Override public void clear() { this.index = 0; } @SuppressWarnings("unchecked")  FixedStack(int size); @Override void push(T element); @Override T peek(); @Override T pop(); @Override int size(); @Override boolean isEmpty(); @Override void clear(); @Override final T[] toArray(Class<T[]> arrayType);  }
@Test void clear() { FixedStack<String> stack = new FixedStack<>(2); stack.clear(); stack.push("1"); stack.push("2"); stack.clear(); Assertions.assertTrue(stack.isEmpty()); Assertions.assertThrows(IndexOutOfBoundsException.class, stack::peek); Assertions.assertEquals("[]", Arrays.toString(stack.toArray(String[].class))); }