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?

Never mind, figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.