0
public int peek () {
       if (empty() == true) {
           throw new EmptyStackException();
       }
       return StackContents[top];
     
   }

So I have this piece of code in a class that implements a stack. The program works perfectly.

However, when I use Junit to test it, I have this:

@Test (expected = EmptyStackException.class)
    public void testException1 () {
        System.out.println("Testing for appropriate exception thrown when popping and peeking an empty stack");
        IArrayStack s = new IArrayStack();
        s.pop();
    }

Netbeans gives me a squiggly line under IllegalArgumentException for some reason and it says symbol not found. If I replace it with another exception like IllegalArgumentException, it compiles and runs, but of course the test fails...

Any idea why it's doing this?

Edited by iamsmooth: n/a

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by iamsmooth
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.