Skip to content

Instantly share code, notes, and snippets.

@mariuszs
Last active December 28, 2015 10:49
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/7489324 to your computer and use it in GitHub Desktop.
Save mariuszs/7489324 to your computer and use it in GitHub Desktop.
Mockito + Catch Exception + Fest Assertion 2 - BDD Style!
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;
import static org.mockito.BDDMockito.given;
public class SomeServiceTest {
private SomeService myMock;
@Test
public void testDoThat() {
given(myMock.doSomething()).willThrow(new MyException());
when(myMock).doSomething();
then(caughtException()).isInstanceOf(MyException.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment