Skip to content

Instantly share code, notes, and snippets.

@mariuszs
Created November 15, 2013 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariuszs/7490875 to your computer and use it in GitHub Desktop.
Save mariuszs/7490875 to your computer and use it in GitHub Desktop.
Checking for 2 expected values in Junit
import org.junit.Test;
import static com.googlecode.catchexception.CatchException.caughtException;
import static com.googlecode.catchexception.apis.CatchExceptionBdd.then;
import static com.googlecode.catchexception.apis.CatchExceptionBdd.when;
public class SomeTest {
SomeService foo;
@Test
public void testAMethodScenario1() {
//given scenario 1
when(foo).amethod();
then(caughtException())
.isInstanceOf(MySystemException.class)
.hasMessage("An error occured due to case 1 being incorrect.");
}
@Test
public void testAMethodScenario2() {
//given scenario 2
when(foo).amethod();
then(caughtException())
.isInstanceOf(MySystemException.class)
.hasMessage("An error occured as case 2 could not be found");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment