Created
November 5, 2011 02:02
-
-
Save bbasata/1340977 to your computer and use it in GitHub Desktop.
An example of BDD-influenced use of JUnit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import java.util.EmptyStackException; | |
import java.util.Stack; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
public class StackTest { | |
Stack<String> stack = new Stack<String>(); | |
@Test public void | |
isInitiallyEmpty() { | |
assertThat(stack.isEmpty(), is(true)); | |
} | |
@Test(expected=EmptyStackException.class) public void | |
refusesToPopWhenItIsEmpty() { | |
stack.pop(); | |
} | |
@Test public void | |
isNotEmptyWhenItHasAnItem() { | |
stack.push("an item"); | |
assertThat(stack.isEmpty(), is(false)); | |
} | |
@Test public void | |
popsAnItem() { | |
stack.push("first item"); | |
String poppedItem = stack.pop(); | |
assertThat(poppedItem, is("first item")); | |
} | |
@Test public void | |
removesAnItemWhenItIsPopped() { | |
stack.push("first item"); | |
stack.pop(); | |
assertThat(stack.isEmpty(), is(true)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment