Skip to content

Commit 4344479

Browse files
author
orrym
committed
BAEL-1517: Added Java7 style assertions
1 parent 3eb71bc commit 4344479

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.testing.assertj.exceptions;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.fail;
5+
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
6+
7+
import org.junit.Test;
8+
9+
public class Java7StyleAssertions {
10+
11+
@Test
12+
public void whenDividingByZero_thenArithmeticException() {
13+
try {
14+
int numerator = 10;
15+
int denominator = 0;
16+
int quotient = numerator / denominator;
17+
fail("ArithmeticException expected because dividing by zero yields an ArithmeticException.");
18+
failBecauseExceptionWasNotThrown(IndexOutOfBoundsException.class);
19+
} catch (ArithmeticException e) {
20+
assertThat(e).hasMessage("/ by zero");
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)