Created
March 26, 2012 20:10
-
-
Save sebastianbenz/2209317 to your computer and use it in GitHub Desktop.
A sample Stack test.
This file contains 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
package demo; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.Suite; | |
import org.junit.runners.Suite.SuiteClasses; | |
@RunWith(Suite.class) | |
@SuiteClasses({EmptyStack.class, StackWithOneElement.class}) | |
public class StackTest { | |
} | |
package demo; | |
import java.util.Stack; | |
public abstract class AbstractStackTest { | |
protected Stack<String> subject = new Stack<String>(); | |
} | |
package demo; | |
import java.util.EmptyStackException; | |
import org.junit.Test; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
public class EmptyStack extends AbstractStackTest { | |
@Test | |
public void shouldHaveSizeZero() throws Exception { | |
assertThat(subject.size(), is(0)); | |
} | |
@Test(expected = EmptyStackException.class) | |
public void shouldThrowExceptionOnPop() throws Exception { | |
subject.pop(); | |
} | |
} | |
package demo; | |
import org.junit.Before; | |
import org.junit.Test; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
public class StackWithOneElement extends AbstractStackTest { | |
@Before | |
public void setup() { | |
subject.add("something"); | |
} | |
@Test | |
public void shouldHaveSizeOne() throws Exception { | |
assertThat(subject.size(), is(1)); | |
} | |
@Test | |
public void shouldDecreaseSizeOnPop() throws Exception { | |
subject.pop(); | |
assertThat(subject.size(), is(0)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment