import static org.junit.Assert.*; import org.junit.Test; import org.junit.Before; import org.junit.After; import org.junit.Ignore; /** * run using: java org.junit.runner.JUnitCore BoundedStackTest */ public class BoundedStackTest { BoundedStack b3; @Before public void setUp() { b3 = new BoundedStack(3); } @After public void tearDown() { b3 = null; } @Test(expected = RuntimeException.class) public void negativeCapacity() { BoundedStack b = new BoundedStack(-1); } @Test public void capacity() { assertEquals("capacity", 3, b3.getCapacity()); } @Test public void popEmptyStack() { assertNull(b3.pop()); } @Test public void peekEmptyStack() { assertNull("peek empty stack", b3.peek()); } @Test public void peek() { b3.push(34); assertEquals("peek34", 34, b3.peek()); } @Ignore("debug later") @Test public void order() { b3.push("first"); b3.push("second"); assertEquals("pop second", "second", b3.pop()); assertEquals("pop first", "first", b3.pop()); } @Test(expected = RuntimeException.class) public void testOverFillStack() { for(int i = 0; i<4; i++) { b3.push(i); } } @Test(timeout = 100) public void waiting() throws InterruptedException { Thread.sleep(50); } @Test public void nullArray() { Object[] a1 = new Object[2]; Object[] a2 = new Object[2]; assertArrayEquals("null arrays", a1, a2); } }