BAEL-1517: Added Java7 style assertions

This commit is contained in:
orrym 2018-02-03 13:06:31 +02:00
parent 3eb71bca92
commit 4344479d7a
1 changed files with 23 additions and 0 deletions

View File

@ -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");
}
}
}