Skip to content

Instantly share code, notes, and snippets.

@mariuszs
Last active December 28, 2015 10:58
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/7489706 to your computer and use it in GitHub Desktop.
Save mariuszs/7489706 to your computer and use it in GitHub Desktop.
BDD Style expect exception for 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 SomeServiceTest {
@Test
public void testDoThat() {
when(new SomeService()).doThat();
then(caughtException()).isExactlyInstanceOf(GenericException.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment