BAEL-1517: Editor Review Changes (#3635)
* Add XML, JavaConfig and Autowired examples.
* BAEL-1517: Added Java7 style assertions
* BAEL-1517: Upgrade AssertJ to 3.9.0;
add Java 8 style assertion tests
* Revert "Add XML, JavaConfig and Autowired examples."
This reverts commit 8f4df6b903
.
* BAEL-1517: Editor Review changes
* BAEL-1517: Formatting...
This commit is contained in:
parent
71e27c6bf0
commit
9cc582e66a
|
@ -5,19 +5,43 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Java8StyleAssertions {
|
||||
|
||||
@Test
|
||||
public void whenDividingByZero_thenArithmeticException() {
|
||||
public void whenGettingOutOfBoundsItem_thenIndexOutOfBoundsException() {
|
||||
assertThatThrownBy(() -> {
|
||||
int numerator = 10;
|
||||
int denominator = 0;
|
||||
int quotient = numerator / denominator;
|
||||
}).isInstanceOf(ArithmeticException.class)
|
||||
.hasMessageContaining("/ by zero");
|
||||
ArrayList<String> myStringList = new ArrayList<String>(Arrays.asList("Strine one", "String two"));
|
||||
myStringList.get(2);
|
||||
}).isInstanceOf(IndexOutOfBoundsException.class)
|
||||
.hasMessageStartingWith("Index: 2")
|
||||
.hasMessageContaining("2")
|
||||
.hasMessageEndingWith("Size: 2")
|
||||
.hasMessageContaining("Index: 2, Size: 2")
|
||||
.hasMessage("Index: %s, Size: %s", 2, 2)
|
||||
.hasMessageMatching("Index: \\d+, Size: \\d+")
|
||||
.hasNoCause();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWrappingException_thenCauseInstanceOfWrappedExceptionType() {
|
||||
assertThatThrownBy(() -> {
|
||||
try {
|
||||
throw new IOException();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).isInstanceOf(RuntimeException.class)
|
||||
.hasCauseInstanceOf(IOException.class)
|
||||
.hasStackTraceContaining("IOException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDividingByZero_thenArithmeticException() {
|
||||
assertThatExceptionOfType(ArithmeticException.class).isThrownBy(() -> {
|
||||
int numerator = 10;
|
||||
int denominator = 0;
|
||||
|
@ -25,7 +49,7 @@ public class Java8StyleAssertions {
|
|||
})
|
||||
.withMessageContaining("/ by zero");
|
||||
|
||||
// BDD style:
|
||||
// Alternatively:
|
||||
|
||||
// when
|
||||
Throwable thrown = catchThrowable(() -> {
|
||||
|
|
Loading…
Reference in New Issue