Skip to content

Instantly share code, notes, and snippets.

@mehmetcemyucel
Last active April 4, 2021 09:03
Show Gist options
  • Save mehmetcemyucel/cd353046d55a9a41af1aa7ac8823e321 to your computer and use it in GitHub Desktop.
Save mehmetcemyucel/cd353046d55a9a41af1aa7ac8823e321 to your computer and use it in GitHub Desktop.
springboot-junit-rule
public class ExpectedExceptionTest {
@Rule
public ExpectedException exp = ExpectedException.none();
@Test
public void test() {
exp.expect(NullPointerException.class);
String value = null;
value.split("");
fail();
}
@Test
public void test2() {
exp.expect(ArithmeticException.class);
exp.expectMessage("/ by zero");
int val1 = 3, val2 = 0;
val1 = val1 / val2;
fail();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment