BAEL-1517: Added Java7 style assertions
This commit is contained in:
parent
3eb71bca92
commit
4344479d7a
|
@ -0,0 +1,23 @@
|
|||
package com.baeldung.testing.assertj.exceptions;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Java7StyleAssertions {
|
||||
|
||||
@Test
|
||||
public void whenDividingByZero_thenArithmeticException() {
|
||||
try {
|
||||
int numerator = 10;
|
||||
int denominator = 0;
|
||||
int quotient = numerator / denominator;
|
||||
fail("ArithmeticException expected because dividing by zero yields an ArithmeticException.");
|
||||
failBecauseExceptionWasNotThrown(IndexOutOfBoundsException.class);
|
||||
} catch (ArithmeticException e) {
|
||||
assertThat(e).hasMessage("/ by zero");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue