diff --git a/assertions-examples/pom.xml b/assertions-examples/pom.xml
index a2f028c..f07dc14 100644
--- a/assertions-examples/pom.xml
+++ b/assertions-examples/pom.xml
@@ -21,7 +21,7 @@
UTF-8
3.0.0
- 3.19.0
+ 3.27.7
@@ -29,7 +29,7 @@
org.junit
junit-bom
- 5.7.0
+ 5.14.4
pom
import
@@ -143,7 +143,7 @@
org.mockito
mockito-core
- 2.18.3
+ 4.11.0
test
@@ -181,7 +181,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 2.22.1
+ 3.1.2
**/*Examples.java
diff --git a/assertions-examples/src/test/java/org/assertj/examples/Array2DAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/Array2DAssertionsExamples.java
index a5fbada..adddf4a 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/Array2DAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/Array2DAssertionsExamples.java
@@ -25,13 +25,11 @@ public void array2D_assertions_examples() {
int[][] numbers = new int[][] { { 1, 2, 3 }, { 4, 5, 6 } };
// 2D generic array
assertThat(abc).hasDimensions(2, 3)
- .isNotEmpty()
.contains(new String[] { "1", "2", "3" }, atIndex(1))
.isDeepEqualTo(new String[][] { { "a", "b", "c" }, { "1", "2", "3" } })
.hasSameDimensionsAs(numbers);
// 2D primtive arrays
assertThat(numbers).hasDimensions(2, 3)
- .isNotEmpty()
.contains(new int[] { 1, 2, 3 }, atIndex(0))
.hasSameDimensionsAs(abc)
.isDeepEqualTo(new int[][] { { 1, 2, 3 }, { 4, 5, 6 } });
diff --git a/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java
index 1e068a7..381d82f 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java
@@ -104,7 +104,7 @@ public void array_assertions_examples() {
String[] abc = { "a", "b", "c" };
assertThat(abc).containsExactly("a", "b", "c")
- .containsAnyOf("b")
+ .contains("b")
.containsAnyOf("b", "c")
.containsAnyOf("a", "b", "c")
.containsAnyOf("a", "b", "c", "d")
diff --git a/assertions-examples/src/test/java/org/assertj/examples/AssumptionExamples.java b/assertions-examples/src/test/java/org/assertj/examples/AssumptionExamples.java
index d2a615e..3bf683f 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/AssumptionExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/AssumptionExamples.java
@@ -21,7 +21,7 @@
import static org.assertj.examples.data.Race.ORC;
import org.assertj.examples.data.TolkienCharacter;
-import org.junit.AfterClass;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
public class AssumptionExamples extends AbstractAssertionsExamples {
@@ -30,7 +30,7 @@ public class AssumptionExamples extends AbstractAssertionsExamples {
private static int ranTests = 0;
- @AfterClass
+ @AfterAll
public static void afterClass() {
assertThat(ranTests).as("number of tests run").isEqualTo(2);
}
diff --git a/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java
index e801b3b..1b03475 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/BasicAssertionsExamples.java
@@ -73,7 +73,7 @@ public void meaningful_error_with_test_description_example() {
assertThat(error).isInstanceOf(AssertionError.class)
.hasMessage(format("[check Frodo's age] %n" +
"expected: 33%n" +
- "but was : 50"));
+ " but was: 50"));
// you can pass a Supplier to avoid building the description if the assertion succeeds
assertThat(frodo.age).as(() -> "check Frodo's age").isEqualTo(50);
diff --git a/assertions-examples/src/test/java/org/assertj/examples/DateAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/DateAssertionsExamples.java
index 8afcc51..392bc6b 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/DateAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/DateAssertionsExamples.java
@@ -104,7 +104,7 @@ public void date_assertions_comparison_with_precision_level() {
Date date5 = parseDatetimeWithMs("2003-01-01T05:55:55.555");
assertThat(date1)
- .isEqualToIgnoringMillis(date2)
+ .isCloseTo(date2, 1000L)
.isInSameSecondAs(date2)
.isEqualToIgnoringSeconds(date3)
.isInSameMinuteAs(date3)
@@ -114,7 +114,7 @@ public void date_assertions_comparison_with_precision_level() {
.isInSameDayAs(date5);
try {
- assertThat(date1).isEqualToIgnoringMillis(date3);
+ assertThat(date1).isCloseTo(date3, 1000L);
} catch (AssertionError e) {
logAssertionErrorMessage("isEqualToIgnoringMillis", e);
}
diff --git a/assertions-examples/src/test/java/org/assertj/examples/GeneratedJunitSoftAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/GeneratedJunitSoftAssertionsExamples.java
index a0779fa..d3ee85a 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/GeneratedJunitSoftAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/GeneratedJunitSoftAssertionsExamples.java
@@ -22,7 +22,7 @@ public class GeneratedJunitSoftAssertionsExamples extends AbstractAssertionsExam
@Rule
public JUnitSoftAssertions softly = new JUnitSoftAssertions();
-
+
@Test
public void generated_soft_assertions_example() throws NameException {
// use the generated soft assertions
diff --git a/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java
index df273ed..8164353 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java
@@ -76,7 +76,7 @@ public void iterable_basic_assertions_examples() {
List abc = asList("a", "b", "c");
assertThat(abc).hasSize(3)
- .containsAnyOf("b")
+ .contains("b")
.containsAnyOf("b", "c")
.containsAnyOf("a", "b", "c")
.containsAnyOf("a", "b", "c", "d")
@@ -145,7 +145,7 @@ public void iterable_basic_assertions_examples() {
List testedList = list(1);
List referenceList = list(1, 2, 3);
- assertThat(referenceList).containsSequence(testedList.toArray(new Integer[testedList.size()]));
+ assertThat(referenceList).contains(testedList.toArray(new Integer[testedList.size()]));
List options = list("--option", "a=b", "--option", "c=d");
assertThat(options).containsSequence("--option", "c=d");
@@ -655,7 +655,7 @@ public boolean matches(BasketBallPlayer player) {
}
@Test
- public void test_issue_245() throws Exception {
+ public void issue_245() throws Exception {
Foo foo1 = new Foo("id", 1);
foo1._f2 = "foo1";
Foo foo2 = new Foo("id", 2);
@@ -673,7 +673,7 @@ public void test_issue_245() throws Exception {
}
@Test
- public void test_issue_236() throws Exception {
+ public void issue_236() throws Exception {
List list1 = list(new Foo("id", 1));
List list2 = list(new Foo("id", 2));
assertThat(list1).usingElementComparatorOnFields("id").isEqualTo(list2);
@@ -695,7 +695,7 @@ public void display_collection_with_one_element_per_line() throws Exception {
}
@Test
- public void test_issue_656() {
+ public void issue_656() {
Iterator iterator = new ArrayList().iterator();
assertThat(iterator).isSameAs(iterator);
}
@@ -727,7 +727,7 @@ public void navigation_with_iterable_examples() {
}
@Test
- public void test_navigation_with_list() {
+ public void navigation_with_list() {
List hobbits = list(frodo, sam, pippin);
assertThat(hobbits).first().isEqualTo(frodo);
assertThat(hobbits).element(1).isEqualTo(sam);
@@ -735,7 +735,7 @@ public void test_navigation_with_list() {
}
@Test
- public void test_navigable_size_assertions() {
+ public void navigable_size_assertions() {
Iterable elvesRings = list(vilya, nenya, narya);
// assertion will pass:
diff --git a/assertions-examples/src/test/java/org/assertj/examples/IterableWithSpecificComparatorAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/IterableWithSpecificComparatorAssertionsExamples.java
index 61e961a..a3f2743 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/IterableWithSpecificComparatorAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/IterableWithSpecificComparatorAssertionsExamples.java
@@ -20,6 +20,7 @@
import java.util.Comparator;
import java.util.List;
+import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.assertj.examples.comparator.AtPrecisionComparator;
import org.assertj.examples.data.Employee;
import org.assertj.examples.data.TolkienCharacter;
@@ -87,6 +88,14 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
Comparator closeEnough = new AtPrecisionComparator<>(0.5);
+ // since 3.x the recursive element comparator takes its own configuration to register field/type comparators
+ RecursiveComparisonConfiguration heightFieldConfig = RecursiveComparisonConfiguration.builder()
+ .withComparatorForFields(closeEnough, "height")
+ .build();
+ RecursiveComparisonConfiguration doubleTypeConfig = RecursiveComparisonConfiguration.builder()
+ .withComparatorForType(closeEnough, Double.class)
+ .build();
+
Dude[] hobbits = new Dude[] { dude };
// assertions will pass
@@ -102,8 +111,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);
- assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height")
- .usingRecursiveFieldByFieldElementComparator()
+ assertThat(hobbits).usingRecursiveFieldByFieldElementComparator(heightFieldConfig)
.contains(tallerDude);
assertThat(asList(dude)).usingComparatorForElementFieldsWithNames(closeEnough, "height")
@@ -118,8 +126,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);
- assertThat(asList(dude)).usingComparatorForElementFieldsWithNames(closeEnough, "height")
- .usingRecursiveFieldByFieldElementComparator()
+ assertThat(asList(dude)).usingRecursiveFieldByFieldElementComparator(heightFieldConfig)
.contains(tallerDude);
assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
@@ -134,8 +141,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);
- assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
- .usingRecursiveFieldByFieldElementComparator()
+ assertThat(hobbits).usingRecursiveFieldByFieldElementComparator(doubleTypeConfig)
.contains(tallerDude);
assertThat(asList(dude)).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
@@ -150,8 +156,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);
- assertThat(asList(dude)).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
- .usingRecursiveFieldByFieldElementComparator()
+ assertThat(asList(dude)).usingRecursiveFieldByFieldElementComparator(doubleTypeConfig)
.contains(tallerDude);
Dude reallyTallDude = new Dude("Frodo", 1.9);
diff --git a/assertions-examples/src/test/java/org/assertj/examples/JUnitBDDSoftAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/JUnitBDDSoftAssertionsExamples.java
index 4c81422..f267a12 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/JUnitBDDSoftAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/JUnitBDDSoftAssertionsExamples.java
@@ -14,8 +14,8 @@
import org.assertj.core.api.JUnitBDDSoftAssertions;
import org.assertj.examples.data.Mansion;
-import org.junit.Ignore;
import org.junit.Rule;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class JUnitBDDSoftAssertionsExamples extends AbstractAssertionsExamples {
@@ -26,7 +26,7 @@ public class JUnitBDDSoftAssertionsExamples extends AbstractAssertionsExamples {
// comment the @Ignore to see the test failing with all the assertion error and not only the first one.
@Test
- @Ignore
+ @Disabled
public void failing_junit_soft_assertions_example() {
Mansion mansion = new Mansion();
mansion.hostPotentiallyMurderousDinnerParty();
diff --git a/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java
index 9a2190f..e1ac64a 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/MapAssertionsExamples.java
@@ -55,6 +55,7 @@ public class MapAssertionsExamples extends AbstractAssertionsExamples {
private Condition> oneRingManBearer = new Condition<>(entry -> entry.getKey().getRace() == MAN
&& entry.getValue() == oneRing,
"One ring man bearer");
+
// @format:on
@Test
@@ -178,15 +179,15 @@ public void display_sorted_maps_in_error_message() {
try {
Map expected = ImmutableMap. builder().put("a", 1).put("b", 2).build();
Map actual = ImmutableMap. builder().put("b", 1).put("a", 1).build();
- assertThat(expected).isEqualTo(actual);
+ assertThat(expected).containsExactlyInAnyOrderEntriesOf(actual);
} catch (AssertionError e) {
logAssertionErrorMessage("display sorted maps in error message", e);
}
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
- public void test_bug_485() {
+ public void bug_485() {
// https://github.com/joel-costigliola/assertj-core/issues/485
Map map1 = new HashMap();
map1.put("Key1", "Value1");
@@ -196,7 +197,7 @@ public void test_bug_485() {
}
@Test
- public void test_navigable_size_assertions() throws Exception {
+ public void navigable_size_assertions() throws Exception {
Map ringBearers = new HashMap<>();
ringBearers.put(nenya, galadriel);
ringBearers.put(narya, gandalf);
diff --git a/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java
index 1dc72a9..12c8c99 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/NumberAssertionsExamples.java
@@ -104,7 +104,7 @@ public void assertion_error_with_message_differentiating_double_and_float() {
// message)
assertThat(e).hasMessage(format("%n" +
"expected: 42.0%n" +
- "but was : 42.0f"));
+ " but was: 42.0f"));
return;
}
}
@@ -129,10 +129,10 @@ public void big_decimals_assertions_examples() {
@Test
public void number_assertions_with_offset_examples() {
- assertThat(8.1).isEqualTo(8.0, offset(0.1));
- assertThat(8.1f).isEqualTo(8.2f, offset(0.1f));
+ assertThat(8.1).isCloseTo(8.0, offset(0.1));
+ assertThat(8.1f).isCloseTo(8.2f, offset(0.1f));
try {
- assertThat(8.1f).isEqualTo(8.0f, offset(0.1f));
+ assertThat(8.1f).isCloseTo(8.0f, offset(0.1f));
} catch (AssertionError e) {
logAssertionErrorMessage("float isEqualTo with offset", e);
}
@@ -198,12 +198,12 @@ public void number_assertions_with_offset_examples() {
assertThat(8.1f)
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
- // alias of within
- .isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
+ .isCloseTo(8.0f, byLessThan(0.2f));
+ assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isCloseTo(0.0f, within(0.1f))
- .isEqualTo(0.0f, within(0.1f));
+ .isCloseTo(0.0f, within(0.1f));
assertThat(8.1f)
.isNotCloseTo(8.0f, byLessThan(0.01f))
@@ -215,23 +215,23 @@ public void number_assertions_with_offset_examples() {
assertThat(8.1f)
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
- // alias of within
- .isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
+ .isCloseTo(8.0f, byLessThan(0.2f));
+ assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isEqualTo(0.0f, within(0.1f))
- .isEqualTo(0.0f, offset(0.1f));
+ .isCloseTo(0.0f, offset(0.1f));
assertThat(8.1f)
// ... except when using byLessThan which implies a strict comparison
// assertThat(0.1f).isEqualTo(0.0f, byLessThan(0.1f)); // strict => fail
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
- // alias of within
- .isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
+ .isCloseTo(8.0f, byLessThan(0.2f));
+ assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isEqualTo(0.0f, within(0.1f))
- .isEqualTo(0.0f, offset(0.1f));
+ .isCloseTo(0.0f, offset(0.1f));
assertThat(5)
.isCloseTo(7, within(3))
@@ -298,7 +298,7 @@ public void isNotCloseTo_examples() {
@Test
public void number_assertions_with_binary_representation_examples() {
- assertThat(1).inBinary().isEqualTo(1);
+ assertThat(1).inBinary().isOne();
try {
assertThat(1).inBinary().isEqualTo(2);
} catch (AssertionError e) {
@@ -358,7 +358,7 @@ public void should_consider_primitive_negative_zero_as_zero_fixing_issue_919() {
@Test
public void should_handle_NaN_and_infinity_correctly_fixing_issue_984() {
- assertThat(Double.NaN == Double.NaN).isFalse();
+ assertThat(Double.NaN).isNotSameAs(Double.NaN);
// https://github.com/joel-costigliola/assertj-core/issues/1775
// assertThat(Double.NaN).isNotEqualTo(Double.NaN);
assertThat(Double.POSITIVE_INFINITY).isEqualTo(Double.POSITIVE_INFINITY);
diff --git a/assertions-examples/src/test/java/org/assertj/examples/OptionalAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/OptionalAssertionsExamples.java
index 7264295..ef3c149 100644
--- a/assertions-examples/src/test/java/org/assertj/examples/OptionalAssertionsExamples.java
+++ b/assertions-examples/src/test/java/org/assertj/examples/OptionalAssertionsExamples.java
@@ -40,9 +40,9 @@ public class OptionalAssertionsExamples extends AbstractAssertionsExamples {
@Test
public void optional_assertions_examples() {
Optional optional = Optional.of("Test");
- assertThat(optional).isPresent()
- .containsInstanceOf(String.class)
- .contains("Test");
+ assertThat(optional)
+ .containsInstanceOf(String.class)
+ .hasValue("Test");
Optional