Created
December 2, 2014 22:03
-
-
Save efleming969/fd5f69d529136cc5139d to your computer and use it in GitHub Desktop.
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
package example; | |
import java.util.*; | |
import java.io.*; | |
import static org.junit.Assert.*; | |
import static org.mockito.Mockito.*; | |
import org.junit.*; | |
import org.junit.rules.*; | |
public class ExceptionRules { | |
@Rule | |
public ExpectedException thrown = ExpectedException.none(); | |
@Test | |
public void should_throw_exception_with_particular_message () throws Exception { | |
thrown.expect ( Exception.class ); | |
thrown.expectMessage ( "bad data" ); | |
Foo.someFunctionThatThrowsAnException (); | |
} | |
} | |
class Foo { | |
public static void someFunctionThatThrowsAnException ( ) throws Exception { | |
throw new Exception ( "bad data" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment