FixedSizeStack { public void push(E item) { if (top < items.length) { items[top ++] = item; } else { throw new IllegalStateException("Stack is full"); } } FixedSizeStack(int capacity); boolean isEmpty(); void push(E item); E pop(); int getSize();  }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "Stack is full") public void testStackCannotBeOverflown() throws Exception { final int capacity = 5; final FixedSizeStack<Integer> stack = new FixedSizeStack<>(capacity); try { for (int i = 0; i < capacity; i ++) { stack.push(i); } } catch (Exception e) { fail("Unexpected exception: " + e); } stack.push(capacity); }