Skip to content
Snippets Groups Projects
Commit 4ae79849 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

added testPopFromEmptyStack()

parent c5b30764
Branches
Tags fails-testPopFromEmptyStack
No related merge requests found
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.EmptyStackException;
import static org.junit.Assert.*;
......@@ -65,4 +69,35 @@ public class MyStackTest {
stack.pop();
assertEquals(2,stack.size());
}
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testPopFromEmptyStack() {
thrown.expect(EmptyStackException.class);
// EmptyStackExpression says it all, but if the were a constructor that took a String then we could test
// thrown.expectMessage("Attempted to pop from empty stack.");
stack.pop();
}
/* WILL TEST IF *ANY* CODE IN TEST METHOD THROWS EXCEPTION -- OKAY FOR SMALL TEST METHODS
@Test(expected = EmptyStackException.class)
public void testPopFromEmptyStack() {
stack.pop();
}
*/
/* JUNIT 3 IDIOM
@Test
public void testPopFromEmptyStack() {
try {
stack.pop();
fail("Expected EmptyStackException to be thrown.");
} catch (EmptyStackException emptyStackException) {
// EmptyStackExpression says it all, but if the were a constructor that took a String then we could test
// assertThat(emptyStackExpression.getMessage(), is("Attempted to pop from empty stack."));
}
}
*/
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment