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 emptyOptional = Optional.empty(); assertThat(emptyOptional).isEmpty(); @@ -69,12 +69,12 @@ public void optional_assertions_examples() { logAssertionErrorMessage("OptionalAssert.isPresent", e); } try { - assertThat(emptyOptional).contains("Test"); + assertThat(emptyOptional).hasValue("Test"); } catch (AssertionError e) { logAssertionErrorMessage("OptionalAssert.contains", e); } try { - assertThat(optional).contains("Foo"); + assertThat(optional).hasValue("Foo"); } catch (AssertionError e) { logAssertionErrorMessage("OptionalAssert.contains", e); } @@ -147,8 +147,8 @@ public void flatMap_optional_assertion_example() { // assertions succeed assertThat(Optional.of("something")).contains("something") - .flatMap(UPPER_CASE_OPTIONAL_STRING) - .contains("SOMETHING"); + .flatMap(UPPER_CASE_OPTIONAL_STRING) + .hasValue("SOMETHING"); assertThat(Optional. empty()).flatMap(UPPER_CASE_OPTIONAL_STRING) .isEmpty(); diff --git a/assertions-examples/src/test/java/org/assertj/examples/PathAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/PathAssertionsExamples.java index e867fe7..8f3c585 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/PathAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/PathAssertionsExamples.java @@ -19,7 +19,7 @@ import static java.nio.file.Files.write; import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.nio.charset.Charset; import java.nio.file.FileSystems; diff --git a/assertions-examples/src/test/java/org/assertj/examples/RepresentationExamples.java b/assertions-examples/src/test/java/org/assertj/examples/RepresentationExamples.java index b5ee89e..5244171 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/RepresentationExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/RepresentationExamples.java @@ -17,14 +17,14 @@ import org.assertj.core.api.Assertions; import org.assertj.core.presentation.StandardRepresentation; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; public class RepresentationExamples extends AbstractAssertionsExamples { private static final CustomRepresentation CUSTOM_REPRESENTATION = new CustomRepresentation(); - @After + @AfterEach public void afterTest() { Assertions.useRepresentation(STANDARD_REPRESENTATION); } diff --git a/assertions-examples/src/test/java/org/assertj/examples/SoftAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/SoftAssertionsExamples.java index 973eda3..314407b 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/SoftAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/SoftAssertionsExamples.java @@ -81,17 +81,17 @@ public void build_soft_assertions_errors_report_example() { // let the assertions fail catchThrowable(() -> softly.assertAll()); // check the built report - assertThat(reportBuilder.toString()).isEqualTo(format("Assertions report:%n" + - "------------------%n" + - "[check Frodo's race] %n" + - "expected: \"Orc\"%n" + - "but was : \"Hobbit\"%n" + - "------------------%n" + - "[check Aragorn's age] %n" + - "Expecting:%n" + - " 87%n" + - "to be greater than:%n" + - " 500%n%n")); + assertThat(reportBuilder).hasToString(format("Assertions report:%n" + + "------------------%n" + + "[check Frodo's race] %n" + + "expected: \"Orc\"%n" + + " but was: \"Hobbit\"%n" + + "------------------%n" + + "[check Aragorn's age] %n" + + "Expecting actual:%n" + + " 87%n" + + "to be greater than:%n" + + " 500%n%n")); } @Test diff --git a/assertions-examples/src/test/java/org/assertj/examples/StreamAssertionsExamples.java b/assertions-examples/src/test/java/org/assertj/examples/StreamAssertionsExamples.java index 890f771..687bf97 100644 --- a/assertions-examples/src/test/java/org/assertj/examples/StreamAssertionsExamples.java +++ b/assertions-examples/src/test/java/org/assertj/examples/StreamAssertionsExamples.java @@ -101,7 +101,7 @@ public void stream_basic_assertions_examples() { Stream testedList = Stream.of(1); Stream referenceList = Stream.of(1, 2, 3); - assertThat(referenceList).containsSequence(testedList.toArray(Integer[]::new)); + assertThat(referenceList).contains(testedList.toArray(Integer[]::new)); Stream stream = Stream.of("--option", "a=b", "--option", "c=d"); assertThat(stream).containsSequence("--option", "c=d"); @@ -110,14 +110,14 @@ public void stream_basic_assertions_examples() { @Test public void primitive_stream_assertions_examples() { - assertThat(IntStream.of(1, 2, 3)).isNotNull() + assertThat(IntStream.of(1, 2, 3)) .contains(1) .anySatisfy(i -> assertThat(i).isLessThan(2)); assertThat(LongStream.of(0, 1, 2, 3, 4)).hasSize(5) .containsSequence(1L, 2L, 3L); - assertThat(DoubleStream.of(1, 2, 3)).isNotNull() + assertThat(DoubleStream.of(1, 2, 3)) .contains(1.0, 2.0, 3.0) .allMatch(Double::isFinite); } @@ -299,11 +299,11 @@ public void iterator_assertion_example() { Iterator elvesRingsIterator = Stream.of(vilya, nenya, narya).iterator(); // elvesRingsIterator is only consumed when needed which is not the case with null/notNull assertion assertThat(elvesRingsIterator).isNotNull(); - assertThat(elvesRingsIterator.hasNext()).as("iterator is not consumed").isTrue(); + assertThat(elvesRingsIterator).as("iterator is not consumed").hasNext(); // elvesRingsIterator is consumed when needed but only once, you can then chain assertion assertThat(elvesRingsIterator).toIterable().isSubsetOf(ringsOfPower).contains(nenya, narya); // elvesRingsIterator is consumed ... - assertThat(elvesRingsIterator.hasNext()).as("iterator is consumed").isFalse(); + assertThat(elvesRingsIterator).as("iterator is consumed").isExhausted(); } @Test @@ -465,7 +465,7 @@ public void stream_assertions_testing_elements_type() throws Exception { } @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); @@ -482,7 +482,7 @@ public void test_issue_245() throws Exception { } @Test - public void test_issue_236() throws Exception { + public void issue_236() throws Exception { List stream2 = newArrayList(new Foo("id", 2)); assertThat(Stream.of(new Foo("id", 1))).usingElementComparatorOnFields("id").isEqualTo(stream2); assertThat(Stream.of(new Foo("id", 1))).usingElementComparatorIgnoringFields("bar").isEqualTo(stream2);