From 347a4014b31fa6c03de767d64f2b7a691c365c04 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 20 Jun 2021 06:16:23 +0200 Subject: [PATCH 001/123] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 09bc134a38f..f811ff53439 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 assertj-core - 3.20.2 + 3.20.3-SNAPSHOT jar AssertJ fluent assertions Rich and fluent assertions for testing for Java @@ -16,7 +16,7 @@ scm:git:git@github.com:assertj/assertj-core.git scm:git:git@github.com:assertj/assertj-core.git git@github.com:assertj/assertj-core - assertj-core-3.20.2 + HEAD github From bbfb89c767a4805114ab3dc007d2fb08224827ea Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 21 Jun 2021 13:28:28 +0200 Subject: [PATCH 002/123] Bump assertj-core version under OSGi configuration --- verify.bndrun | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/verify.bndrun b/verify.bndrun index 458c0d0cf2e..2b5a7764b3b 100644 --- a/verify.bndrun +++ b/verify.bndrun @@ -30,8 +30,8 @@ # The version ranges will change as the version of # AssertJ and/or its dependencies change. -runbundles: \ - assertj-core;version='[3.20.0,3.20.1)',\ - assertj-core-tests;version='[3.20.0,3.20.1)',\ + assertj-core;version='[3.20.2,3.20.3)',\ + assertj-core-tests;version='[3.20.2,3.20.3)',\ junit-jupiter-api;version='[5.7.2,5.7.3)',\ junit-jupiter-engine;version='[5.7.2,5.7.3)',\ junit-platform-commons;version='[1.7.2,1.7.3)',\ From ea7cb4682e157fea72996b1726ae5bd2087c6f34 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 22 Jun 2021 08:33:25 +0200 Subject: [PATCH 003/123] Bump mockito.version from 3.11.1 to 3.11.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f811ff53439..1e3131b1c7b 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 4.13.2 5.7.2 - 3.11.1 + 3.11.2 0.8.7 From 9bbe2b53709edcc60d3869be2511d1976e3a32f8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Jun 2021 08:33:41 +0200 Subject: [PATCH 004/123] Bump byte-buddy.version from 1.11.2 to 1.11.5 (#2269) Bumps `byte-buddy.version` from 1.11.2 to 1.11.5. Updates `byte-buddy` from 1.11.2 to 1.11.5 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.2...byte-buddy-1.11.5) Updates `byte-buddy-agent` from 1.11.2 to 1.11.5 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.2...byte-buddy-1.11.5) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e3131b1c7b..4e24ae23cbf 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.2 + 1.11.5 1.2.0 5.3.0 0.0.10 From 1fdf4dd964e793d72c021726c370d38340d74966 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 22 Jun 2021 09:04:00 +0200 Subject: [PATCH 005/123] Bump minor version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4e24ae23cbf..1f89beacbd7 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 assertj-core - 3.20.3-SNAPSHOT + 3.21.0-SNAPSHOT jar AssertJ fluent assertions Rich and fluent assertions for testing for Java From 941002f383b6189bbe9712cead8b1bd3ef03f475 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 22 Jun 2021 23:13:08 +0200 Subject: [PATCH 006/123] Fix URLs for actions badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3739095b67..5fb752b3232 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # AssertJ - Fluent assertions for java -[![Github CI status](https://github.com/assertj/assertj-core/workflows/CI/badge.svg)](https://github.com/assertj/assertj-core/actions?query=workflow%3ACI) -[![Github Cross-Version status](https://github.com/assertj/assertj-core/workflows/Cross-Version/badge.svg)](https://github.com/assertj/assertj-core/actions?query=workflow%3ACross-Version) +[![Github CI status](https://github.com/assertj/assertj-core/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/assertj/assertj-core/actions/workflows/main.yml?query=branch%3Amain) +[![Github Cross-Version status](https://github.com/assertj/assertj-core/actions/workflows/cross-version.yml/badge.svg?branch=main)](https://github.com/assertj/assertj-core/actions/workflows/cross-version.yml?query=branch%3Amain) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.assertj/assertj-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.assertj/assertj-core) [![Javadocs](http://www.javadoc.io/badge/org.assertj/assertj-core.svg)](http://www.javadoc.io/doc/org.assertj/assertj-core) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=joel-costigliola_assertj-core&metric=alert_status)](https://sonarcloud.io/dashboard?id=joel-costigliola_assertj-core) From f638a41f5058cb00758fa9aaf92d6dedc2f02ff3 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 23 Jun 2021 12:55:23 +0200 Subject: [PATCH 007/123] Add binary compatibility check of `main` against latest release (#2271) --- .github/workflows/binary-compatibility.yml | 35 ++++++++++++++++++ CONTRIBUTING.md | 17 +++++++++ README.md | 1 + pom.xml | 41 +++++++++++++++++++++- 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/binary-compatibility.yml diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml new file mode 100644 index 00000000000..32cc5357f3b --- /dev/null +++ b/.github/workflows/binary-compatibility.yml @@ -0,0 +1,35 @@ +name: Binary Compatibility + +on: + push: + branches: [ main ] + +jobs: + japicmp: + name: Compare with the latest release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Java + uses: actions/setup-java@v2 + with: + distribution: 'zulu' + java-version: 11 + - name: Cache Maven Repository + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-maven + - name: Compare + run: > + ./mvnw -V --no-transfer-progress -e package japicmp:cmp + -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true + - name: Print Result + run: cat target/japicmp/default-cli.diff + - name: Upload Reports + uses: actions/upload-artifact@v2 + with: + name: japicmp + path: target/japicmp + if-no-files-found: error diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 75e3ae94ad6..af56be01f64 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -122,6 +122,23 @@ BAD! (not in the same line) To be sure of what the javadoc actually looks, simply generate it and read it in your browser. +## Binary compatibility + +Try to keep binary compatibility whenever possible. It means that you can safely: +* Rewrite the body of methods, constructors, and initializers (like static blocks). +* Rewrite code in the above that previously threw exceptions to no longer do so. +* Add fields, methods, and constructors. +* Delete elements declared private. +* Reorder fields, methods, and constructors. +* Move a method higher in a class hierarchy. +* Reorder the list of direct super-interfaces in a class or interface. +* Insert new class or interface types in a type hierarchy. +* Add generics (since the compiler erases them). +* Update package-private elements. + +Other changes could compromise binary compatibility. +These are not automatically rejected, but we will carefully evaluate each of them to weigh all the pros and cons. + ## Legal stuff: Project license(s): Apache License Version 2.0 diff --git a/README.md b/README.md index 5fb752b3232..8c70db9b8b3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Github CI status](https://github.com/assertj/assertj-core/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/assertj/assertj-core/actions/workflows/main.yml?query=branch%3Amain) [![Github Cross-Version status](https://github.com/assertj/assertj-core/actions/workflows/cross-version.yml/badge.svg?branch=main)](https://github.com/assertj/assertj-core/actions/workflows/cross-version.yml?query=branch%3Amain) +[![Binary Compatibility](https://github.com/assertj/assertj-core/actions/workflows/binary-compatibility.yml/badge.svg?branch=main)](https://github.com/assertj/assertj-core/actions/workflows/binary-compatibility.yml?query=branch%3Amain) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.assertj/assertj-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.assertj/assertj-core) [![Javadocs](http://www.javadoc.io/badge/org.assertj/assertj-core.svg)](http://www.javadoc.io/doc/org.assertj/assertj-core) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=joel-costigliola_assertj-core&metric=alert_status)](https://sonarcloud.io/dashboard?id=joel-costigliola_assertj-core) diff --git a/pom.xml b/pom.xml index 1f89beacbd7..cf53e5d9842 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ -html5 --allow-script-in-comments --no-module-directories 1.11.5 + 2.2 1.2.0 5.3.0 0.0.10 @@ -52,7 +53,7 @@ org.hamcrest hamcrest - 2.2 + ${hamcrest.version} org.opentest4j @@ -670,6 +671,44 @@ + + com.github.siom79.japicmp + japicmp-maven-plugin + 0.15.3 + + + + junit + junit + ${junit.version} + + + org.hamcrest + hamcrest + ${hamcrest.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + + + org.opentest4j + opentest4j + ${opentest4j.version} + + + + + org.assertj.core.internal + + true + true + true + + true + + From e8e221dafb69c88b64bddb8accd497e26c1635ee Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 23 Jun 2021 01:14:20 +0200 Subject: [PATCH 008/123] Use custom display name generator instead of `@DisplayName` on each test --- CONTRIBUTING.md | 2 -- ...tAssert_usingRecursiveComparison_Test.java | 2 -- ...sNotCloseTo_with_Long_and_Offset_Test.java | 2 -- ...CloseTo_with_Long_and_Percentage_Test.java | 2 -- ...derAssert_usingDefaultComparator_Test.java | 2 -- ...ssert_containsOnlyOnceElementsOf_Test.java | 2 -- ...DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- ...olean2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../Boolean2DArrayAssert_isEmpty_Test.java | 2 -- ...DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- .../Byte2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../Byte2DArrayAssert_isEmpty_Test.java | 2 -- .../Byte2DArrayAssert_isNullOrEmpty_Test.java | 2 -- ...rrayAssert_usingCustomComparator_Test.java | 2 -- .../ByteArrayAssert_asString_Test.java | 2 -- ...rt_containsAnyOf_with_Byte_array_Test.java | 2 -- ..._containsExactly_with_Byte_array_Test.java | 2 -- ...containsOnlyOnce_with_Byte_array_Test.java | 2 -- ...ert_containsOnly_with_Byte_array_Test.java | 2 -- ...containsSequence_with_Byte_array_Test.java | 2 -- ...tainsSubsequence_with_Byte_array_Test.java | 2 -- ...yAssert_contains_with_Byte_array_Test.java | 2 -- ...t_doesNotContain_with_Byte_array_Test.java | 2 -- .../ByteArrayAssert_encodedAsBase64_Test.java | 2 -- ...ssert_startsWith_with_Byte_array_Test.java | 2 -- .../Char2DArrayAssert_hasDimensions_Test.java | 2 -- ...DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- .../Char2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../Char2DArrayAssert_isEmpty_Test.java | 2 -- .../Char2DArrayAssert_isNullOrEmpty_Test.java | 2 -- ...rrayAssert_usingCustomComparator_Test.java | 2 -- ...ntainsAnyOf_with_Character_array_Test.java | 2 -- ...yInAnyOrder_with_Character_array_Test.java | 2 -- ...ainsExactly_with_Character_array_Test.java | 2 -- ...insOnlyOnce_with_Character_array_Test.java | 2 -- ...insSequence_with_Character_array_Test.java | 2 -- ...Subsequence_with_Character_array_Test.java | 2 -- ...rt_contains_with_Character_array_Test.java | 2 -- ...sNotContain_with_Character_array_Test.java | 2 -- ..._startsWith_with_Character_array_Test.java | 2 -- .../ClassAssert_hasNoSuperclass_Test.java | 2 -- ...ssAssert_hasPackage_with_Package_Test.java | 2 -- ...assAssert_hasPackage_with_String_Test.java | 2 -- .../ClassAssert_hasSuperclass_Test.java | 2 -- .../ClassAssert_isPackagePrivate_Test.java | 2 -- ...DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- .../DoubleAssert_isNotFinite_Test.java | 2 -- .../DoubleAssert_isNotInfinite_Test.java | 2 -- ..._containsAnyOf_with_Double_array_Test.java | 2 -- ...t_containsOnly_with_Double_array_Test.java | 2 -- ...ntainsSequence_with_Double_array_Test.java | 2 -- ...insSubsequence_with_Double_array_Test.java | 2 -- ...ssert_endsWith_with_Double_array_Test.java | 2 -- .../duration/DurationAssert_hasDays_Test.java | 2 -- ...DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- .../Float2DArrayAssert_isEmpty_Test.java | 2 -- .../Float2DArrayAssert_isNotEmpty_Test.java | 2 -- ...rrayAssert_usingCustomComparator_Test.java | 2 -- .../float_/FloatAssert_isNotFinite_Test.java | 2 -- ...t_containsAnyOf_with_Float_array_Test.java | 2 -- ...actlyInAnyOrder_with_Float_array_Test.java | 2 -- ...containsExactly_with_Float_array_Test.java | 2 -- ...ontainsOnlyOnce_with_Float_array_Test.java | 2 -- ...ainsSubsequence_with_Float_array_Test.java | 2 -- ...Assert_contains_with_Float_array_Test.java | 2 -- ..._doesNotContain_with_Float_array_Test.java | 2 -- ...Assert_endsWith_with_Float_array_Test.java | 2 -- ...sert_startsWith_with_Float_array_Test.java | 2 -- ...ompletableFutureAssert_hasFailed_Test.java | 2 -- ...letableFutureAssert_hasNotFailed_Test.java | 2 -- .../CompletableFutureAssert_isDone_Test.java | 2 -- ...tableFutureAssert_isNotCancelled_Test.java | 2 -- ...tableFutureAssert_isNotCompleted_Test.java | 2 -- ...ompletableFutureAssert_isNotDone_Test.java | 2 -- ...tableFutureAssert_succeedsWithin_Test.java | 2 -- .../future/FutureAssert_failsWithin_Test.java | 2 -- .../InputStreamAssert_isEmpty_Test.java | 2 -- ...DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- .../Long2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../Long2DArrayAssert_isEmpty_Test.java | 2 -- .../Long2DArrayAssert_isNotEmpty_Test.java | 2 -- .../Long2DArrayAssert_isNullOrEmpty_Test.java | 2 -- ...rrayAssert_usingCustomComparator_Test.java | 2 -- ...t_containsOnlyKeys_with_Iterable_Test.java | 1 - ...ptionalAssert_containsInstanceOf_Test.java | 2 -- .../api/optional/OptionalAssert_get_Test.java | 2 -- ...get_with_InstanceOfAssertFactory_Test.java | 2 -- .../Maps_assertContainsOnlyKeys_Test.java | 2 -- .../jupiter/DefaultDisplayNameGenerator.java | 20 ++++++++++++ .../DefaultDisplayNameGeneratorTest.java | 32 +++++++++++++++++++ src/test/resources/junit-platform.properties | 2 +- 91 files changed, 53 insertions(+), 176 deletions(-) create mode 100644 src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java create mode 100644 src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af56be01f64..0c1ad50c63e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,6 @@ We appreciate your effort and to make sure that your pull request is easy to rev * Write complete Javadocs for each assertion method and include a code example (succeeding and failing assertion(s)). * As we use JUnit 5, favor `package-private` visibility for both test classes and test methods. * Write one JUnit test class for each assertion method with the following naming convention: `__Test`. -* Use `@DisplayName` on the test class - see `OptionalAssert_containsInstanceOf_Test` as an example. * Write unit test assertions with AssertJ! Let's eat our own dog food. * Unit tests method naming convention is underscore-based (like python) and not camel-case, we find it is much readable for long test names! * Successful assertion unit test method names should start with: `should_pass_xxx` (if you find a better test name, use your best judgment and go for it!) @@ -27,7 +26,6 @@ import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; // other imports not shown for brevity -@DisplayName("OptionalAssert containsInstanceOf") class OptionalAssert_containsInstanceOf_Test extends BaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/AbstractAssert_usingRecursiveComparison_Test.java b/src/test/java/org/assertj/core/api/AbstractAssert_usingRecursiveComparison_Test.java index 6e600b1ecfc..97d630cc9ac 100644 --- a/src/test/java/org/assertj/core/api/AbstractAssert_usingRecursiveComparison_Test.java +++ b/src/test/java/org/assertj/core/api/AbstractAssert_usingRecursiveComparison_Test.java @@ -17,10 +17,8 @@ import static org.assertj.core.presentation.UnicodeRepresentation.UNICODE_REPRESENTATION; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("AbstractAssert usingRecursiveComparison") class AbstractAssert_usingRecursiveComparison_Test { @Test diff --git a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Offset_Test.java b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Offset_Test.java index 972024a34d5..1bce4a8b00b 100644 --- a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Offset_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Offset_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.LongAdderAssert; import org.assertj.core.api.LongAdderAssertBaseTest; import org.assertj.core.data.Offset; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link LongAdderAssert#isNotCloseTo(Long, Offset)}. * * @author Stefano Cordio */ -@DisplayName("LongAdderAssert isNotCloseTo(Long, Offset)") class LongAdderAssert_isNotCloseTo_with_Long_and_Offset_Test extends LongAdderAssertBaseTest { private final long value = 10L; diff --git a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Percentage_Test.java b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Percentage_Test.java index 34ead0c41b6..7fc1d2c4ec7 100644 --- a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Percentage_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_isNotCloseTo_with_Long_and_Percentage_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.LongAdderAssert; import org.assertj.core.api.LongAdderAssertBaseTest; import org.assertj.core.data.Percentage; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link LongAdderAssert#isNotCloseTo(Long, Percentage)}. * * @author Stefano Cordio */ -@DisplayName("LongAdderAssert isNotCloseTo(Long, Percentage)") class LongAdderAssert_isNotCloseTo_with_Long_and_Percentage_Test extends LongAdderAssertBaseTest { private final long value = 10L; diff --git a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingDefaultComparator_Test.java b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingDefaultComparator_Test.java index f719b255b8d..6f16d5cab25 100644 --- a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingDefaultComparator_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingDefaultComparator_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.internal.Longs; import org.assertj.core.internal.Objects; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -32,7 +31,6 @@ * * @author Stefano Cordio */ -@DisplayName("LongAdderAssert usingDefaultComparator") @ExtendWith(MockitoExtension.class) class LongAdderAssert_usingDefaultComparator_Test extends LongAdderAssertBaseTest { diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_containsOnlyOnceElementsOf_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_containsOnlyOnceElementsOf_Test.java index 205d2d4368d..7f0c575827b 100644 --- a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_containsOnlyOnceElementsOf_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_containsOnlyOnceElementsOf_Test.java @@ -19,14 +19,12 @@ import org.assertj.core.api.AtomicReferenceArrayAssert; import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link AtomicReferenceArrayAssert#containsOnlyOnceElementsOf(Iterable)}. * * @author CAL027 */ -@DisplayName("AtomicReferenceArrayAssert containsOnlyOnceElementsOf") class AtomicReferenceArrayAssert_containsOnlyOnceElementsOf_Test extends AtomicReferenceArrayAssertBaseTest { private final List values = newArrayList("Yoda", "Luke"); diff --git a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_hasSameDimensionsAs_Test.java index 4b01816fc9c..6550ca9cc50 100644 --- a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_hasSameDimensionsAs_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Boolean2DArrayAssert; import org.assertj.core.api.Boolean2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Boolean2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Boolean2DArrayAssert hasSameDimensionsAs") class Boolean2DArrayAssert_hasSameDimensionsAs_Test extends Boolean2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isDeepEqualTo_Test.java index 2f18e2c12ab..1bb52fac044 100644 --- a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isDeepEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.Boolean2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Boolean2DArrayAssert isDeepEqualTo") class Boolean2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isEmpty_Test.java index a08834565d6..4a462c90a26 100644 --- a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Boolean2DArrayAssert; import org.assertj.core.api.Boolean2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Boolean2DArrayAssert isEmpty") class Boolean2DArrayAssert_isEmpty_Test extends Boolean2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_hasSameDimensionsAs_Test.java index 35156a07d89..f745e9eeacd 100644 --- a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_hasSameDimensionsAs_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Byte2DArrayAssert; import org.assertj.core.api.Byte2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Byte2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Byte2DArrayAssert assertHasSameDimensionsAs") class Byte2DArrayAssert_hasSameDimensionsAs_Test extends Byte2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isDeepEqualTo_Test.java index 995f1d83b97..d59267cdecd 100644 --- a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isDeepEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.Byte2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Byte2DArrayAssert isDeepEqualTo") class Byte2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isEmpty_Test.java index 6728dc76ac2..9a86719bab1 100644 --- a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Byte2DArrayAssert; import org.assertj.core.api.Byte2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Byte2DArrayAssert isEmpty") class Byte2DArrayAssert_isEmpty_Test extends Byte2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNullOrEmpty_Test.java index 236c2e2ca86..ffd6bf28de5 100644 --- a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Byte2DArrayAssert; import org.assertj.core.api.Byte2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Byte2DArrayAssert isNullOrEmpty") class Byte2DArrayAssert_isNullOrEmpty_Test extends Byte2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_usingCustomComparator_Test.java index 5b390d8eec9..f6442a7008c 100644 --- a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Byte2DArrayAssert; import org.assertj.core.api.Byte2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Byte2DArrayAssert usingCustomComparator") class Byte2DArrayAssert_usingCustomComparator_Test extends Byte2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_asString_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_asString_Test.java index 7efba53c227..f52171cdaa5 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_asString_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_asString_Test.java @@ -22,11 +22,9 @@ import org.assertj.core.api.SoftAssertions; import org.assertj.core.error.AssertJMultipleFailuresError; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.opentest4j.AssertionFailedError; -@DisplayName("ByteArrayAssert asString") class ByteArrayAssert_asString_Test { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsAnyOf_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsAnyOf_with_Byte_array_Test.java index 84abac4dca7..5a80cbdd700 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsAnyOf_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsAnyOf_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert containsAnyOf(Byte[])") class ByteArrayAssert_containsAnyOf_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsExactly_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsExactly_with_Byte_array_Test.java index 75f81df4557..050c4d038de 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsExactly_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsExactly_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert containsExactly(Byte[])") class ByteArrayAssert_containsExactly_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnlyOnce_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnlyOnce_with_Byte_array_Test.java index 37da632c2a9..769df0df7ac 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnlyOnce_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnlyOnce_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert containsOnlyOnce(Byte[])") class ByteArrayAssert_containsOnlyOnce_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnly_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnly_with_Byte_array_Test.java index 946ce8fd849..d66bc37f6c4 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnly_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsOnly_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert containsOnly(Byte[])") class ByteArrayAssert_containsOnly_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSequence_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSequence_with_Byte_array_Test.java index 3f9be08b215..b07815dd145 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSequence_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSequence_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert containsSequence(Byte[])") class ByteArrayAssert_containsSequence_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSubsequence_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSubsequence_with_Byte_array_Test.java index 10ab96a8c61..c4f9a51f8e0 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSubsequence_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_containsSubsequence_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert containsSubsequence(Byte[])") class ByteArrayAssert_containsSubsequence_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_contains_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_contains_with_Byte_array_Test.java index 8defab8cc97..c68dd011b4c 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_contains_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_contains_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert contains(Byte[])") class ByteArrayAssert_contains_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_doesNotContain_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_doesNotContain_with_Byte_array_Test.java index e783d1e0ec9..dacc4c71caa 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_doesNotContain_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_doesNotContain_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert doesNotContain(Byte[])") class ByteArrayAssert_doesNotContain_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_encodedAsBase64_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_encodedAsBase64_Test.java index 670c76cc575..a8ca853e657 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_encodedAsBase64_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_encodedAsBase64_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; import org.assertj.core.api.NavigationMethodBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("ByteArrayAssert encodedAsBase64") class ByteArrayAssert_encodedAsBase64_Test extends ByteArrayAssertBaseTest implements NavigationMethodBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_startsWith_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_startsWith_with_Byte_array_Test.java index 9f769f9aa3f..d761ef7e3c4 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_startsWith_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_startsWith_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert startsWith(Byte[])") class ByteArrayAssert_startsWith_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasDimensions_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasDimensions_Test.java index c8665231bc6..c4116797f65 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasDimensions_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasDimensions_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.api.Char2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Char2DArrayAssert#hasDimensions(int, int)}. * * @author Maciej Wajcht */ -@DisplayName("Char2DArrayAssert hasSize") class Char2DArrayAssert_hasDimensions_Test extends Char2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasSameDimensionsAs_Test.java index 3deeb0f074c..b4d83a3890e 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_hasSameDimensionsAs_Test.java @@ -17,14 +17,12 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.api.Char2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Char2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Char2DArrayAssert hasSameDimensionsAs") class Char2DArrayAssert_hasSameDimensionsAs_Test extends Char2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isDeepEqualTo_Test.java index 2d51f03d5ec..016a1418c07 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isDeepEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Char2DArrayAssert isDeepEqualTo") class Char2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isEmpty_Test.java index c1f174b7149..e0dfffdd285 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.api.Char2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Char2DArrayAssert isEmpty") class Char2DArrayAssert_isEmpty_Test extends Char2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNullOrEmpty_Test.java index 5f2ba38602e..a8d630a96a8 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.api.Char2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Char2DArrayAssert isNullOrEmpty") class Char2DArrayAssert_isNullOrEmpty_Test extends Char2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_usingCustomComparator_Test.java index cf3d9c98190..08bcfbad709 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.api.Char2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Char2DArrayAssert usingCustomComparator") class Char2DArrayAssert_usingCustomComparator_Test extends Char2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsAnyOf_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsAnyOf_with_Character_array_Test.java index c826107f75c..bc7c7069921 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsAnyOf_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsAnyOf_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharArrayAssert containsAnyOf(Character[])") class CharArrayAssert_containsAnyOf_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactlyInAnyOrder_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactlyInAnyOrder_with_Character_array_Test.java index cce6ec472fc..14942a68664 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactlyInAnyOrder_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactlyInAnyOrder_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert containsExactlyInAnyOrder(Character[])") class CharArrayAssert_containsExactlyInAnyOrder_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactly_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactly_with_Character_array_Test.java index 95fdac5b15b..f9850fa789f 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactly_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsExactly_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert containsExactly(Character[])") class CharArrayAssert_containsExactly_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnlyOnce_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnlyOnce_with_Character_array_Test.java index e7b1172cc49..5893a2f65af 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnlyOnce_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnlyOnce_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert containsOnlyOnce(Character[])") class CharArrayAssert_containsOnlyOnce_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSequence_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSequence_with_Character_array_Test.java index 3740281b44c..59a752942b9 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSequence_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSequence_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert containsSequence(Character[])") class CharArrayAssert_containsSequence_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSubsequence_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSubsequence_with_Character_array_Test.java index 02485b4cb8e..933b81177c9 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSubsequence_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsSubsequence_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert containsSubsequence(Character[])") class CharArrayAssert_containsSubsequence_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_contains_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_contains_with_Character_array_Test.java index a2035966a13..29fd06c2030 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_contains_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_contains_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert contains(Character[])") class CharArrayAssert_contains_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_doesNotContain_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_doesNotContain_with_Character_array_Test.java index a66c495b83f..524b4f2fe8b 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_doesNotContain_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_doesNotContain_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert doesNotContain(Character[])") class CharArrayAssert_doesNotContain_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_startsWith_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_startsWith_with_Character_array_Test.java index d13834619af..b0c03d2ff76 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_startsWith_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_startsWith_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert startsWith(Character[])") class CharArrayAssert_startsWith_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasNoSuperclass_Test.java b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasNoSuperclass_Test.java index 27d5c5b25b8..3a159016e61 100644 --- a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasNoSuperclass_Test.java +++ b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasNoSuperclass_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.ClassAssert; import org.assertj.core.api.ClassAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link ClassAssert#hasNoSuperclass()}. * * @author Stefano Cordio */ -@DisplayName("ClassAssert hasNoSuperclass") class ClassAssert_hasNoSuperclass_Test extends ClassAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_Package_Test.java b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_Package_Test.java index f33b6c0b028..a1fd6fea8c1 100644 --- a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_Package_Test.java +++ b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_Package_Test.java @@ -17,14 +17,12 @@ import org.assertj.core.api.ClassAssert; import org.assertj.core.api.ClassAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link ClassAssert#hasPackage(Package)}. * * @author Matteo Mirk */ -@DisplayName("ClassAssert hasPackage(Package)") class ClassAssert_hasPackage_with_Package_Test extends ClassAssertBaseTest { private static final Package PACKAGE = mock(Package.class); diff --git a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_String_Test.java b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_String_Test.java index c5f89db511b..cf51f1ebd8f 100644 --- a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_String_Test.java +++ b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasPackage_with_String_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.ClassAssert; import org.assertj.core.api.ClassAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link ClassAssert#hasPackage(String)}. * * @author Matteo Mirk */ -@DisplayName("ClassAssert hasPackage(String)") class ClassAssert_hasPackage_with_String_Test extends ClassAssertBaseTest { private static final String PACKAGE = "org.assertj.core.api"; diff --git a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasSuperclass_Test.java b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasSuperclass_Test.java index e69103a5057..5964bd97687 100644 --- a/src/test/java/org/assertj/core/api/classes/ClassAssert_hasSuperclass_Test.java +++ b/src/test/java/org/assertj/core/api/classes/ClassAssert_hasSuperclass_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.ClassAssert; import org.assertj.core.api.ClassAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link ClassAssert#hasSuperclass(Class)}. * * @author Stefano Cordio */ -@DisplayName("ClassAssert hasSuperclass") class ClassAssert_hasSuperclass_Test extends ClassAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/classes/ClassAssert_isPackagePrivate_Test.java b/src/test/java/org/assertj/core/api/classes/ClassAssert_isPackagePrivate_Test.java index a5a7aed6968..070842265b4 100644 --- a/src/test/java/org/assertj/core/api/classes/ClassAssert_isPackagePrivate_Test.java +++ b/src/test/java/org/assertj/core/api/classes/ClassAssert_isPackagePrivate_Test.java @@ -16,12 +16,10 @@ import org.assertj.core.api.ClassAssert; import org.assertj.core.api.ClassAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link ClassAssert#isPackagePrivate()}. */ -@DisplayName("ClassAssert isPackagePrivate") class ClassAssert_isPackagePrivate_Test extends ClassAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasSameDimensionsAs_Test.java index 522fc7e3584..b84747d67cb 100644 --- a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasSameDimensionsAs_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Double2DArrayAssert; import org.assertj.core.api.Double2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Double2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Double2DArrayAssert hasSameDimensionsAs") class Double2DArrayAssert_hasSameDimensionsAs_Test extends Double2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotFinite_Test.java b/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotFinite_Test.java index 93330347b39..c6a30f718a4 100644 --- a/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotFinite_Test.java +++ b/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotFinite_Test.java @@ -16,9 +16,7 @@ import org.assertj.core.api.DoubleAssert; import org.assertj.core.api.DoubleAssertBaseTest; -import org.junit.jupiter.api.DisplayName; -@DisplayName("DoubleAssert isNotFinite") class DoubleAssert_isNotFinite_Test extends DoubleAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotInfinite_Test.java b/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotInfinite_Test.java index fad54858923..ae064759b92 100644 --- a/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotInfinite_Test.java +++ b/src/test/java/org/assertj/core/api/double_/DoubleAssert_isNotInfinite_Test.java @@ -16,9 +16,7 @@ import org.assertj.core.api.DoubleAssert; import org.assertj.core.api.DoubleAssertBaseTest; -import org.junit.jupiter.api.DisplayName; -@DisplayName("DoubleAssert isNotInfinite") class DoubleAssert_isNotInfinite_Test extends DoubleAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsAnyOf_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsAnyOf_with_Double_array_Test.java index 96071e5663c..1d00a579980 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsAnyOf_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsAnyOf_with_Double_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert containsAnyOf(Double[])") class DoubleArrayAssert_containsAnyOf_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnly_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnly_with_Double_array_Test.java index 706c2883242..57e1a435dff 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnly_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnly_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert containsOnly(Double[])") class DoubleArrayAssert_containsOnly_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSequence_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSequence_with_Double_array_Test.java index 365aba5d69d..007dc395b6d 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSequence_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSequence_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert containsSequence(Double[])") class DoubleArrayAssert_containsSequence_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSubsequence_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSubsequence_with_Double_array_Test.java index e4808ae39f3..de960cb60a7 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSubsequence_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsSubsequence_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("BooleanArrayAssert containsSubsequence(Boolean[])") class DoubleArrayAssert_containsSubsequence_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_endsWith_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_endsWith_with_Double_array_Test.java index 9a90439ea49..820dcbe98aa 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_endsWith_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_endsWith_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert endsWith(Double[])") class DoubleArrayAssert_endsWith_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/duration/DurationAssert_hasDays_Test.java b/src/test/java/org/assertj/core/api/duration/DurationAssert_hasDays_Test.java index c9384958537..8c1802facfb 100644 --- a/src/test/java/org/assertj/core/api/duration/DurationAssert_hasDays_Test.java +++ b/src/test/java/org/assertj/core/api/duration/DurationAssert_hasDays_Test.java @@ -20,13 +20,11 @@ import java.time.Duration; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** * @author Filip Hrisafov */ -@DisplayName("DurationAssert hasDays") class DurationAssert_hasDays_Test { @Test diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasSameDimensionsAs_Test.java index ebb0331735c..bcee56d737f 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasSameDimensionsAs_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.api.Float2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Float2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Float2DArrayAssert hasSameDimensionsAs") class Float2DArrayAssert_hasSameDimensionsAs_Test extends Float2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isEmpty_Test.java index 923df487701..2e5a3ce52a3 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.api.Float2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Float2DArrayAssert isEmpty") class Float2DArrayAssert_isEmpty_Test extends Float2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNotEmpty_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNotEmpty_Test.java index 2fddecf8dea..2c781665632 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNotEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNotEmpty_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.api.Float2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Float2DArrayAssert#isNotEmpty()}. * * @author Maciej Wajcht */ -@DisplayName("Float2DArrayAssert isNotEmpty") class Float2DArrayAssert_isNotEmpty_Test extends Float2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_usingCustomComparator_Test.java index a9282b08bc5..40a06f1a31c 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.api.Float2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Float2DArrayAssert usingCustomComparator") class Float2DArrayAssert_usingCustomComparator_Test extends Float2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/float_/FloatAssert_isNotFinite_Test.java b/src/test/java/org/assertj/core/api/float_/FloatAssert_isNotFinite_Test.java index b5e2d399bef..769e0523bde 100644 --- a/src/test/java/org/assertj/core/api/float_/FloatAssert_isNotFinite_Test.java +++ b/src/test/java/org/assertj/core/api/float_/FloatAssert_isNotFinite_Test.java @@ -16,9 +16,7 @@ import org.assertj.core.api.FloatAssert; import org.assertj.core.api.FloatAssertBaseTest; -import org.junit.jupiter.api.DisplayName; -@DisplayName("FloatAssert isNotFinite") class FloatAssert_isNotFinite_Test extends FloatAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsAnyOf_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsAnyOf_with_Float_array_Test.java index 4b94c022dca..69ca65bfbc2 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsAnyOf_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsAnyOf_with_Float_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsAnyOf(Float[])") class FloatArrayAssert_containsAnyOf_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactlyInAnyOrder_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactlyInAnyOrder_with_Float_array_Test.java index c1932c7d577..5c689eb4c9e 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactlyInAnyOrder_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactlyInAnyOrder_with_Float_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsExactlyInAnyOrder(Float[])") class FloatArrayAssert_containsExactlyInAnyOrder_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactly_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactly_with_Float_array_Test.java index 10a1a57a6d1..621982fcd85 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactly_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsExactly_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsExactly(Float[])") class FloatArrayAssert_containsExactly_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnlyOnce_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnlyOnce_with_Float_array_Test.java index f0c8177cfb4..88cc83d11cd 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnlyOnce_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnlyOnce_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsOnlyOnce(Float[])") class FloatArrayAssert_containsOnlyOnce_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSubsequence_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSubsequence_with_Float_array_Test.java index 75a706f5b4c..58b9d1dcef0 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSubsequence_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSubsequence_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsSubsequence(Float[])") class FloatArrayAssert_containsSubsequence_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_contains_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_contains_with_Float_array_Test.java index 6c1e606b72c..f5e3d8ea300 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_contains_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_contains_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert contains(Float[])") class FloatArrayAssert_contains_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_doesNotContain_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_doesNotContain_with_Float_array_Test.java index ca61fb7d0e7..cb56ed9c1b7 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_doesNotContain_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_doesNotContain_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert doesNotContain(Float[])") class FloatArrayAssert_doesNotContain_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_endsWith_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_endsWith_with_Float_array_Test.java index a7eb676ab10..be1c3133288 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_endsWith_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_endsWith_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert endsWith(Float[])") class FloatArrayAssert_endsWith_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_startsWith_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_startsWith_with_Float_array_Test.java index 5f8068b3cec..beeaa9247c0 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_startsWith_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_startsWith_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert startsWith(Float[])") class FloatArrayAssert_startsWith_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasFailed_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasFailed_Test.java index 4c201cc10a8..c4555c4941e 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasFailed_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasFailed_Test.java @@ -21,11 +21,9 @@ import java.util.concurrent.CompletableFuture; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") -@DisplayName("CompletableFutureAssert hasFailed") class CompletableFutureAssert_hasFailed_Test { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasNotFailed_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasNotFailed_Test.java index a94d2063aa5..f19a0b70243 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasNotFailed_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_hasNotFailed_Test.java @@ -21,11 +21,9 @@ import java.util.concurrent.CompletableFuture; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") -@DisplayName("CompletableFutureAssert hasNotFailed") class CompletableFutureAssert_hasNotFailed_Test { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isDone_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isDone_Test.java index 4c230a7c1ee..0a1eb28f986 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isDone_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isDone_Test.java @@ -20,10 +20,8 @@ import java.util.concurrent.CompletableFuture; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("CompletableFutureAssert isDone") class CompletableFutureAssert_isDone_Test { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCancelled_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCancelled_Test.java index dbb740037b4..160ad030976 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCancelled_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCancelled_Test.java @@ -20,10 +20,8 @@ import java.util.concurrent.CompletableFuture; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("CompletableFutureAssert isNotCancelled") class CompletableFutureAssert_isNotCancelled_Test { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCompleted_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCompleted_Test.java index ff498f84c1a..d258e1d9d51 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCompleted_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotCompleted_Test.java @@ -20,10 +20,8 @@ import java.util.concurrent.CompletableFuture; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("CompletableFutureAssert isNotCompleted") class CompletableFutureAssert_isNotCompleted_Test { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotDone_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotDone_Test.java index 34274c695b3..fde4d8dbcae 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotDone_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_isNotDone_Test.java @@ -20,10 +20,8 @@ import java.util.concurrent.CompletableFuture; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("CompletableFutureAssert isNotDone") class CompletableFutureAssert_isNotDone_Test { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_succeedsWithin_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_succeedsWithin_Test.java index 6eacc7e5369..c386ba2ad87 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_succeedsWithin_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_succeedsWithin_Test.java @@ -25,10 +25,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("CompletableFutureAssert succeedsWithin") class CompletableFutureAssert_succeedsWithin_Test extends AbstractFutureTest { @Test diff --git a/src/test/java/org/assertj/core/api/future/FutureAssert_failsWithin_Test.java b/src/test/java/org/assertj/core/api/future/FutureAssert_failsWithin_Test.java index d89d6c5bd69..55ec97c2b2a 100644 --- a/src/test/java/org/assertj/core/api/future/FutureAssert_failsWithin_Test.java +++ b/src/test/java/org/assertj/core/api/future/FutureAssert_failsWithin_Test.java @@ -25,10 +25,8 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("FutureAssert failsWithin") class FutureAssert_failsWithin_Test extends AbstractFutureTest { private static final Duration ONE_SECOND = Duration.ofSeconds(1); diff --git a/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isEmpty_Test.java index 07d9c16361d..076fdb203ae 100644 --- a/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isEmpty_Test.java @@ -16,12 +16,10 @@ import org.assertj.core.api.InputStreamAssert; import org.assertj.core.api.InputStreamAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link InputStreamAssert#isEmpty()}. */ -@DisplayName("InputStreamAssert isEmpty") class InputStreamAssert_isEmpty_Test extends InputStreamAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasSameDimensionsAs_Test.java index 095db7ffa97..fe475ad5796 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasSameDimensionsAs_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.api.Long2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Long2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Long2DArrayAssert hasSameDimensionsAs") class Long2DArrayAssert_hasSameDimensionsAs_Test extends Long2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isDeepEqualTo_Test.java index d4167c2adab..078bd7090da 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isDeepEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Long2DArrayAssert isDeepEqualTo") class Long2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isEmpty_Test.java index 78fdf083ab1..e87474626a4 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.api.Long2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Long2DArrayAssert isEmpty") class Long2DArrayAssert_isEmpty_Test extends Long2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNotEmpty_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNotEmpty_Test.java index b0b8e908fe0..c34fd416911 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNotEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNotEmpty_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.api.Long2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Long2DArrayAssert#isNotEmpty()}. * * @author Maciej Wajcht */ -@DisplayName("Long2DArrayAssert isNotEmpty") class Long2DArrayAssert_isNotEmpty_Test extends Long2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNullOrEmpty_Test.java index 9990db2ff84..6cf80ebb50d 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.api.Long2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Long2DArrayAssert isNullOrEmpty") class Long2DArrayAssert_isNullOrEmpty_Test extends Long2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_usingCustomComparator_Test.java index c24c0caa296..822ebde3ad7 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.api.Long2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Long2DArrayAssert usingCustomComparator") class Long2DArrayAssert_usingCustomComparator_Test extends Long2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/map/MapAssert_containsOnlyKeys_with_Iterable_Test.java b/src/test/java/org/assertj/core/api/map/MapAssert_containsOnlyKeys_with_Iterable_Test.java index 67005b869a2..75760cb0aec 100644 --- a/src/test/java/org/assertj/core/api/map/MapAssert_containsOnlyKeys_with_Iterable_Test.java +++ b/src/test/java/org/assertj/core/api/map/MapAssert_containsOnlyKeys_with_Iterable_Test.java @@ -30,7 +30,6 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -@DisplayName("MapAssert containsOnlyKeys(Iterable)") class MapAssert_containsOnlyKeys_with_Iterable_Test extends MapAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/optional/OptionalAssert_containsInstanceOf_Test.java b/src/test/java/org/assertj/core/api/optional/OptionalAssert_containsInstanceOf_Test.java index 6c24d2511a0..983e5ffafb0 100644 --- a/src/test/java/org/assertj/core/api/optional/OptionalAssert_containsInstanceOf_Test.java +++ b/src/test/java/org/assertj/core/api/optional/OptionalAssert_containsInstanceOf_Test.java @@ -20,10 +20,8 @@ import java.util.Optional; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("OptionalAssert containsInstanceOf") class OptionalAssert_containsInstanceOf_Test { @Test diff --git a/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_Test.java b/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_Test.java index d3fce5b8382..2d47350abbe 100644 --- a/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_Test.java +++ b/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_Test.java @@ -24,7 +24,6 @@ import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.NavigationMethodBaseTest; import org.assertj.core.api.OptionalAssert; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -32,7 +31,6 @@ * * @author Filip Hrisafov */ -@DisplayName("OptionalAssert get") class OptionalAssert_get_Test implements NavigationMethodBaseTest> { private final Optional optional = Optional.of("Frodo"); diff --git a/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_with_InstanceOfAssertFactory_Test.java b/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_with_InstanceOfAssertFactory_Test.java index 8ee35418918..b7792e1daaf 100644 --- a/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_with_InstanceOfAssertFactory_Test.java +++ b/src/test/java/org/assertj/core/api/optional/OptionalAssert_get_with_InstanceOfAssertFactory_Test.java @@ -29,7 +29,6 @@ import org.assertj.core.api.InstanceOfAssertFactory; import org.assertj.core.api.NavigationMethodBaseTest; import org.assertj.core.api.OptionalAssert; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -37,7 +36,6 @@ * * @author Stefano Cordio */ -@DisplayName("OptionalAssert get(InstanceOfAssertFactory)") class OptionalAssert_get_with_InstanceOfAssertFactory_Test implements NavigationMethodBaseTest> { private final Optional optional = Optional.of("Frodo"); diff --git a/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsOnlyKeys_Test.java b/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsOnlyKeys_Test.java index c0226dd5a11..9f1e273da28 100644 --- a/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsOnlyKeys_Test.java +++ b/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsOnlyKeys_Test.java @@ -47,7 +47,6 @@ import org.assertj.core.api.AssertionInfo; import org.assertj.core.internal.Maps; import org.assertj.core.internal.MapsBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -61,7 +60,6 @@ * * @author Christopher Arnott */ -@DisplayName("Maps assertContainsOnlyKeys(Object[])") class Maps_assertContainsOnlyKeys_Test extends MapsBaseTest { private static final Supplier> CASE_INSENSITIVE_TREE_MAP = () -> new TreeMap<>(CASE_INSENSITIVE_ORDER); diff --git a/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java new file mode 100644 index 00000000000..8db0967df22 --- /dev/null +++ b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java @@ -0,0 +1,20 @@ +package org.assertj.core.test.junit.jupiter; + +import org.junit.jupiter.api.DisplayNameGenerator; + +public class DefaultDisplayNameGenerator extends DisplayNameGenerator.ReplaceUnderscores { + + private static final String TEST_SUFFIX = " Test"; + + @Override + public String generateDisplayNameForClass(Class testClass) { + return removeTestSuffixIfExists(super.generateDisplayNameForClass(testClass)); + } + + private static String removeTestSuffixIfExists(String displayName) { + return displayName.endsWith(TEST_SUFFIX) + ? displayName.substring(0, displayName.lastIndexOf(TEST_SUFFIX)) + : displayName; + } + +} diff --git a/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java new file mode 100644 index 00000000000..f33cc9607bf --- /dev/null +++ b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java @@ -0,0 +1,32 @@ +package org.assertj.core.test.junit.jupiter; + +import static org.assertj.core.api.BDDAssertions.then; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class DefaultDisplayNameGeneratorTest { + + private final DefaultDisplayNameGenerator underTest = new DefaultDisplayNameGenerator(); + + @ParameterizedTest + @CsvSource({ + "org.assertj.core.test.junit.jupiter.SomeAssert_someMethod_Test, SomeAssert someMethod", + "org.assertj.core.test.junit.jupiter.SomeAssert_someMethod_with_SomeType_Test, SomeAssert someMethod with SomeType" + }) + void generateDisplayNameForClass_should_remove_test_suffix(Class testClass, String expected) { + // WHEN + String displayName = underTest.generateDisplayNameForClass(testClass); + // THEN + then(displayName).isEqualTo(expected); + } + +} + +@SuppressWarnings("unused") +class SomeAssert_someMethod_Test { +} + +@SuppressWarnings("unused") +class SomeAssert_someMethod_with_SomeType_Test { +} diff --git a/src/test/resources/junit-platform.properties b/src/test/resources/junit-platform.properties index a5582325c97..4f656ee47aa 100644 --- a/src/test/resources/junit-platform.properties +++ b/src/test/resources/junit-platform.properties @@ -1 +1 @@ -junit.jupiter.displayname.generator.default=org.junit.jupiter.api.DisplayNameGenerator$ReplaceUnderscores \ No newline at end of file +junit.jupiter.displayname.generator.default=org.assertj.core.test.junit.jupiter.DefaultDisplayNameGenerator From 408c5b67ee60960e72040527899ee9fb0a5d710e Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 26 Jun 2021 23:36:14 +0200 Subject: [PATCH 009/123] Remove unnecessary `@DisplayName` annotation --- ...xtracting_with_Function_and_AssertFactory_Test.java | 1 - ..._extracting_with_String_and_AssertFactory_Test.java | 2 -- .../AbstractAssert_isInstanceOfSatisfying_Test.java | 4 ++-- .../LongAdderAssert_usingComparator_Test.java | 2 -- ...ferenceArrayAssert_usingComparatorForType_Test.java | 6 ++---- ...oolean2DArrayAssert_usingCustomComparator_Test.java | 2 -- ...ayAssert_containsAnyOf_with_Boolean_array_Test.java | 2 -- ...tainsExactlyInAnyOrder_with_Boolean_array_Test.java | 2 -- ...Assert_containsExactly_with_Boolean_array_Test.java | 2 -- ...ssert_containsOnlyOnce_with_Boolean_array_Test.java | 2 -- ...rayAssert_containsOnly_with_Boolean_array_Test.java | 2 -- ...ssert_containsSequence_with_Boolean_array_Test.java | 2 -- ...rt_containsSubsequence_with_Boolean_array_Test.java | 2 -- ...anArrayAssert_contains_with_Boolean_array_Test.java | 2 -- ...anArrayAssert_endsWith_with_Boolean_array_Test.java | 2 -- ...ArrayAssert_startsWith_with_Boolean_array_Test.java | 2 -- .../byte2darray/Byte2DArrayAssert_isNotEmpty_Test.java | 2 -- .../ByteArrayAssert_endsWith_with_Byte_array_Test.java | 2 -- .../char2darray/Char2DArrayAssert_isNotEmpty_Test.java | 2 -- ...yAssert_containsOnly_with_Character_array_Test.java | 2 -- ...ArrayAssert_endsWith_with_Character_array_Test.java | 2 -- .../Double2DArrayAssert_hasDimensions_Test.java | 2 -- .../Double2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../Double2DArrayAssert_isEmpty_Test.java | 2 -- .../Double2DArrayAssert_isNullOrEmpty_Test.java | 2 -- ...eAssert_isLessThanOrEqualTo_DoubleWrapper_Test.java | 4 +--- ...ntainsExactlyInAnyOrder_with_Double_array_Test.java | 2 -- ...yAssert_containsExactly_with_Double_array_Test.java | 2 -- ...Assert_containsOnlyOnce_with_Double_array_Test.java | 2 -- ...bleArrayAssert_contains_with_Double_array_Test.java | 2 -- ...ayAssert_doesNotContain_with_Double_array_Test.java | 2 -- ...eArrayAssert_startsWith_with_Double_array_Test.java | 2 -- .../api/duration/DurationAssert_isCloseTo_Test.java | 2 -- .../file/FileAssert_hasSameTextualContentAs_Test.java | 2 -- ...mptyFile_Test.java => FileAssert_isEmpty_Test.java} | 9 ++++----- ...yFile_Test.java => FileAssert_isNotEmpty_Test.java} | 9 ++++----- .../Float2DArrayAssert_hasDimensions_Test.java | 2 -- .../Float2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../Float2DArrayAssert_isNullOrEmpty_Test.java | 2 -- ...ArrayAssert_containsOnly_with_Float_array_Test.java | 2 -- ...yAssert_containsSequence_with_Float_array_Test.java | 2 -- .../CompletableFutureAssert_failsWithin_Test.java | 6 ++---- .../api/future/FutureAssert_succeedsWithin_Test.java | 2 -- .../inputstream/InputStreamAssert_isNotEmpty_Test.java | 2 -- .../instant/InstantAssert_IsBeforeOrEqualTo_Test.java | 2 -- .../api/instant/InstantAssert_isAfterOrEqual_Test.java | 2 -- .../core/api/instant/InstantAssert_isAfter_Test.java | 2 -- .../core/api/instant/InstantAssert_isBefore_Test.java | 2 -- .../core/api/instant/InstantAssert_isEqualTo_Test.java | 2 -- .../core/api/instant/InstantAssert_isIn_Test.java | 2 -- .../core/api/instant/InstantAssert_isNotIn_Test.java | 2 -- .../Int2DArrayAssert_hasDimensions_Test.java | 2 -- .../Int2DArrayAssert_hasSameDimensionsAs_Test.java | 2 -- .../Int2DArrayAssert_isDeepEqualTo_Test.java | 2 -- .../api/int2darray/Int2DArrayAssert_isEmpty_Test.java | 2 -- .../int2darray/Int2DArrayAssert_isNotEmpty_Test.java | 2 -- .../Int2DArrayAssert_isNullOrEmpty_Test.java | 2 -- .../Int2DArrayAssert_usingCustomComparator_Test.java | 2 -- ...ayAssert_containsAnyOf_with_Integer_array_Test.java | 2 -- ...tainsExactlyInAnyOrder_with_Integer_array_Test.java | 2 -- ...ssert_containsOnlyOnce_with_Integer_array_Test.java | 2 -- ...rayAssert_containsOnly_with_Integer_array_Test.java | 2 -- ...rt_containsSubsequence_with_Integer_array_Test.java | 2 -- ...yAssert_doesNotContain_with_Integer_array_Test.java | 2 -- .../api/localdate/LocalDateAssert_isAfter_Test.java | 2 -- .../LocalDateAssert_isBeforeOrEqualTo_Test.java | 2 -- .../api/localdate/LocalDateAssert_isEqualTo_Test.java | 2 -- .../localdate/LocalDateAssert_isNotEqualTo_Test.java | 2 -- .../LocalDateTimeAssert_isAfterOrEqualTo_Test.java | 2 -- .../LocalDateTimeAssert_isAfter_Test.java | 2 -- .../LocalDateTimeAssert_isBeforeOrEqualTo_Test.java | 2 -- .../LocalDateTimeAssert_isBefore_Test.java | 2 -- .../LocalDateTimeAssert_isEqualTo_Test.java | 4 +--- .../localdatetime/LocalDateTimeAssert_isIn_Test.java | 2 -- .../LocalDateTimeAssert_isNotEqualTo_Test.java | 2 -- .../LocalDateTimeAssert_isNotIn_Test.java | 2 -- .../LocalTimeAssert_isAfterOrEqualTo_Test.java | 2 -- .../Long2DArrayAssert_hasDimensions_Test.java | 2 -- .../api/long_/LongAssert_usingComparator_Test.java | 4 +--- ...ayAssert_containsOnlyOnce_with_Long_array_Test.java | 2 -- ...ectArrayAssert_containsOnlyOnceElementsOf_Test.java | 2 -- .../ObjectArrayAssert_usingComparatorForType_Test.java | 6 ++---- .../OffsetDateTimeAssert_isAfterOrEqualTo_Test.java | 2 -- .../OffsetDateTimeAssert_isAfter_Test.java | 2 -- .../OffsetDateTimeAssert_isAtSameInstantAs_Test.java | 2 -- .../OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java | 2 -- .../OffsetDateTimeAssert_isBefore_Test.java | 2 -- .../OffsetDateTimeAssert_isEqualTo_Test.java | 4 +--- .../offsetdatetime/OffsetDateTimeAssert_isIn_Test.java | 4 +--- .../OffsetDateTimeAssert_isNotEqualTo_Test.java | 6 ++---- .../OffsetDateTimeAssert_isNotIn_Test.java | 4 +--- .../core/api/period/PeriodAssert_hasYears_Test.java | 10 ++++------ .../core/api/period/PeriodAssert_isPositive_Test.java | 10 ++++------ .../comparison/DualValue_getFieldName_Test.java | 2 -- .../Short2DArrayAssert_hasDimensions_Test.java | 2 -- .../short2darray/Short2DArrayAssert_isEmpty_Test.java | 2 -- .../Short2DArrayAssert_isNullOrEmpty_Test.java | 2 -- .../Short2DArrayAssert_usingCustomComparator_Test.java | 2 -- ...ontainsExactlyInAnyOrder_with_Short_array_Test.java | 2 -- ...ayAssert_containsExactly_with_Short_array_Test.java | 2 -- ...hortArrayAssert_endsWith_with_Short_array_Test.java | 2 -- .../throwable/NotThrownAssert_description_Test.java | 2 -- .../api/throwable/ThrowableAssert_getCause_Test.java | 4 +--- .../throwable/ThrowableAssert_getRootCause_Test.java | 6 ++---- .../ThrowableAssert_hasRootCauseMessage_Test.java | 2 -- .../core/error/ClassModifierShouldBe_create_Test.java | 2 -- .../assertj/core/error/ShouldBeEven_create_Test.java | 2 -- .../core/error/ShouldBeInfinite_create_Test.java | 2 -- .../error/ShouldHaveBinaryContent_create_Test.java | 2 -- .../core/error/ShouldHaveDimensions_create_Test.java | 2 -- .../core/util/Introspection_getProperty_Test.java | 2 -- .../PropertyOrFieldSupport_getValueOf_Test.java | 3 --- 112 files changed, 35 insertions(+), 255 deletions(-) rename src/test/java/org/assertj/core/api/file/{FileAssert_isEmptyFile_Test.java => FileAssert_isEmpty_Test.java} (88%) rename src/test/java/org/assertj/core/api/file/{FileAssert_isNotEmptyFile_Test.java => FileAssert_isNotEmpty_Test.java} (87%) diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_Function_and_AssertFactory_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_Function_and_AssertFactory_Test.java index 8e299b8c298..8fddbab7c9e 100644 --- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_Function_and_AssertFactory_Test.java +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_Function_and_AssertFactory_Test.java @@ -38,7 +38,6 @@ * * @author Stefano Cordio */ -@DisplayName("AbstractAssert extracting(Function, AssertFactory)") class AbstractAssert_extracting_with_Function_and_AssertFactory_Test implements NavigationMethodBaseTest { private TestAssert underTest; diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_String_and_AssertFactory_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_String_and_AssertFactory_Test.java index 871bf0c3adb..76db737fa2a 100644 --- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_String_and_AssertFactory_Test.java +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_extracting_with_String_and_AssertFactory_Test.java @@ -28,7 +28,6 @@ import org.assertj.core.test.Name; import org.assertj.core.util.introspection.IntrospectionError; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -36,7 +35,6 @@ * * @author Stefano Cordio */ -@DisplayName("AbstractAssert extracting(String, AssertFactory)") class AbstractAssert_extracting_with_String_and_AssertFactory_Test implements NavigationMethodBaseTest { private TestAssert underTest; diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_isInstanceOfSatisfying_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_isInstanceOfSatisfying_Test.java index 1ebfed000f6..1e81229a64d 100644 --- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_isInstanceOfSatisfying_Test.java +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_isInstanceOfSatisfying_Test.java @@ -31,8 +31,8 @@ class AbstractAssert_isInstanceOfSatisfying_Test extends AbstractAssertBaseTest { // init here to make it available in create_assertions() - private Jedi yoda = new Jedi("Yoda", "Green"); - private Jedi luke = new Jedi("Luke Skywalker", "Green"); + private final Jedi yoda = new Jedi("Yoda", "Green"); + private final Jedi luke = new Jedi("Luke Skywalker", "Green"); private Consumer jediRequirements; @BeforeEach diff --git a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingComparator_Test.java b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingComparator_Test.java index 61979bc5600..d2548600b16 100644 --- a/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingComparator_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/longadder/LongAdderAssert_usingComparator_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.LongAdderAssert; import org.assertj.core.api.LongAdderAssertBaseTest; import org.assertj.core.api.LongAssert; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -30,7 +29,6 @@ * * @author Stefano Cordio */ -@DisplayName("LongAdderAssert usingComparator") @ExtendWith(MockitoExtension.class) class LongAdderAssert_usingComparator_Test extends LongAdderAssertBaseTest { diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_usingComparatorForType_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_usingComparatorForType_Test.java index 06b3b56c68c..95991a90852 100644 --- a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_usingComparatorForType_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_usingComparatorForType_Test.java @@ -32,17 +32,15 @@ import org.assertj.core.internal.ObjectArrays; import org.assertj.core.test.Jedi; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") -@DisplayName("AtomicReferenceArrayAssert usingComparatorForType") class AtomicReferenceArrayAssert_usingComparatorForType_Test extends AtomicReferenceArrayAssertBaseTest { private ObjectArrays arraysBefore; - private Jedi actual = new Jedi("Yoda", "green"); - private Jedi other = new Jedi("Luke", "blue"); + private final Jedi actual = new Jedi("Yoda", "green"); + private final Jedi other = new Jedi("Luke", "blue"); @BeforeEach void before() { diff --git a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_usingCustomComparator_Test.java index 25e70d5a031..57e6535c857 100644 --- a/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/boolean2darray/Boolean2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Boolean2DArrayAssert; import org.assertj.core.api.Boolean2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Boolean2DArrayAssert usingCustomComparator") class Boolean2DArrayAssert_usingCustomComparator_Test extends Boolean2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsAnyOf_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsAnyOf_with_Boolean_array_Test.java index 3e23f6024e9..5f1da1bebb4 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsAnyOf_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsAnyOf_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsAnyOf(Boolean[])") class BooleanArrayAssert_containsAnyOf_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactlyInAnyOrder_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactlyInAnyOrder_with_Boolean_array_Test.java index 46ba6914e93..9fef92e5c32 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactlyInAnyOrder_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactlyInAnyOrder_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsExactlyInAnyOrder(Boolean[])") class BooleanArrayAssert_containsExactlyInAnyOrder_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactly_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactly_with_Boolean_array_Test.java index 25a19aa2e21..c28e5f6334d 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactly_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsExactly_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsExactly(Boolean[])") class BooleanArrayAssert_containsExactly_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnlyOnce_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnlyOnce_with_Boolean_array_Test.java index 840b98c14f1..b885d8c9be3 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnlyOnce_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnlyOnce_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsOnlyOnce(Boolean[])") class BooleanArrayAssert_containsOnlyOnce_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnly_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnly_with_Boolean_array_Test.java index c0c547c643f..5adbf0a5bdf 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnly_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsOnly_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsOnly(Boolean[])") class BooleanArrayAssert_containsOnly_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSequence_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSequence_with_Boolean_array_Test.java index ea627c6afbb..783ae1a146e 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSequence_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSequence_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsSequence(Boolean[])") class BooleanArrayAssert_containsSequence_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSubsequence_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSubsequence_with_Boolean_array_Test.java index 6b760eba302..ea19ab966b0 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSubsequence_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_containsSubsequence_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert containsSubsequence(Boolean[])") class BooleanArrayAssert_containsSubsequence_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_contains_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_contains_with_Boolean_array_Test.java index 75407900078..513ba99b571 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_contains_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_contains_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert contains(Boolean[])") class BooleanArrayAssert_contains_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_endsWith_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_endsWith_with_Boolean_array_Test.java index 3b4d5037380..b80c4d4020e 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_endsWith_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_endsWith_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert endsWith(Boolean[])") class BooleanArrayAssert_endsWith_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_startsWith_with_Boolean_array_Test.java b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_startsWith_with_Boolean_array_Test.java index 00a8e3ebd85..5a0517ff242 100644 --- a/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_startsWith_with_Boolean_array_Test.java +++ b/src/test/java/org/assertj/core/api/booleanarray/BooleanArrayAssert_startsWith_with_Boolean_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.BooleanArrayAssert; import org.assertj.core.api.BooleanArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("BooleanArrayAssert startsWith(Boolean[])") class BooleanArrayAssert_startsWith_with_Boolean_array_Test extends BooleanArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNotEmpty_Test.java b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNotEmpty_Test.java index 9e472630dad..37a11d8dbba 100644 --- a/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNotEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/byte2darray/Byte2DArrayAssert_isNotEmpty_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Byte2DArrayAssert; import org.assertj.core.api.Byte2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Byte2DArrayAssert#isNotEmpty()}. * * @author Maciej Wajcht */ -@DisplayName("Byte2DArrayAssert isNotEmpty") class Byte2DArrayAssert_isNotEmpty_Test extends Byte2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_endsWith_with_Byte_array_Test.java b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_endsWith_with_Byte_array_Test.java index 3ebd027fafc..ae43e588906 100644 --- a/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_endsWith_with_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/api/bytearray/ByteArrayAssert_endsWith_with_Byte_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.ByteArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ByteArrayAssert endsWith(Byte[])") class ByteArrayAssert_endsWith_with_Byte_array_Test extends ByteArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNotEmpty_Test.java b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNotEmpty_Test.java index 81d804a7ffb..ec427dcdba6 100644 --- a/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNotEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/char2darray/Char2DArrayAssert_isNotEmpty_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Char2DArrayAssert; import org.assertj.core.api.Char2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Char2DArrayAssert#isNotEmpty()}. * * @author Maciej Wajcht */ -@DisplayName("Char2DArrayAssert isNotEmpty") class Char2DArrayAssert_isNotEmpty_Test extends Char2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnly_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnly_with_Character_array_Test.java index 2d81343cd1b..b8de7b16fd7 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnly_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_containsOnly_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert containsOnly(Character[])") class CharArrayAssert_containsOnly_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_endsWith_with_Character_array_Test.java b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_endsWith_with_Character_array_Test.java index 7da851a7462..94f01c50a0b 100644 --- a/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_endsWith_with_Character_array_Test.java +++ b/src/test/java/org/assertj/core/api/chararray/CharArrayAssert_endsWith_with_Character_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.CharArrayAssert; import org.assertj.core.api.CharArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("CharacterArrayAssert endsWith(Character[])") class CharArrayAssert_endsWith_with_Character_array_Test extends CharArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasDimensions_Test.java b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasDimensions_Test.java index 173846ccd81..88a6b03e9ff 100644 --- a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasDimensions_Test.java +++ b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_hasDimensions_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Double2DArrayAssert; import org.assertj.core.api.Double2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Double2DArrayAssert#hasDimensions(int, int)}. * * @author Maciej Wajcht */ -@DisplayName("Double2DArrayAssert hasDimensions") class Double2DArrayAssert_hasDimensions_Test extends Double2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isDeepEqualTo_Test.java index aed28150395..3cf6309236d 100644 --- a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isDeepEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.Double2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Double2DArrayAssert isDeepEqualTo") class Double2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isEmpty_Test.java index d7625dc5ed7..f2d75a4bb62 100644 --- a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Double2DArrayAssert; import org.assertj.core.api.Double2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Double2DArrayAssert isEmpty") class Double2DArrayAssert_isEmpty_Test extends Double2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isNullOrEmpty_Test.java index 7d0076f551f..e9a66262271 100644 --- a/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/double2darray/Double2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Double2DArrayAssert; import org.assertj.core.api.Double2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Double2DArrayAssert isNullOrEmpty") class Double2DArrayAssert_isNullOrEmpty_Test extends Double2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/double_/DoubleAssert_isLessThanOrEqualTo_DoubleWrapper_Test.java b/src/test/java/org/assertj/core/api/double_/DoubleAssert_isLessThanOrEqualTo_DoubleWrapper_Test.java index b1d3db8c749..4f1dcfd0d7c 100644 --- a/src/test/java/org/assertj/core/api/double_/DoubleAssert_isLessThanOrEqualTo_DoubleWrapper_Test.java +++ b/src/test/java/org/assertj/core/api/double_/DoubleAssert_isLessThanOrEqualTo_DoubleWrapper_Test.java @@ -19,13 +19,11 @@ import org.assertj.core.api.DoubleAssert; import org.assertj.core.api.DoubleAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("DoubleAssert isLessThanOrEqualTo") class DoubleAssert_isLessThanOrEqualTo_DoubleWrapper_Test extends DoubleAssertBaseTest { - private Double other = 11.0D; + private final Double other = 11.0D; @Override protected DoubleAssert invoke_api_method() { diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactlyInAnyOrder_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactlyInAnyOrder_with_Double_array_Test.java index 72dd2ee4af0..7581596d56b 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactlyInAnyOrder_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactlyInAnyOrder_with_Double_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert containsExactlyInAnyOrder(Double[])") class DoubleArrayAssert_containsExactlyInAnyOrder_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactly_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactly_with_Double_array_Test.java index 9c87d282e37..841f4c011e7 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactly_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsExactly_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert containsExactly(Double[])") class DoubleArrayAssert_containsExactly_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnlyOnce_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnlyOnce_with_Double_array_Test.java index 9a5ad0ec13d..8495b26b0a4 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnlyOnce_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_containsOnlyOnce_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert containsOnlyOnce(Double[])") class DoubleArrayAssert_containsOnlyOnce_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_contains_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_contains_with_Double_array_Test.java index c15899a1d6a..31f7f342e2f 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_contains_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_contains_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert contains(Double[])") class DoubleArrayAssert_contains_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_doesNotContain_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_doesNotContain_with_Double_array_Test.java index 620fc57eec1..41464050ae3 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_doesNotContain_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_doesNotContain_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert doesNotContain(Double[])") class DoubleArrayAssert_doesNotContain_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_startsWith_with_Double_array_Test.java b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_startsWith_with_Double_array_Test.java index c1880cf4bc9..c8623536dc7 100644 --- a/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_startsWith_with_Double_array_Test.java +++ b/src/test/java/org/assertj/core/api/doublearray/DoubleArrayAssert_startsWith_with_Double_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.DoubleArrayAssert; import org.assertj.core.api.DoubleArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("DoubleArrayAssert startsWith(Double[])") class DoubleArrayAssert_startsWith_with_Double_array_Test extends DoubleArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/duration/DurationAssert_isCloseTo_Test.java b/src/test/java/org/assertj/core/api/duration/DurationAssert_isCloseTo_Test.java index 5eb80849bcd..c456aedb9b4 100644 --- a/src/test/java/org/assertj/core/api/duration/DurationAssert_isCloseTo_Test.java +++ b/src/test/java/org/assertj/core/api/duration/DurationAssert_isCloseTo_Test.java @@ -23,12 +23,10 @@ import java.time.Duration; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -@DisplayName("DurationAssert isCloseTo") class DurationAssert_isCloseTo_Test { @ParameterizedTest(name = "PT2M should close to {0} withMarginOf {1}") diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_hasSameTextualContentAs_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_hasSameTextualContentAs_Test.java index 70516365183..11f7be4be40 100644 --- a/src/test/java/org/assertj/core/api/file/FileAssert_hasSameTextualContentAs_Test.java +++ b/src/test/java/org/assertj/core/api/file/FileAssert_hasSameTextualContentAs_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FileAssert; import org.assertj.core.api.FileAssertBaseTest; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * @author Yvonne Wang * @author Nikolaos Georgiou */ -@DisplayName("FileAssert hasSameTextualContentAs") class FileAssert_hasSameTextualContentAs_Test extends FileAssertBaseTest { private static File expected; diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_isEmptyFile_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_isEmpty_Test.java similarity index 88% rename from src/test/java/org/assertj/core/api/file/FileAssert_isEmptyFile_Test.java rename to src/test/java/org/assertj/core/api/file/FileAssert_isEmpty_Test.java index cce4290296a..297a3d64a0e 100644 --- a/src/test/java/org/assertj/core/api/file/FileAssert_isEmptyFile_Test.java +++ b/src/test/java/org/assertj/core/api/file/FileAssert_isEmpty_Test.java @@ -12,17 +12,15 @@ */ package org.assertj.core.api.file; +import static org.mockito.Mockito.verify; + import org.assertj.core.api.FileAssert; import org.assertj.core.api.FileAssertBaseTest; -import org.junit.jupiter.api.DisplayName; - -import static org.mockito.Mockito.verify; /** * Tests for {@link FileAssert#isEmpty()}. */ -@DisplayName("FileAssert isEmptyFile") -class FileAssert_isEmptyFile_Test extends FileAssertBaseTest { +class FileAssert_isEmpty_Test extends FileAssertBaseTest { @Override protected FileAssert invoke_api_method() { @@ -33,4 +31,5 @@ protected FileAssert invoke_api_method() { protected void verify_internal_effects() { verify(files).assertIsEmptyFile(getInfo(assertions), getActual(assertions)); } + } diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_isNotEmptyFile_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_isNotEmpty_Test.java similarity index 87% rename from src/test/java/org/assertj/core/api/file/FileAssert_isNotEmptyFile_Test.java rename to src/test/java/org/assertj/core/api/file/FileAssert_isNotEmpty_Test.java index f6f26e6ac07..2cfc9f68d5c 100644 --- a/src/test/java/org/assertj/core/api/file/FileAssert_isNotEmptyFile_Test.java +++ b/src/test/java/org/assertj/core/api/file/FileAssert_isNotEmpty_Test.java @@ -12,17 +12,15 @@ */ package org.assertj.core.api.file; +import static org.mockito.Mockito.verify; + import org.assertj.core.api.FileAssert; import org.assertj.core.api.FileAssertBaseTest; -import org.junit.jupiter.api.DisplayName; - -import static org.mockito.Mockito.verify; /** * Tests for {@link FileAssert#isNotEmpty()}. */ -@DisplayName("FileAssert isNotEmptyFile") -class FileAssert_isNotEmptyFile_Test extends FileAssertBaseTest { +class FileAssert_isNotEmpty_Test extends FileAssertBaseTest { @Override protected FileAssert invoke_api_method() { @@ -33,4 +31,5 @@ protected FileAssert invoke_api_method() { protected void verify_internal_effects() { verify(files).assertIsNotEmptyFile(getInfo(assertions), getActual(assertions)); } + } diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasDimensions_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasDimensions_Test.java index 0672997d523..04244200148 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasDimensions_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_hasDimensions_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.api.Float2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Float2DArrayAssert#hasDimensions(int, int)}. * * @author Maciej Wajcht */ -@DisplayName("Float2DArrayAssert hasSize") class Float2DArrayAssert_hasDimensions_Test extends Float2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isDeepEqualTo_Test.java index 6180bb2225f..3ebed6acfd1 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isDeepEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Float2DArrayAssert isDeepEqualTo") class Float2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNullOrEmpty_Test.java index 5eedb5f0c70..b978f342e67 100644 --- a/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/float2darray/Float2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Float2DArrayAssert; import org.assertj.core.api.Float2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Float2DArrayAssert isNullOrEmpty") class Float2DArrayAssert_isNullOrEmpty_Test extends Float2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnly_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnly_with_Float_array_Test.java index 07da9babaa4..a947b8468ed 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnly_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsOnly_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsOnly(Float[])") class FloatArrayAssert_containsOnly_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSequence_with_Float_array_Test.java b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSequence_with_Float_array_Test.java index fda0bf2c76e..062af2cc100 100644 --- a/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSequence_with_Float_array_Test.java +++ b/src/test/java/org/assertj/core/api/floatarray/FloatArrayAssert_containsSequence_with_Float_array_Test.java @@ -22,7 +22,6 @@ import org.assertj.core.api.FloatArrayAssert; import org.assertj.core.api.FloatArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("FloatArrayAssert containsSequence(Float[])") class FloatArrayAssert_containsSequence_with_Float_array_Test extends FloatArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_failsWithin_Test.java b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_failsWithin_Test.java index 2cddaf1249c..28ad2be95df 100644 --- a/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_failsWithin_Test.java +++ b/src/test/java/org/assertj/core/api/future/CompletableFutureAssert_failsWithin_Test.java @@ -24,11 +24,9 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeoutException; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("FutureAssert failsWithin") -class CompletableFutureAssert_failsWithin_Test extends AbstractFutureTest{ +class CompletableFutureAssert_failsWithin_Test extends AbstractFutureTest { private static final Duration ONE_SECOND = Duration.ofSeconds(1); @@ -51,7 +49,7 @@ void should_pass_when_future_does_not_complete_within_timeout() { @Test void should_allow_assertion_on_future_exception_when_future_did_not_complete_within_timeout_Duration() { // GIVEN - CompletableFuture future = futureCompletingAfter(ONE_SECOND,executorService); + CompletableFuture future = futureCompletingAfter(ONE_SECOND, executorService); // WHEN/THEN assertThat(future).failsWithin(Duration.ofMillis(50)) .withThrowableOfType(TimeoutException.class) diff --git a/src/test/java/org/assertj/core/api/future/FutureAssert_succeedsWithin_Test.java b/src/test/java/org/assertj/core/api/future/FutureAssert_succeedsWithin_Test.java index e1a72c155d9..bf988e9a310 100644 --- a/src/test/java/org/assertj/core/api/future/FutureAssert_succeedsWithin_Test.java +++ b/src/test/java/org/assertj/core/api/future/FutureAssert_succeedsWithin_Test.java @@ -26,10 +26,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("FutureAssert succeedsWithin") class FutureAssert_succeedsWithin_Test extends AbstractFutureTest { @Test diff --git a/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isNotEmpty_Test.java b/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isNotEmpty_Test.java index baf5bd8c381..3edad692d19 100644 --- a/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isNotEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/inputstream/InputStreamAssert_isNotEmpty_Test.java @@ -16,12 +16,10 @@ import org.assertj.core.api.InputStreamAssert; import org.assertj.core.api.InputStreamAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link InputStreamAssert#isNotEmpty()}. */ -@DisplayName("InputStreamAssert isNotEmpty") class InputStreamAssert_isNotEmpty_Test extends InputStreamAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_IsBeforeOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_IsBeforeOrEqualTo_Test.java index cbaedde9f74..00b9fe4a918 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_IsBeforeOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_IsBeforeOrEqualTo_Test.java @@ -21,10 +21,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isBeforeOrEqualTo") class InstantAssert_IsBeforeOrEqualTo_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfterOrEqual_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfterOrEqual_Test.java index fe1688684de..9a644538ac5 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfterOrEqual_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfterOrEqual_Test.java @@ -21,10 +21,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isAfterOrEqual") class InstantAssert_isAfterOrEqual_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfter_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfter_Test.java index 9277f3255e7..a211f3d5202 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfter_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_isAfter_Test.java @@ -21,10 +21,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isAfter") class InstantAssert_isAfter_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_isBefore_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_isBefore_Test.java index bec1a959d4c..45d1861f377 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_isBefore_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_isBefore_Test.java @@ -21,10 +21,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isBefore") class InstantAssert_isBefore_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_isEqualTo_Test.java index 1f7ff4c407a..379406ca8e2 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_isEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_isEqualTo_Test.java @@ -20,10 +20,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isEqualTo") class InstantAssert_isEqualTo_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_isIn_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_isIn_Test.java index 5390c7195f9..657651c6919 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_isIn_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_isIn_Test.java @@ -21,10 +21,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isIn") class InstantAssert_isIn_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/instant/InstantAssert_isNotIn_Test.java b/src/test/java/org/assertj/core/api/instant/InstantAssert_isNotIn_Test.java index 74a9b5cedaf..95333458c98 100644 --- a/src/test/java/org/assertj/core/api/instant/InstantAssert_isNotIn_Test.java +++ b/src/test/java/org/assertj/core/api/instant/InstantAssert_isNotIn_Test.java @@ -21,10 +21,8 @@ import java.time.Instant; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("InstantAssert isNotIn") class InstantAssert_isNotIn_Test extends InstantAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasDimensions_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasDimensions_Test.java index 8e9f2c5a794..11382119729 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasDimensions_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasDimensions_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.api.Int2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Int2DArrayAssert#hasDimensions(int, int)}. * * @author Maciej Wajcht */ -@DisplayName("Int2DArrayAssert hasSize") class Int2DArrayAssert_hasDimensions_Test extends Int2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasSameDimensionsAs_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasSameDimensionsAs_Test.java index 86fdb0cebc2..ead0defc1e2 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasSameDimensionsAs_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_hasSameDimensionsAs_Test.java @@ -17,14 +17,12 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.api.Int2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Int2DArrayAssert#hasSameDimensionsAs(Object)}. * * @author Maciej Wajcht */ -@DisplayName("Int2DArrayAssert hasSameDimensionsAs") class Int2DArrayAssert_hasSameDimensionsAs_Test extends Int2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isDeepEqualTo_Test.java index 7b8f9d7a596..d702b543ef4 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isDeepEqualTo_Test.java @@ -24,7 +24,6 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -32,7 +31,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Int2DArrayAssert isDeepEqualTo") class Int2DArrayAssert_isDeepEqualTo_Test { @Test diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isEmpty_Test.java index 06c140706a6..328bf8f88ae 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.api.Int2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Int2DArrayAssert isEmpty") class Int2DArrayAssert_isEmpty_Test extends Int2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNotEmpty_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNotEmpty_Test.java index dc7a0d9bf35..2cc1033de27 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNotEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNotEmpty_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.api.Int2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Int2DArrayAssert#isNotEmpty()}. * * @author Maciej Wajcht */ -@DisplayName("Int2DArrayAssert isNotEmpty") class Int2DArrayAssert_isNotEmpty_Test extends Int2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNullOrEmpty_Test.java index 3c0e7b26339..84038ec7a13 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.api.Int2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Int2DArrayAssert isNullOrEmpty") class Int2DArrayAssert_isNullOrEmpty_Test extends Int2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_usingCustomComparator_Test.java index 234a9ee8c64..09375cc9391 100644 --- a/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/int2darray/Int2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Int2DArrayAssert; import org.assertj.core.api.Int2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Int2DArrayAssert usingCustomComparator") class Int2DArrayAssert_usingCustomComparator_Test extends Int2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsAnyOf_with_Integer_array_Test.java b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsAnyOf_with_Integer_array_Test.java index 7787120bab0..fe5a287e85d 100644 --- a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsAnyOf_with_Integer_array_Test.java +++ b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsAnyOf_with_Integer_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.IntArrayAssert; import org.assertj.core.api.IntArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("IntArrayAssert containsAnyOf(Integer[])") class IntArrayAssert_containsAnyOf_with_Integer_array_Test extends IntArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsExactlyInAnyOrder_with_Integer_array_Test.java b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsExactlyInAnyOrder_with_Integer_array_Test.java index 773fda38d62..f0b8337d368 100644 --- a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsExactlyInAnyOrder_with_Integer_array_Test.java +++ b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsExactlyInAnyOrder_with_Integer_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.IntArrayAssert; import org.assertj.core.api.IntArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("IntArrayAssert containsExactlyInAnyOrder(Integer[])") class IntArrayAssert_containsExactlyInAnyOrder_with_Integer_array_Test extends IntArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnlyOnce_with_Integer_array_Test.java b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnlyOnce_with_Integer_array_Test.java index dc4e1253268..31a2c29c9b0 100644 --- a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnlyOnce_with_Integer_array_Test.java +++ b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnlyOnce_with_Integer_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.IntArrayAssert; import org.assertj.core.api.IntArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("IntArrayAssert containsOnlyOnce(Integer[])") class IntArrayAssert_containsOnlyOnce_with_Integer_array_Test extends IntArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnly_with_Integer_array_Test.java b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnly_with_Integer_array_Test.java index 27865e22bf4..5595a93514d 100644 --- a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnly_with_Integer_array_Test.java +++ b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsOnly_with_Integer_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.IntArrayAssert; import org.assertj.core.api.IntArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("IntArrayAssert containsOnly(Integer[])") class IntArrayAssert_containsOnly_with_Integer_array_Test extends IntArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsSubsequence_with_Integer_array_Test.java b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsSubsequence_with_Integer_array_Test.java index 0eaca4ba2b4..53a49a2fbff 100644 --- a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsSubsequence_with_Integer_array_Test.java +++ b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_containsSubsequence_with_Integer_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.IntArrayAssert; import org.assertj.core.api.IntArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("IntArrayAssert containsSubsequence(Integer[])") class IntArrayAssert_containsSubsequence_with_Integer_array_Test extends IntArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_doesNotContain_with_Integer_array_Test.java b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_doesNotContain_with_Integer_array_Test.java index d0284bb5279..2904727b320 100644 --- a/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_doesNotContain_with_Integer_array_Test.java +++ b/src/test/java/org/assertj/core/api/intarray/IntArrayAssert_doesNotContain_with_Integer_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.IntArrayAssert; import org.assertj.core.api.IntArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Omar Morales Ortega */ -@DisplayName("IntArrayAssert doesNotContain(Integer])") class IntArrayAssert_doesNotContain_with_Integer_array_Test extends IntArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isAfter_Test.java b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isAfter_Test.java index bf1ca4fe063..a061aecf149 100644 --- a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isAfter_Test.java +++ b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isAfter_Test.java @@ -21,10 +21,8 @@ import java.time.LocalDate; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("LocalDateAssert isAfter") class LocalDateAssert_isAfter_Test extends LocalDateAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isBeforeOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isBeforeOrEqualTo_Test.java index f47ad85e304..e3f1c6c55a9 100644 --- a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isBeforeOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isBeforeOrEqualTo_Test.java @@ -21,7 +21,6 @@ import java.time.LocalDate; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -29,7 +28,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateAssert") class LocalDateAssert_isBeforeOrEqualTo_Test extends LocalDateAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isEqualTo_Test.java index efc9cf76db5..7517f37b2c8 100644 --- a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isEqualTo_Test.java @@ -21,7 +21,6 @@ import java.time.LocalDate; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateAssert isEqualTo") class LocalDateAssert_isEqualTo_Test extends LocalDateAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isNotEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isNotEqualTo_Test.java index 0d7bc1abbb7..5aa1d2c6cf6 100644 --- a/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isNotEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdate/LocalDateAssert_isNotEqualTo_Test.java @@ -20,13 +20,11 @@ import java.time.LocalDate; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** * Only test String based assertion (tests with {@link LocalDate} are already defined in assertj-core) */ -@DisplayName("LocalDateAssert isNotEqualTo") class LocalDateAssert_isNotEqualTo_Test extends LocalDateAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfterOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfterOrEqualTo_Test.java index b00bb056d98..9b3e2e92866 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfterOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfterOrEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.AbstractLocalDateTimeAssertBaseTest; import org.assertj.core.api.LocalDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isAfterOrEqualTo") class LocalDateTimeAssert_isAfterOrEqualTo_Test extends AbstractLocalDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfter_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfter_Test.java index 4c44c8f8ea9..deef63b210c 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfter_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isAfter_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.AbstractLocalDateTimeAssertBaseTest; import org.assertj.core.api.LocalDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isAfter") class LocalDateTimeAssert_isAfter_Test extends AbstractLocalDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBeforeOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBeforeOrEqualTo_Test.java index a7085c3c3d5..dc6fd0ed6e6 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBeforeOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBeforeOrEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.AbstractLocalDateTimeAssertBaseTest; import org.assertj.core.api.LocalDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isBeforeOrEqualTo") class LocalDateTimeAssert_isBeforeOrEqualTo_Test extends AbstractLocalDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBefore_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBefore_Test.java index f3a11295266..834ef2619cc 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBefore_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isBefore_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.AbstractLocalDateTimeAssertBaseTest; import org.assertj.core.api.LocalDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -31,7 +30,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isBefore") class LocalDateTimeAssert_isBefore_Test extends AbstractLocalDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isEqualTo_Test.java index eddd5a8b8db..53cde90b8dd 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isEqualTo_Test.java @@ -26,7 +26,6 @@ import org.assertj.core.api.AbstractLocalDateTimeAssertBaseTest; import org.assertj.core.api.LocalDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -35,10 +34,9 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isEqualTo") class LocalDateTimeAssert_isEqualTo_Test extends AbstractLocalDateTimeAssertBaseTest { - private Object otherType = new Object(); + private final Object otherType = new Object(); @Override public LocalDateTimeAssert invoke_api_method() { diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isIn_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isIn_Test.java index 25a64c3f547..52db3352433 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isIn_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isIn_Test.java @@ -21,7 +21,6 @@ import java.time.LocalDateTime; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isIn") class LocalDateTimeAssert_isIn_Test extends LocalDateTimeAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotEqualTo_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotEqualTo_Test.java index 9c99085604d..a2b65d23ec4 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotEqualTo_Test.java @@ -23,7 +23,6 @@ import org.assertj.core.api.AbstractLocalDateTimeAssertBaseTest; import org.assertj.core.api.LocalDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -32,7 +31,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isNotEqualTo") class LocalDateTimeAssert_isNotEqualTo_Test extends AbstractLocalDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotIn_Test.java b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotIn_Test.java index a471fdd2862..028560a690b 100644 --- a/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotIn_Test.java +++ b/src/test/java/org/assertj/core/api/localdatetime/LocalDateTimeAssert_isNotIn_Test.java @@ -21,7 +21,6 @@ import java.time.LocalDateTime; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -30,7 +29,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalDateTimeAssert isNotIn") class LocalDateTimeAssert_isNotIn_Test extends LocalDateTimeAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/localtime/LocalTimeAssert_isAfterOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/localtime/LocalTimeAssert_isAfterOrEqualTo_Test.java index e023aacf7b2..c10ac97c307 100644 --- a/src/test/java/org/assertj/core/api/localtime/LocalTimeAssert_isAfterOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/localtime/LocalTimeAssert_isAfterOrEqualTo_Test.java @@ -21,7 +21,6 @@ import java.time.LocalTime; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -29,7 +28,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("LocalTimeAssert isAfterOrEqualTo") class LocalTimeAssert_isAfterOrEqualTo_Test extends LocalTimeAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasDimensions_Test.java b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasDimensions_Test.java index 56f2034656d..7c5161eb1a6 100644 --- a/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasDimensions_Test.java +++ b/src/test/java/org/assertj/core/api/long2darray/Long2DArrayAssert_hasDimensions_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Long2DArrayAssert; import org.assertj.core.api.Long2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Long2DArrayAssert#hasDimensions(int, int)} (int, int)}. * * @author Maciej Wajcht */ -@DisplayName("Long2DArrayAssert hasDimensions") class Long2DArrayAssert_hasDimensions_Test extends Long2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/long_/LongAssert_usingComparator_Test.java b/src/test/java/org/assertj/core/api/long_/LongAssert_usingComparator_Test.java index a800abc14d8..a9d9868e7c7 100644 --- a/src/test/java/org/assertj/core/api/long_/LongAssert_usingComparator_Test.java +++ b/src/test/java/org/assertj/core/api/long_/LongAssert_usingComparator_Test.java @@ -19,17 +19,15 @@ import org.assertj.core.api.LongAssert; import org.assertj.core.api.LongAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link LongAssert#usingComparator(Comparator)}. * * @author Joel Costigliola */ -@DisplayName("LongAssert usingComparator") class LongAssert_usingComparator_Test extends LongAssertBaseTest { - private Comparator comparator = alwaysEqual(); + private final Comparator comparator = alwaysEqual(); @Override protected LongAssert invoke_api_method() { diff --git a/src/test/java/org/assertj/core/api/longarray/LongArrayAssert_containsOnlyOnce_with_Long_array_Test.java b/src/test/java/org/assertj/core/api/longarray/LongArrayAssert_containsOnlyOnce_with_Long_array_Test.java index 4b9adff32ef..5a3f58886eb 100644 --- a/src/test/java/org/assertj/core/api/longarray/LongArrayAssert_containsOnlyOnce_with_Long_array_Test.java +++ b/src/test/java/org/assertj/core/api/longarray/LongArrayAssert_containsOnlyOnce_with_Long_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.LongArrayAssert; import org.assertj.core.api.LongArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Stefano Cordio */ -@DisplayName("LongArrayAssert containsOnlyOnce(Long[])") class LongArrayAssert_containsOnlyOnce_with_Long_array_Test extends LongArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_containsOnlyOnceElementsOf_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_containsOnlyOnceElementsOf_Test.java index 2e3acd3b572..a36a361bbd8 100644 --- a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_containsOnlyOnceElementsOf_Test.java +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_containsOnlyOnceElementsOf_Test.java @@ -19,14 +19,12 @@ import org.assertj.core.api.ObjectArrayAssert; import org.assertj.core.api.ObjectArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link ObjectArrayAssert#containsOnlyOnceElementsOf(Iterable)}. * * @author CAL027 */ -@DisplayName("ObjectArrayAssert containsOnlyOnceElementsOf") class ObjectArrayAssert_containsOnlyOnceElementsOf_Test extends ObjectArrayAssertBaseTest { private final List values = newArrayList("Yoda", "Luke"); diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_usingComparatorForType_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_usingComparatorForType_Test.java index 794296e2012..574973d30f1 100644 --- a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_usingComparatorForType_Test.java +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_usingComparatorForType_Test.java @@ -31,17 +31,15 @@ import org.assertj.core.internal.ObjectArrays; import org.assertj.core.test.Jedi; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @SuppressWarnings("deprecation") -@DisplayName("ObjectArrayAssert usingComparatorForType") class ObjectArrayAssert_usingComparatorForType_Test extends ObjectArrayAssertBaseTest { private ObjectArrays arraysBefore; - private Jedi actual = new Jedi("Yoda", "green"); - private Jedi other = new Jedi("Luke", "blue"); + private final Jedi actual = new Jedi("Yoda", "green"); + private final Jedi other = new Jedi("Luke", "blue"); @BeforeEach void before() { diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java index 54ffaad9e6c..bacd66f52ec 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java @@ -27,7 +27,6 @@ import org.assertj.core.api.AbstractOffsetDateTimeAssertBaseTest; import org.assertj.core.api.OffsetDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -35,7 +34,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isAfterOrEqualTo") class OffsetDateTimeAssert_isAfterOrEqualTo_Test extends AbstractOffsetDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java index 64bd949c7bd..49220055ddc 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java @@ -27,7 +27,6 @@ import org.assertj.core.api.AbstractOffsetDateTimeAssertBaseTest; import org.assertj.core.api.OffsetDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -35,7 +34,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isAfter") class OffsetDateTimeAssert_isAfter_Test extends AbstractOffsetDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAtSameInstantAs_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAtSameInstantAs_Test.java index bcad49b2db1..928d0ae8c71 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAtSameInstantAs_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAtSameInstantAs_Test.java @@ -22,10 +22,8 @@ import java.time.OffsetDateTime; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("OffsetDateTimeAssert isAtSameInstantAs") class OffsetDateTimeAssert_isAtSameInstantAs_Test extends OffsetDateTimeAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java index 9ac2f6092b4..0ff653cd51b 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java @@ -26,7 +26,6 @@ import org.assertj.core.api.AbstractOffsetDateTimeAssertBaseTest; import org.assertj.core.api.OffsetDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -34,7 +33,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isBeforeOrEqualTo") class OffsetDateTimeAssert_isBeforeOrEqualTo_Test extends AbstractOffsetDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java index 0fa9a55e3e9..178b01f7ceb 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java @@ -26,7 +26,6 @@ import org.assertj.core.api.AbstractOffsetDateTimeAssertBaseTest; import org.assertj.core.api.OffsetDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -34,7 +33,6 @@ * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isBefore") class OffsetDateTimeAssert_isBefore_Test extends AbstractOffsetDateTimeAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java index 2d561db9ba2..e673e5d3e17 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java @@ -29,17 +29,15 @@ import org.assertj.core.api.AbstractOffsetDateTimeAssertBaseTest; import org.assertj.core.api.OffsetDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isEqualTo") class OffsetDateTimeAssert_isEqualTo_Test extends AbstractOffsetDateTimeAssertBaseTest { - private Object otherType = new Object(); + private final Object otherType = new Object(); @Override protected OffsetDateTimeAssert invoke_api_method() { diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java index 880d17bd55c..fb901b81ea0 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java @@ -21,16 +21,14 @@ import java.time.OffsetDateTime; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** - * Only test String based assertion (tests with {@link java.time.OffsetDateTime} are already defined in assertj-core) + * Only test String based assertion (tests with {@link OffsetDateTime} are already defined in assertj-core) * * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isIn") class OffsetDateTimeAssert_isIn_Test extends OffsetDateTimeAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java index f1671363e55..9332470ff40 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java @@ -27,19 +27,17 @@ import org.assertj.core.api.AbstractOffsetDateTimeAssertBaseTest; import org.assertj.core.api.OffsetDateTimeAssert; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** - * Only test String based assertion (tests with {@link java.time.OffsetDateTime} are already defined in assertj-core) + * Only test String based assertion (tests with {@link OffsetDateTime} are already defined in assertj-core) * * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isNotEqualTo") class OffsetDateTimeAssert_isNotEqualTo_Test extends AbstractOffsetDateTimeAssertBaseTest { - private Object otherType = new Object(); + private final Object otherType = new Object(); @Override protected OffsetDateTimeAssert invoke_api_method() { diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java index 9818f6e8479..c933ec88023 100644 --- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java +++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java @@ -23,16 +23,14 @@ import java.time.OffsetDateTime; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** - * Only test String based assertion (tests with {@link java.time.OffsetDateTime} are already defined in assertj-core) + * Only test String based assertion (tests with {@link OffsetDateTime} are already defined in assertj-core) * * @author Joel Costigliola * @author Marcin ZajÄ…czkowski */ -@DisplayName("OffsetDateTimeAssert isNotIn") class OffsetDateTimeAssert_isNotIn_Test extends OffsetDateTimeAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/period/PeriodAssert_hasYears_Test.java b/src/test/java/org/assertj/core/api/period/PeriodAssert_hasYears_Test.java index 456bacef73e..838bd0c103d 100644 --- a/src/test/java/org/assertj/core/api/period/PeriodAssert_hasYears_Test.java +++ b/src/test/java/org/assertj/core/api/period/PeriodAssert_hasYears_Test.java @@ -12,21 +12,19 @@ */ package org.assertj.core.api.period; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.time.Period; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHavePeriod.shouldHaveYears; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import java.time.Period; + +import org.junit.jupiter.api.Test; + /** * @author Hayden Meloche */ -@DisplayName("PeriodAssert hasYears") class PeriodAssert_hasYears_Test { @Test diff --git a/src/test/java/org/assertj/core/api/period/PeriodAssert_isPositive_Test.java b/src/test/java/org/assertj/core/api/period/PeriodAssert_isPositive_Test.java index b929812b948..ceefbe0e294 100644 --- a/src/test/java/org/assertj/core/api/period/PeriodAssert_isPositive_Test.java +++ b/src/test/java/org/assertj/core/api/period/PeriodAssert_isPositive_Test.java @@ -12,21 +12,19 @@ */ package org.assertj.core.api.period; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.time.Period; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBePeriod.shouldBePositive; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import java.time.Period; + +import org.junit.jupiter.api.Test; + /** * @author Hayden Meloche */ -@DisplayName("PeriodAssert isPositive") class PeriodAssert_isPositive_Test { @Test diff --git a/src/test/java/org/assertj/core/api/recursive/comparison/DualValue_getFieldName_Test.java b/src/test/java/org/assertj/core/api/recursive/comparison/DualValue_getFieldName_Test.java index 80cfbf7bc8d..93b8cf61b16 100644 --- a/src/test/java/org/assertj/core/api/recursive/comparison/DualValue_getFieldName_Test.java +++ b/src/test/java/org/assertj/core/api/recursive/comparison/DualValue_getFieldName_Test.java @@ -16,10 +16,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.util.Lists.list; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("DualValue getFieldName") class DualValue_getFieldName_Test { @Test diff --git a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_hasDimensions_Test.java b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_hasDimensions_Test.java index 73c46978c38..358efca80ed 100644 --- a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_hasDimensions_Test.java +++ b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_hasDimensions_Test.java @@ -16,14 +16,12 @@ import org.assertj.core.api.Short2DArrayAssert; import org.assertj.core.api.Short2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; /** * Tests for {@link Short2DArrayAssert#hasDimensions(int, int)}. * * @author Maciej Wajcht */ -@DisplayName("Short2DArrayAssert hasDimensions") class Short2DArrayAssert_hasDimensions_Test extends Short2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isEmpty_Test.java b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isEmpty_Test.java index 6947e27ff6b..b5268c5fe11 100644 --- a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Short2DArrayAssert; import org.assertj.core.api.Short2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Short2DArrayAssert isEmpty") class Short2DArrayAssert_isEmpty_Test extends Short2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isNullOrEmpty_Test.java b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isNullOrEmpty_Test.java index 8d7d3d5a596..0ea0f6304d9 100644 --- a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isNullOrEmpty_Test.java +++ b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_isNullOrEmpty_Test.java @@ -16,7 +16,6 @@ import org.assertj.core.api.Short2DArrayAssert; import org.assertj.core.api.Short2DArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -24,7 +23,6 @@ * * @author Maciej Wajcht */ -@DisplayName("Short2DArrayAssert isNullOrEmpty") class Short2DArrayAssert_isNullOrEmpty_Test extends Short2DArrayAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_usingCustomComparator_Test.java b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_usingCustomComparator_Test.java index f0038a026d9..589039e2c7b 100644 --- a/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_usingCustomComparator_Test.java +++ b/src/test/java/org/assertj/core/api/short2darray/Short2DArrayAssert_usingCustomComparator_Test.java @@ -18,10 +18,8 @@ import org.assertj.core.api.Short2DArrayAssert; import org.assertj.core.api.Short2DArrayAssertBaseTest; import org.assertj.core.test.AlwaysEqualComparator; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Short2DArrayAssert usingCustomComparator") class Short2DArrayAssert_usingCustomComparator_Test extends Short2DArrayAssertBaseTest { private static final AlwaysEqualComparator ALWAYS_EQUAL = alwaysEqual(); diff --git a/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactlyInAnyOrder_with_Short_array_Test.java b/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactlyInAnyOrder_with_Short_array_Test.java index cf2d8e708eb..02cbe6a81c8 100644 --- a/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactlyInAnyOrder_with_Short_array_Test.java +++ b/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactlyInAnyOrder_with_Short_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ShortArrayAssert; import org.assertj.core.api.ShortArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ShortArrayAssert containsExactly(Short[])") class ShortArrayAssert_containsExactlyInAnyOrder_with_Short_array_Test extends ShortArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactly_with_Short_array_Test.java b/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactly_with_Short_array_Test.java index 526cd4538a8..adcb47c3e11 100644 --- a/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactly_with_Short_array_Test.java +++ b/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_containsExactly_with_Short_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ShortArrayAssert; import org.assertj.core.api.ShortArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ShortArrayAssert containsExactly(Short[])") class ShortArrayAssert_containsExactly_with_Short_array_Test extends ShortArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_endsWith_with_Short_array_Test.java b/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_endsWith_with_Short_array_Test.java index 823fa8ef910..5cba095e8d4 100644 --- a/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_endsWith_with_Short_array_Test.java +++ b/src/test/java/org/assertj/core/api/shortarray/ShortArrayAssert_endsWith_with_Short_array_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.api.ShortArrayAssert; import org.assertj.core.api.ShortArrayAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Lucero Garcia */ -@DisplayName("ShortArrayAssert endsWith(Short[])") class ShortArrayAssert_endsWith_with_Short_array_Test extends ShortArrayAssertBaseTest { @Test diff --git a/src/test/java/org/assertj/core/api/throwable/NotThrownAssert_description_Test.java b/src/test/java/org/assertj/core/api/throwable/NotThrownAssert_description_Test.java index 59e08e6f567..ee341d3dfb8 100644 --- a/src/test/java/org/assertj/core/api/throwable/NotThrownAssert_description_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/NotThrownAssert_description_Test.java @@ -25,11 +25,9 @@ import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.assertj.core.description.TextDescription; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -@DisplayName("NotThrownAssert description") class NotThrownAssert_description_Test { @BeforeAll diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getCause_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getCause_Test.java index 9bab11f0960..f94860a36b8 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getCause_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getCause_Test.java @@ -17,13 +17,11 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ThrowableAssert getCause") class ThrowableAssert_getCause_Test { - private Throwable cause = new NullPointerException(); + private final Throwable cause = new NullPointerException(); @Test void should_return_throwable_assertions_for_actual_cause() { diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getRootCause_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getRootCause_Test.java index 12c5b69f5b5..7b8c6248bac 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getRootCause_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_getRootCause_Test.java @@ -17,14 +17,12 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ThrowableAssert getRootCause") class ThrowableAssert_getRootCause_Test { - private Throwable rootCause = new NullPointerException(); - private Throwable cause = new RuntimeException(rootCause); + private final Throwable rootCause = new NullPointerException(); + private final Throwable cause = new RuntimeException(rootCause); @Test void should_return_throwable_assertions_for_actual_root_cause() { diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java index 84e4a13c951..b3d5b5c534a 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java @@ -16,9 +16,7 @@ import org.assertj.core.api.ThrowableAssert; import org.assertj.core.api.ThrowableAssertBaseTest; -import org.junit.jupiter.api.DisplayName; -@DisplayName("ThrowableAssert hasRootCauseMessage") class ThrowableAssert_hasRootCauseMessage_Test extends ThrowableAssertBaseTest { @Override diff --git a/src/test/java/org/assertj/core/error/ClassModifierShouldBe_create_Test.java b/src/test/java/org/assertj/core/error/ClassModifierShouldBe_create_Test.java index b1dc11320c3..f0f3a849cb8 100644 --- a/src/test/java/org/assertj/core/error/ClassModifierShouldBe_create_Test.java +++ b/src/test/java/org/assertj/core/error/ClassModifierShouldBe_create_Test.java @@ -19,10 +19,8 @@ import static org.assertj.core.error.ClassModifierShouldBe.shouldNotBeFinal; import org.assertj.core.internal.TestDescription; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ClassModifierShouldBe create") class ClassModifierShouldBe_create_Test { @Test diff --git a/src/test/java/org/assertj/core/error/ShouldBeEven_create_Test.java b/src/test/java/org/assertj/core/error/ShouldBeEven_create_Test.java index 954d53be2c6..7270fe53052 100644 --- a/src/test/java/org/assertj/core/error/ShouldBeEven_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldBeEven_create_Test.java @@ -20,7 +20,6 @@ import org.assertj.core.description.Description; import org.assertj.core.internal.TestDescription; import org.assertj.core.presentation.Representation; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; /** @@ -28,7 +27,6 @@ * * @author Cal027 */ -@DisplayName("ShouldBeEven create") class ShouldBeEven_create_Test { @Test diff --git a/src/test/java/org/assertj/core/error/ShouldBeInfinite_create_Test.java b/src/test/java/org/assertj/core/error/ShouldBeInfinite_create_Test.java index 390ffec64ad..e57c58a9726 100644 --- a/src/test/java/org/assertj/core/error/ShouldBeInfinite_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldBeInfinite_create_Test.java @@ -18,10 +18,8 @@ import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; import org.assertj.core.internal.TestDescription; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ShouldBeInfinite create") class ShouldBeInfinite_create_Test { @Test diff --git a/src/test/java/org/assertj/core/error/ShouldHaveBinaryContent_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveBinaryContent_create_Test.java index 80797983fc9..91a29c72ad2 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveBinaryContent_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveBinaryContent_create_Test.java @@ -20,10 +20,8 @@ import org.assertj.core.internal.BinaryDiffResult; import org.assertj.core.internal.TestDescription; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ShouldHaveBinaryContent create") class ShouldHaveBinaryContent_create_Test { @Test diff --git a/src/test/java/org/assertj/core/error/ShouldHaveDimensions_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveDimensions_create_Test.java index 7b193d99f44..94c3a9c9596 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveDimensions_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveDimensions_create_Test.java @@ -19,10 +19,8 @@ import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; import org.assertj.core.description.TextDescription; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ShouldHaveDimensions create") class ShouldHaveDimensions_create_Test { @Test diff --git a/src/test/java/org/assertj/core/util/Introspection_getProperty_Test.java b/src/test/java/org/assertj/core/util/Introspection_getProperty_Test.java index 4df97fd4ade..ac48fd84b5d 100644 --- a/src/test/java/org/assertj/core/util/Introspection_getProperty_Test.java +++ b/src/test/java/org/assertj/core/util/Introspection_getProperty_Test.java @@ -19,10 +19,8 @@ import java.lang.reflect.Method; import org.assertj.core.util.introspection.IntrospectionError; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("Introspection getProperty") class Introspection_getProperty_Test { private final Employee judy = new Employee(100000.0, 31); diff --git a/src/test/java/org/assertj/core/util/introspection/PropertyOrFieldSupport_getValueOf_Test.java b/src/test/java/org/assertj/core/util/introspection/PropertyOrFieldSupport_getValueOf_Test.java index 8e19d64b9f4..b2560d32253 100644 --- a/src/test/java/org/assertj/core/util/introspection/PropertyOrFieldSupport_getValueOf_Test.java +++ b/src/test/java/org/assertj/core/util/introspection/PropertyOrFieldSupport_getValueOf_Test.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; -import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.introspection.FieldSupport.EXTRACTION_OF_PUBLIC_FIELD_ONLY; import java.util.HashMap; @@ -27,10 +26,8 @@ import org.assertj.core.test.Employee; import org.assertj.core.test.Name; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("PropertyOrFieldSupport getValueOf") class PropertyOrFieldSupport_getValueOf_Test { private final PropertyOrFieldSupport underTest = PropertyOrFieldSupport.EXTRACTION; From 523067895bb607a55fca6e2a5bc5a05eed6bf082 Mon Sep 17 00:00:00 2001 From: GolanLevy <39908864+GolanLevy@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:30:07 +0300 Subject: [PATCH 010/123] Improve javadoc (#2274) --- .../java/org/assertj/core/api/RecursiveComparisonAssert.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/assertj/core/api/RecursiveComparisonAssert.java b/src/main/java/org/assertj/core/api/RecursiveComparisonAssert.java index 67c5b23139d..f4c6d436d1f 100644 --- a/src/main/java/org/assertj/core/api/RecursiveComparisonAssert.java +++ b/src/main/java/org/assertj/core/api/RecursiveComparisonAssert.java @@ -98,9 +98,9 @@ void setRecursiveComparisonConfiguration(RecursiveComparisonConfiguration recurs * You can specify a custom comparator or equals BiPredicate per (nested) fields or type with the methods below (but before calling {@code isEqualTo} otherwise this has no effect!): *
    *
  1. {@link #withEqualsForType(BiPredicate, Class)} for a given type
  2. + *
  3. {@link #withEqualsForFields(BiPredicate, String...)} for one or multiple fields
  4. *
  5. {@link #withComparatorForType(Comparator, Class)} for a given type
  6. - *
  7. {@link #withComparatorForFields(Comparator, String...) withComparatorForFields(Comparator, String...)} for one or multiple fields
  8. - *
  9. {@link #withComparatorForFields(Comparator, String...) withComparatorForFields(Comparator, String...)} for one or multiple fields
  10. + *
  11. {@link #withComparatorForFields(Comparator, String...)} for one or multiple fields
  12. *
*

* Note that field comparators always take precedence over type comparators. From e57c9b98b02ade99e526897c68542c4439490496 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 30 Jun 2021 06:51:29 +0200 Subject: [PATCH 011/123] Apply missing license header --- .../junit/jupiter/DefaultDisplayNameGenerator.java | 12 ++++++++++++ .../jupiter/DefaultDisplayNameGeneratorTest.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java index 8db0967df22..052fe06c59b 100644 --- a/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java +++ b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGenerator.java @@ -1,3 +1,15 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ package org.assertj.core.test.junit.jupiter; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java index f33cc9607bf..eda551a3581 100644 --- a/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java +++ b/src/test/java/org/assertj/core/test/junit/jupiter/DefaultDisplayNameGeneratorTest.java @@ -1,3 +1,15 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ package org.assertj.core.test.junit.jupiter; import static org.assertj.core.api.BDDAssertions.then; From 5e0b6f22909ce22be8ecbb4beead724e22d6d5dd Mon Sep 17 00:00:00 2001 From: Shiva <27730051+ShivakumarSwamy@users.noreply.github.com> Date: Wed, 30 Jun 2021 06:53:49 +0200 Subject: [PATCH 012/123] Add hasFileName as an alias of hasName for File assertions (#2247) --- .../assertj/core/api/AbstractFileAssert.java | 32 ++++++++++++++++++ .../api/file/FileAssert_hasFileName_Test.java | 33 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/test/java/org/assertj/core/api/file/FileAssert_hasFileName_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractFileAssert.java b/src/main/java/org/assertj/core/api/AbstractFileAssert.java index 762bcbec05b..69bc0ce71ec 100644 --- a/src/main/java/org/assertj/core/api/AbstractFileAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractFileAssert.java @@ -19,6 +19,7 @@ import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.nio.file.FileSystem; +import java.nio.file.Path; import java.security.MessageDigest; import java.util.function.Predicate; @@ -685,12 +686,43 @@ public SELF hasExtension(String expected) { * @throws AssertionError if the actual {@code File} does not have the expected name. * * @see java.io.File#getName() name definition. + * @see #hasFileName(String) */ public SELF hasName(String expected) { files.assertHasName(info, actual, expected); return myself; } + /** + * Verifies that the actual {@code File} has given name (alias of {@link #hasName(String)}). + * + *

+ * Example: + *

 File xFile = new File("somewhere/xFile.java");
+   * File xDirectory = new File("somewhere/xDirectory");
+   *
+   * // assertion will pass
+   * assertThat(xFile).hasFileName("xFile.java");
+   * assertThat(xDirectory).hasFileName("xDirectory");
+   *
+   * // assertion will fail
+   * assertThat(xFile).hasFileName("xFile");
+   * assertThat(xDirectory).hasFileName("somewhere");
+ * + * @param expected the expected {@code File} name. + * @return {@code this} assertion object. + * @throws NullPointerException if the expected name is {@code null}. + * @throws AssertionError if the actual {@code File} is {@code null}. + * @throws AssertionError if the actual {@code File} does not have the expected name. + * + * @see java.io.File#getName() name definition. + * @see #hasName(String) + * @since 3.21.0 + */ + public SELF hasFileName(String expected) { + return hasName(expected); + } + /** * Verifies that the actual {@code File} does not have a parent. * diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_hasFileName_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_hasFileName_Test.java new file mode 100644 index 00000000000..33eb018a619 --- /dev/null +++ b/src/test/java/org/assertj/core/api/file/FileAssert_hasFileName_Test.java @@ -0,0 +1,33 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.file; + +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.FileAssert; +import org.assertj.core.api.FileAssertBaseTest; + +class FileAssert_hasFileName_Test extends FileAssertBaseTest { + + private final String expected = "expected.name"; + + @Override + protected FileAssert invoke_api_method() { + return assertions.hasFileName(expected); + } + + @Override + protected void verify_internal_effects() { + verify(files).assertHasName(getInfo(assertions), getActual(assertions), expected); + } +} From f2d7c1b28f51b1fe7de23f6acb080262d7841237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Aguilar?= <42753018+Ivan12273@users.noreply.github.com> Date: Wed, 30 Jun 2021 00:04:50 -0500 Subject: [PATCH 013/123] Add isWritable as an alias of canWrite for File assertions (#2273) --- .../assertj/core/api/AbstractFileAssert.java | 29 ++++++++++++++ .../api/file/FileAssert_isWritable_Test.java | 39 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/test/java/org/assertj/core/api/file/FileAssert_isWritable_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractFileAssert.java b/src/main/java/org/assertj/core/api/AbstractFileAssert.java index 69bc0ce71ec..ae4257d9f2c 100644 --- a/src/main/java/org/assertj/core/api/AbstractFileAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractFileAssert.java @@ -555,12 +555,41 @@ public SELF hasContent(String expected) { * @return {@code this} assertion object. * @throws AssertionError if the actual {@code File} is {@code null}. * @throws AssertionError if the actual {@code File} can not be modified by the application. + * @see #isWritable() */ public SELF canWrite() { files.assertCanWrite(info, actual); return myself; } + /** + * Verifies that the actual {@code File} can be modified by the application (alias of {@link #canWrite()}. + *

+ * Example: + *

 File tmpFile = File.createTempFile("tmp", "txt");
+   * File tmpDir = Files.createTempDirectory("tmp").toFile();
+   *
+   * // assertions will pass
+   * assertThat(tmpFile).isWritable();
+   * assertThat(tmpDir).isWritable();
+   *
+   * tmpFile.setReadOnly();
+   * tmpDir.setReadOnly();
+   *
+   * // assertions will fail
+   * assertThat(tmpFile).isWritable();
+   * assertThat(tmpDir).isWritable();
+ * + * @return {@code this} assertion object. + * @throws AssertionError if the actual {@code File} is {@code null}. + * @throws AssertionError if the actual {@code File} can not be modified by the application. + * @see #canWrite() + * @since 3.21.0 + */ + public SELF isWritable() { + return canWrite(); + } + /** * Verifies that the actual {@code File} can be read by the application. *

diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_isWritable_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_isWritable_Test.java new file mode 100644 index 00000000000..9ead35800c8 --- /dev/null +++ b/src/test/java/org/assertj/core/api/file/FileAssert_isWritable_Test.java @@ -0,0 +1,39 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.file; + +import org.assertj.core.api.FileAssert; +import org.assertj.core.api.FileAssertBaseTest; + +import static org.mockito.Mockito.verify; + + +/** + * Tests for {@link FileAssert#isWritable()}. + * + * @author Ivan Aguilar + * + */ +class FileAssert_isWritable_Test extends FileAssertBaseTest { + + @Override + protected FileAssert invoke_api_method() { + return assertions.isWritable(); + } + + @Override + protected void verify_internal_effects() { + verify(files).assertCanWrite(getInfo(assertions), getActual(assertions)); + } + +} From f3d2bf407379fcad19af87ca42dc4dd313d3691c Mon Sep 17 00:00:00 2001 From: Alberto Pascual Date: Wed, 30 Jun 2021 07:11:28 +0200 Subject: [PATCH 014/123] Add isReadable as an alias of canRead for File assertions (#2249) --- .../assertj/core/api/AbstractFileAssert.java | 30 +++++++++++++++++ .../api/file/FileAssert_isReadable_Test.java | 32 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/java/org/assertj/core/api/file/FileAssert_isReadable_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractFileAssert.java b/src/main/java/org/assertj/core/api/AbstractFileAssert.java index ae4257d9f2c..9783b94832d 100644 --- a/src/main/java/org/assertj/core/api/AbstractFileAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractFileAssert.java @@ -207,6 +207,36 @@ public SELF isRelative() { return myself; } + /** + * Verifies that the actual {@code File} can be read by the application (alias of {@link #canRead()}) + * + *

+ * Example: + *

 File tmpFile = File.createTempFile("tmp", "txt");
+   * File tmpDir = Files.createTempDirectory("tmp").toFile();
+   *
+   * // assertions will pass
+   * assertThat(tmpFile).isReadable();
+   * assertThat(tmpDir).isReadable();
+   *
+   * tmpFile.setReadable(false);
+   * tmpDir.setReadable(false);
+   *
+   * // assertions will fail
+   * assertThat(tmpFile).isReadable();
+   * assertThat(tmpDir).isReadable();
+ * + * @return {@code this} assertion object. + * @throws AssertionError if the actual {@code File} is {@code null}. + * @throws AssertionError if the actual {@code File} can not be read by the application. + * + * @see #canRead() + * @since 3.21.0 + */ + public SELF isReadable() { + return canRead(); + } + /** * Verifies that the content of the actual {@code File} is equal to the content of the given one. * The charset to use when reading the actual file can be provided with {@link #usingCharset(Charset)} or diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_isReadable_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_isReadable_Test.java new file mode 100644 index 00000000000..10f77994c7f --- /dev/null +++ b/src/test/java/org/assertj/core/api/file/FileAssert_isReadable_Test.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.file; + +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.FileAssert; +import org.assertj.core.api.FileAssertBaseTest; + +class FileAssert_isReadable_Test extends FileAssertBaseTest { + + @Override + protected FileAssert invoke_api_method() { + return assertions.isReadable(); + } + + @Override + protected void verify_internal_effects() { + verify(files).assertCanRead(getInfo(assertions), getActual(assertions)); + } + +} From bb7c760b3fe04af739dc5abd3bd66dfda5062b23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Jul 2021 13:57:30 +0200 Subject: [PATCH 015/123] Bump cdg.pitest.version from 0.0.10 to 0.0.11 (#2275) * Bump cdg.pitest.version from 0.0.10 to 0.0.11 Bumps `cdg.pitest.version` from 0.0.10 to 0.0.11. Updates `pitest-git-plugin` from 0.0.10 to 0.0.11 Updates `pitest-git-maven-plugin` from 0.0.10 to 0.0.11 --- updated-dependencies: - dependency-name: com.groupcdg:pitest-git-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.groupcdg:pitest-git-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump pitest-github-maven-plugin version from 0.0.10 to 0.0.11 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefano Cordio --- .github/workflows/pitest-updated-pr.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pitest-updated-pr.yml b/.github/workflows/pitest-updated-pr.yml index 6cd67f3b305..31056107eb1 100644 --- a/.github/workflows/pitest-updated-pr.yml +++ b/.github/workflows/pitest-updated-pr.yml @@ -42,4 +42,4 @@ jobs: # The updatePR maven goal is used here with an explicit version. This allows us to upload without checking out # the code, but does mean the version here must be maintained. An alternative would be to checkout the code and use # the github goal. This will work as long as the artifact is extracted to the maven target directory - run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.10:updatePR + run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.11:updatePR diff --git a/pom.xml b/pom.xml index cf53e5d9842..931215c6397 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 2.2 1.2.0 5.3.0 - 0.0.10 + 0.0.11 4.13.2 5.7.2 From ee9d6b54082ccbcca87ab3a2f618d266070eba03 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Fri, 2 Jul 2021 23:58:55 +0200 Subject: [PATCH 016/123] Add Java 18 EA --- .github/workflows/cross-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cross-version.yml b/.github/workflows/cross-version.yml index d6dfa72a8f6..f71f2bc62cd 100644 --- a/.github/workflows/cross-version.yml +++ b/.github/workflows/cross-version.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - java: [16, 17-ea] + java: [16, 17-ea, 18-ea] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 5acaba69648dc34f2ce6cc6b627ce587aff6f5bd Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 3 Jul 2021 00:07:48 +0200 Subject: [PATCH 017/123] Remove unnecessary clean goal --- .github/workflows/cross-version.yml | 2 +- .github/workflows/main.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cross-version.yml b/.github/workflows/cross-version.yml index f71f2bc62cd..fd8fc1c5724 100644 --- a/.github/workflows/cross-version.yml +++ b/.github/workflows/cross-version.yml @@ -25,4 +25,4 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-maven - name: Test - run: ./mvnw -V --no-transfer-progress -e clean verify javadoc:javadoc + run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ba9388574b..0e329148529 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-maven - name: Test - run: ./mvnw -V --no-transfer-progress -e clean verify javadoc:javadoc + run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc sonar: name: Sonar code analysis @@ -48,7 +48,7 @@ jobs: restore-keys: ${{ runner.os }}-maven - name: Test with Sonar run: > - ./mvnw -V --no-transfer-progress -e clean verify javadoc:javadoc sonar:sonar + ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=assertj -Dsonar.projectKey=joel-costigliola_assertj-core From a043f9696d9e6a3a5aacbd2c460c8498c6430315 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 3 Jul 2021 00:12:03 +0200 Subject: [PATCH 018/123] Skip tests during binary compatibility check --- .github/workflows/binary-compatibility.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml index 32cc5357f3b..c72978549f8 100644 --- a/.github/workflows/binary-compatibility.yml +++ b/.github/workflows/binary-compatibility.yml @@ -24,6 +24,7 @@ jobs: - name: Compare run: > ./mvnw -V --no-transfer-progress -e package japicmp:cmp + -DskipTests -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true - name: Print Result run: cat target/japicmp/default-cli.diff From d491769fddb64d918bf06a7db7b58819f924985c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Jul 2021 07:37:04 +0200 Subject: [PATCH 019/123] Bump byte-buddy.version from 1.11.5 to 1.11.6 (#2277) Bumps `byte-buddy.version` from 1.11.5 to 1.11.6. Updates `byte-buddy` from 1.11.5 to 1.11.6 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.5...byte-buddy-1.11.6) Updates `byte-buddy-agent` from 1.11.5 to 1.11.6 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.5...byte-buddy-1.11.6) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 931215c6397..e95050a0fc9 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.5 + 1.11.6 2.2 1.2.0 5.3.0 From 892fb9aef423cc9828f4df41b2edbc4e8a57acec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Jul 2021 05:57:35 +0200 Subject: [PATCH 020/123] Bump jackson-databind from 2.12.3 to 2.12.4 (#2280) Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.12.3 to 2.12.4. - [Release notes](https://github.com/FasterXML/jackson/releases) - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e95050a0fc9..2226d813296 100644 --- a/pom.xml +++ b/pom.xml @@ -134,7 +134,7 @@ com.fasterxml.jackson.core jackson-databind - 2.12.3 + 2.12.4 test + + METHOD_NEW_DEFAULT + true + true + + true true From c954da6eed6a8a3ea1e8c722fea06be96e4164f3 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Thu, 8 Jul 2021 22:42:40 +1200 Subject: [PATCH 028/123] Don't use String.format to describe ComparisonDifference in case the given string has a % that must not be interpreted Fixes #2279 --- ...cursiveComparisonDifferenceCalculator.java | 28 ++++++++++--------- ...nAssert_isEqualTo_with_iterables_Test.java | 18 ++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java b/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java index f21d07c9508..82563680522 100644 --- a/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java +++ b/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java @@ -82,8 +82,8 @@ void addDifference(DualValue dualValue) { differences.add(new ComparisonDifference(dualValue)); } - void addDifference(DualValue dualValue, String description, Object... args) { - differences.add(new ComparisonDifference(dualValue, format(description, args))); + void addDifference(DualValue dualValue, String description) { + differences.add(new ComparisonDifference(dualValue, description)); } void addKeyDifference(DualValue parentDualValue, Object actualKey, Object expectedKey) { @@ -268,8 +268,8 @@ private static List determineDifferences(Object actual, Ob Class actualFieldValueClass = actualFieldValue.getClass(); Class expectedFieldClass = expectedFieldValue.getClass(); if (recursiveComparisonConfiguration.isInStrictTypeCheckingMode() && expectedTypeIsNotSubtypeOfActualType(dualValue)) { - comparisonState.addDifference(dualValue, STRICT_TYPE_ERROR, expectedFieldClass.getName(), - actualFieldValueClass.getName()); + comparisonState.addDifference(dualValue, + format(STRICT_TYPE_ERROR, expectedFieldClass.getName(), actualFieldValueClass.getName())); continue; } @@ -347,7 +347,7 @@ private static void compareArrays(DualValue dualValue, ComparisonState compariso int actualArrayLength = Array.getLength(dualValue.actual); int expectedArrayLength = Array.getLength(dualValue.expected); if (actualArrayLength != expectedArrayLength) { - comparisonState.addDifference(dualValue, DIFFERENT_SIZE_ERROR, "arrays", actualArrayLength, expectedArrayLength); + comparisonState.addDifference(dualValue, format(DIFFERENT_SIZE_ERROR, "arrays", actualArrayLength, expectedArrayLength)); // no need to inspect elements, arrays are not equal as they don't have the same size return; } @@ -367,15 +367,16 @@ private static void compareArrays(DualValue dualValue, ComparisonState compariso private static void compareOrderedCollections(DualValue dualValue, ComparisonState comparisonState) { if (!dualValue.isActualFieldAnOrderedCollection()) { // at the moment if expected is an ordered collection then actual should also be one - comparisonState.addDifference(dualValue, ACTUAL_NOT_ORDERED_COLLECTION, dualValue.actual.getClass().getCanonicalName()); + comparisonState.addDifference(dualValue, + format(ACTUAL_NOT_ORDERED_COLLECTION, dualValue.actual.getClass().getCanonicalName())); return; } Collection actualCollection = (Collection) dualValue.actual; Collection expectedCollection = (Collection) dualValue.expected; if (actualCollection.size() != expectedCollection.size()) { - comparisonState.addDifference(dualValue, DIFFERENT_SIZE_ERROR, - "collections", actualCollection.size(), expectedCollection.size()); + comparisonState.addDifference(dualValue, format(DIFFERENT_SIZE_ERROR, "collections", actualCollection.size(), + expectedCollection.size())); // no need to inspect elements, arrays are not equal as they don't have the same size return; } @@ -406,7 +407,7 @@ private static void compareUnorderedIterables(DualValue dualValue, ComparisonSta int actualSize = sizeOf(actual); int expectedSize = sizeOf(expected); if (actualSize != expectedSize) { - comparisonState.addDifference(dualValue, DIFFERENT_SIZE_ERROR, "collections", actualSize, expectedSize); + comparisonState.addDifference(dualValue, format(DIFFERENT_SIZE_ERROR, "collections", actualSize, expectedSize)); // no need to inspect elements, iterables are not equal as they don't have the same size return; // TODO instead we could register the diff between expected and actual that is: @@ -456,7 +457,7 @@ private static void compareSortedMap(DualValue dualValue, ComparisonState @SuppressWarnings("unchecked") Map expectedMap = (Map) dualValue.expected; if (actualMap.size() != expectedMap.size()) { - comparisonState.addDifference(dualValue, DIFFERENT_SIZE_ERROR, "sorted maps", actualMap.size(), expectedMap.size()); + comparisonState.addDifference(dualValue, format(DIFFERENT_SIZE_ERROR, "sorted maps", actualMap.size(), expectedMap.size())); // no need to inspect entries, maps are not equal as they don't have the same size return; // TODO instead we could register the diff between expected and actual that is: @@ -487,7 +488,7 @@ private static void compareUnorderedMap(DualValue dualValue, ComparisonState com Map actualMap = (Map) dualValue.actual; Map expectedMap = (Map) dualValue.expected; if (actualMap.size() != expectedMap.size()) { - comparisonState.addDifference(dualValue, DIFFERENT_SIZE_ERROR, "maps", actualMap.size(), expectedMap.size()); + comparisonState.addDifference(dualValue, format(DIFFERENT_SIZE_ERROR, "maps", actualMap.size(), expectedMap.size())); // no need to inspect entries, maps are not equal as they don't have the same size return; // TODO instead we could register the diff between expected and actual that is: @@ -507,8 +508,9 @@ private static void compareUnorderedMap(DualValue dualValue, ComparisonState com .collect(toMap(entry -> entry.getKey(), entry -> actualMap.get(entry.getKey()))); if (!unmatchedActualEntries.isEmpty()) { - comparisonState.addDifference(dualValue, "The following actual map entries were not found in the expected map:%n %s", - unmatchedActualEntries); + comparisonState.addDifference(dualValue, + format("The following actual map entries were not found in the expected map:%n %s", + unmatchedActualEntries)); return; } diff --git a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_with_iterables_Test.java b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_with_iterables_Test.java index d62a7220311..7dc87643e4b 100644 --- a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_with_iterables_Test.java +++ b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_with_iterables_Test.java @@ -16,6 +16,8 @@ import static java.lang.String.format; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.Assertions.tuple; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.recursive.comparison.Author.authorsTreeSet; import static org.assertj.core.util.Arrays.array; @@ -29,9 +31,11 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.UnknownFormatConversionException; import java.util.stream.Stream; import org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest; +import org.assertj.core.groups.Tuple; import org.assertj.core.internal.objects.data.PersonDto; import org.assertj.core.test.Person; import org.junit.jupiter.api.Test; @@ -222,6 +226,20 @@ void should_report_unmatched_duplicate_elements_even_if_the_first_was_matched() + " [aaa]")); } + // https://github.com/assertj/assertj-core/issues/2279 + @Test + void should_not_throw_UnknownFormatConversionException_when_unmatched_elements_have_percent_in_their_description() { + // GIVEN + List first = list(tuple("VtQh0ZAo%s2FKCnQcirWL", "foo % %d"), tuple("%F", "VtQh0ZAo%s2FKCnQcirWL")); + List second = list(tuple("%F", "VtQh0ZAo%s2FKCnQcirWL"), tuple("VtQh0ZAo%s2FKCnQcirWL", "bar % %d")); + // WHEN + Throwable thrown = catchThrowable(() -> assertThat(first).usingRecursiveComparison() + .ignoringCollectionOrder() + .isEqualTo(second)); + // THEN + then(thrown).isNotInstanceOf(UnknownFormatConversionException.class); + } + public static class WithCollection { public Collection group; From 5b769d0c027d018c79074d4862a70bd7c53aa7bc Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Thu, 8 Jul 2021 22:42:58 +1200 Subject: [PATCH 029/123] Remove unused import --- .../comparison/RecursiveComparisonAssert_isEqualTo_Test.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_Test.java index 0738f02e82c..1700672600b 100644 --- a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_Test.java @@ -23,7 +23,6 @@ import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING; import static org.assertj.core.util.Lists.list; -import static org.junit.jupiter.api.condition.OS.WINDOWS; import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.Mockito.verify; @@ -41,7 +40,6 @@ import org.assertj.core.internal.objects.data.Person; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; From f5fbc1c12c3487ac015e71f3531de38e1bc65163 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Mon, 5 Jul 2021 21:44:02 +1200 Subject: [PATCH 030/123] Add content() to Path assertions to allow string assertions on the Path content. Fixes #2252 --- .../assertj/core/api/AbstractPathAssert.java | 61 +++++++++++++++++++ .../org/assertj/core/api/SoftProxies.java | 1 + .../core/api/BDDSoftAssertionsTest.java | 25 ++++++++ .../assertj/core/api/SoftAssertionsTest.java | 26 ++++++++ ...umptions_assumeThat_with_content_Test.java | 61 +++++++++++++++++++ .../api/path/PathAssert_content_Test.java | 54 ++++++++++++++++ .../PathAssert_content_with_charset_Test.java | 55 +++++++++++++++++ .../assertj/core/internal/PathsBaseTest.java | 54 ++++++++-------- 8 files changed, 310 insertions(+), 27 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java create mode 100644 src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java create mode 100644 src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index 68fca97f816..5764449a716 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -12,9 +12,12 @@ */ package org.assertj.core.api; +import static java.lang.String.format; +import static java.nio.file.Files.readAllBytes; import static java.util.Objects.requireNonNull; import static org.assertj.core.util.Preconditions.checkArgument; +import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.nio.file.ClosedFileSystemException; @@ -1812,4 +1815,62 @@ public SELF isNotEmptyFile() { return myself; } + /** + * Returns String assertions on the content of the actual {@code Path} read with the {@link Charset#defaultCharset() default charset}. + *

+ * Example: + *

 Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());
+   *
+   * // assertion succeeds (default charset is used to read xFile content):
+   * assertThat(xFile).content().startsWith("The Truth Is ");
+   *
+   * // assertion fails:
+   * assertThat(xFile).content().contains("Elsewhere");
+ * + * @return a StringAssert object with the content of the actual {@code Path} read with the default {@link Charset}. + * @throws AssertionError if the actual {@code Path} is not readable as per {@link Files#isReadable(Path)}. + * @throws UncheckedIOException when failing to read the actual {@code Path}. + * @since 3.21.0 + */ + public AbstractStringAssert content() { + // does not call content(Charset.defaultCharset()) to avoid double proxying in soft assertions. + return internalContent(Charset.defaultCharset()); + } + + /** + * Returns String assertions on the content of the actual {@code Path} read with the given {@link Charset}. + *

+ * Example: + *

 Path utf8Path = Files.write(Paths.get("utf8.txt"), "é à".getBytes());
+   *
+   * // assertion succeeds:
+   * assertThat(utf8Path).content(StandardCharsets.UTF_8).endsWith("é à");
+   *
+   * // assertion fails:
+   * assertThat(utf8Path).content(StandardCharsets.UTF_8).contains("e");
+ * + * @param charset the {@link Charset} to use to read the actual {@link Path}. + * @return a {@link StringAssert} object with the content of the actual {@code Path} read with the default {@link Charset}. + * @throws AssertionError if the actual {@code Path} is not readable as per {@link Files#isReadable(Path)}. + * @throws UncheckedIOException when failing to read the actual {@code Path}. + * @since 3.21.0 + */ + public AbstractStringAssert content(Charset charset) { + return internalContent(charset); + } + + // this method was introduced to avoid to avoid double proxying in soft assertions for content() + private AbstractStringAssert internalContent(Charset charset) { + paths.assertIsReadable(info, actual); + String pathContent = readPath(charset); + return new StringAssert(pathContent); + } + + private String readPath(Charset charset) { + try { + return new String(readAllBytes(actual), charset); + } catch (IOException e) { + throw new UncheckedIOException(format("Failed to read %s content with %s charset", actual, charset), e); + } + } } diff --git a/src/main/java/org/assertj/core/api/SoftProxies.java b/src/main/java/org/assertj/core/api/SoftProxies.java index 08e0b237791..fe686edfa65 100644 --- a/src/main/java/org/assertj/core/api/SoftProxies.java +++ b/src/main/java/org/assertj/core/api/SoftProxies.java @@ -46,6 +46,7 @@ class SoftProxies { "asList", "asString", "asHexString", + "content", "decodedAsBase64", "encodedAsBase64", "extracting", diff --git a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java index c834d0e79c8..93295c30903 100644 --- a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java @@ -13,6 +13,7 @@ package org.assertj.core.api; import static java.lang.String.format; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.emptyList; import static java.util.Spliterators.emptySpliterator; import static java.util.stream.Collectors.toList; @@ -23,6 +24,7 @@ import static org.assertj.core.api.Assertions.entry; import static org.assertj.core.api.Assertions.in; import static org.assertj.core.api.Assertions.tuple; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.InstanceOfAssertFactories.STRING; import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -42,6 +44,7 @@ import java.math.BigDecimal; import java.net.MalformedURLException; import java.net.URI; +import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; @@ -1845,4 +1848,26 @@ void should_collect_errors_when_using_extractingFromEntries_with_map() { } } + @Test + void path_soft_assertions_should_report_errors_on_methods_that_switch_the_object_under_test() { + // GIVEN + Path path = new File("src/test/resources/actual_file.txt").toPath(); + // WHEN + softly.then(path) + .overridingErrorMessage("error message") + .as("content()") + .content() + .startsWith("actual") + .startsWith("123"); + softly.then(path) + .overridingErrorMessage("error message") + .as("content(UTF_8)") + .content(UTF_8) + .startsWith("actual") + .startsWith("123"); + // THEN + then(softly.errorsCollected()).extracting(Throwable::getMessage) + .containsExactly("[content()] error message", + "[content(UTF_8)] error message"); + } } diff --git a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java index 5ca83dfbf24..c695cba57c3 100644 --- a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java @@ -13,6 +13,7 @@ package org.assertj.core.api; import static java.lang.String.format; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.emptyList; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.as; @@ -46,6 +47,7 @@ import java.math.BigDecimal; import java.net.MalformedURLException; import java.net.URI; +import java.nio.file.Path; import java.time.Duration; import java.time.LocalTime; import java.time.OffsetTime; @@ -2500,4 +2502,28 @@ void throwable_soft_assertions_should_work_with_navigation_method_get_root_cause assertThat(errorsCollected.get(0)).hasMessageContaining("not top level message"); assertThat(errorsCollected.get(1)).hasMessageContaining("not root cause message"); } + + @Test + void path_soft_assertions_should_report_errors_on_methods_that_switch_the_object_under_test() { + // GIVEN + Path path = new File("src/test/resources/actual_file.txt").toPath(); + // WHEN + softly.assertThat(path) + .overridingErrorMessage("error message") + .as("content()") + .content() + .startsWith("actual") + .startsWith("123"); + softly.assertThat(path) + .overridingErrorMessage("error message") + .as("content(UTF_8)") + .content(UTF_8) + .startsWith("actual") + .startsWith("123"); + // THEN + then(softly.errorsCollected()).extracting(Throwable::getMessage) + .containsExactly("[content()] error message", + "[content(UTF_8)] error message"); + } + } diff --git a/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java b/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java new file mode 100644 index 00000000000..e94ce50f42e --- /dev/null +++ b/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java @@ -0,0 +1,61 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.assumptions; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assumptions.assumeThat; +import static org.assertj.core.api.BDDAssertions.thenCode; +import static org.assertj.core.util.AssertionsUtil.expectAssumptionNotMetException; + +import java.io.File; +import java.nio.file.Path; + +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.Test; + +class Assumptions_assumeThat_with_content_Test { + + private static final Path PATH = new File("src/test/resources/actual_file.txt").toPath(); + + @Test + void should_run_test_when_assumption_using_path_content_succeeds() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(PATH).content().contains("actual"); + // THEN + thenCode(assumptionCode).doesNotThrowAnyException(); + } + + @Test + void should_ignore_test_when_assumption_using_path_content_fails() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(PATH).content().contains("foo"); + // THEN + expectAssumptionNotMetException(assumptionCode); + } + + @Test + void should_run_test_when_assumption_using_path_content_with_charset_succeeds() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(PATH).content(UTF_8).contains("actual"); + // THEN + thenCode(assumptionCode).doesNotThrowAnyException(); + } + + @Test + void should_ignore_test_when_assumption_using_path_content_with_charset_fails() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(PATH).content(UTF_8).contains("foo"); + // THEN + expectAssumptionNotMetException(assumptionCode); + } +} diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java new file mode 100644 index 00000000000..971ce58ef58 --- /dev/null +++ b/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java @@ -0,0 +1,54 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.path; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import java.io.File; +import java.nio.file.Path; + +import org.assertj.core.api.AbstractStringAssert; +import org.assertj.core.api.PathAssert; +import org.assertj.core.api.PathAssertBaseTest; +import org.junit.jupiter.api.Test; + +class PathAssert_content_Test extends PathAssertBaseTest { + + @Override + protected PathAssert invoke_api_method() { + assertions.content(); + return assertions; + } + + @Override + protected void verify_internal_effects() { + verify(paths).assertIsReadable(getInfo(assertions), getActual(assertions)); + } + + @Override + protected PathAssert create_assertions() { + return new PathAssert(new File("src/test/resources/actual_file.txt").toPath()); + } + + @Test + public void should_return_StringAssert_on_path_content() { + // GIVEN + Path path = new File("src/test/resources/actual_file.txt").toPath(); + // WHEN + AbstractStringAssert stringAssert = assertThat(path).content(); + // THEN + stringAssert.isEqualTo("actual%n", ""); + } + +} diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java new file mode 100644 index 00000000000..f0194c0a935 --- /dev/null +++ b/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java @@ -0,0 +1,55 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.path; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import java.io.File; +import java.nio.file.Path; + +import org.assertj.core.api.AbstractStringAssert; +import org.assertj.core.api.PathAssert; +import org.assertj.core.api.PathAssertBaseTest; +import org.junit.jupiter.api.Test; + +class PathAssert_content_with_charset_Test extends PathAssertBaseTest { + + @Override + protected PathAssert invoke_api_method() { + assertions.content(UTF_8); + return assertions; + } + + @Override + protected void verify_internal_effects() { + verify(paths).assertIsReadable(getInfo(assertions), getActual(assertions)); + } + + @Override + protected PathAssert create_assertions() { + return new PathAssert(new File("src/test/resources/actual_file.txt").toPath()); + } + + @Test + public void should_return_StringAssert_on_path_content_with_given_charset() { + // GIVEN + Path path = new File("src/test/resources/utf8.txt").toPath(); + // WHEN + AbstractStringAssert stringAssert = assertThat(path).content(UTF_8); + // THEN + stringAssert.contains("é à"); + } + +} diff --git a/src/test/java/org/assertj/core/internal/PathsBaseTest.java b/src/test/java/org/assertj/core/internal/PathsBaseTest.java index 8b5c9fbbb68..613874ca473 100644 --- a/src/test/java/org/assertj/core/internal/PathsBaseTest.java +++ b/src/test/java/org/assertj/core/internal/PathsBaseTest.java @@ -64,15 +64,15 @@ public abstract class PathsBaseTest { @BeforeEach public void setUp() { - failures = spy(new Failures()); - nioFilesWrapper = mock(NioFilesWrapper.class); - paths = new Paths(nioFilesWrapper); - paths.failures = failures; - info = someInfo(); - diff = mock(Diff.class); - paths.diff = diff; - binaryDiff = mock(BinaryDiff.class); - paths.binaryDiff = binaryDiff; + failures = spy(new Failures()); + nioFilesWrapper = mock(NioFilesWrapper.class); + paths = new Paths(nioFilesWrapper); + paths.failures = failures; + info = someInfo(); + diff = mock(Diff.class); + paths.diff = diff; + binaryDiff = mock(BinaryDiff.class); + paths.binaryDiff = binaryDiff; } /** @@ -80,26 +80,26 @@ public void setUp() { */ public static class FileSystemResource { - private final FileSystem fs; + private final FileSystem fs; - public FileSystemResource() { - try { - fs = MemoryFileSystemBuilder.newLinux().build("PathsTest"); - } catch (IOException e) { - throw new RuntimeException("failed to initialize filesystem", e); - } - } + public FileSystemResource() { + try { + fs = MemoryFileSystemBuilder.newLinux().build("PathsTest"); + } catch (IOException e) { + throw new RuntimeException("failed to initialize filesystem", e); + } + } - public FileSystem getFileSystem() { - return fs; - } + public FileSystem getFileSystem() { + return fs; + } - public void close() { - try { - fs.close(); - } catch (IOException e) { - throw new RuntimeException("failed to close filesystem", e); - } - } + public void close() { + try { + fs.close(); + } catch (IOException e) { + throw new RuntimeException("failed to close filesystem", e); + } + } } } \ No newline at end of file From a62eccc055e86a9549bad290d8c3cdbcfac723b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 10 Jul 2021 13:17:11 +0200 Subject: [PATCH 031/123] Bump equalsverifier from 3.6.1 to 3.7 (#2284) Bumps [equalsverifier](https://github.com/jqno/equalsverifier) from 3.6.1 to 3.7. - [Release notes](https://github.com/jqno/equalsverifier/releases) - [Changelog](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md) - [Commits](https://github.com/jqno/equalsverifier/compare/equalsverifier-3.6.1...equalsverifier-3.7) --- updated-dependencies: - dependency-name: nl.jqno.equalsverifier:equalsverifier dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bcf07565d7d..1d949c22c0e 100644 --- a/pom.xml +++ b/pom.xml @@ -174,7 +174,7 @@ nl.jqno.equalsverifier equalsverifier - 3.6.1 + 3.7 test From 56f3e24449dc66193ce31e1a72a2f67ad1ff6761 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 10 Jul 2021 23:14:21 +0200 Subject: [PATCH 032/123] Add binary compatibility check of branches against `main` (#2285) --- .github/workflows/binary-compatibility.yml | 34 +++++++++++++++++----- pom.xml | 20 +++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml index 90ccd12898c..cb5e4294bf9 100644 --- a/.github/workflows/binary-compatibility.yml +++ b/.github/workflows/binary-compatibility.yml @@ -1,15 +1,21 @@ name: Binary Compatibility -on: - push: - branches: [ main ] +on: [push, pull_request] jobs: japicmp: - name: Compare with the latest release + name: Verify runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + + - name: (branch only) Checkout `main` into subfolder + if: github.ref != 'refs/heads/main' + uses: actions/checkout@v2 + with: + ref: main + path: assertj-core.main + - name: Setup Java uses: actions/setup-java@v2 with: @@ -21,15 +27,29 @@ jobs: path: ~/.m2 key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-maven - - name: Compare + + - name: (`main` only) Compare with the latest release + if: github.ref == 'refs/heads/main' run: > ./mvnw -V --no-transfer-progress -e package japicmp:cmp -DskipTests -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true - - name: Print Result + + - name: (branch only) Build `main` + if: github.ref != 'refs/heads/main' + run: ./mvnw -V --no-transfer-progress -e -f assertj-core.main/pom.xml package -DskipTests + - name: (branch only) Compare with `main` + if: github.ref != 'refs/heads/main' + run: > + ./mvnw -V --no-transfer-progress -e -Pjapicmp-branch package japicmp:cmp + -DskipTests + -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true + -Djapicmp.oldVersion.basedir=assertj-core.main + + - name: Print result if: success() || failure() run: cat target/japicmp/default-cli.diff - - name: Upload Reports + - name: Upload reports if: success() || failure() uses: actions/upload-artifact@v2 with: diff --git a/pom.xml b/pom.xml index 1d949c22c0e..0f8ee83d459 100644 --- a/pom.xml +++ b/pom.xml @@ -769,6 +769,26 @@ + + japicmp-branch + + + + + com.github.siom79.japicmp + japicmp-maven-plugin + + + + ${japicmp.oldVersion.basedir}/target/${project.build.finalName}.${project.packaging} + + + + + + + +
From 38b8667659735cfee90de218aee74a2656d1c07e Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Sun, 11 Jul 2021 21:50:38 +1200 Subject: [PATCH 033/123] Add content() to File assertions to allow string assertions on the Path content. Fixes #2198 Co-authored-by: Wenhao ZHANG --- .../assertj/core/api/AbstractFileAssert.java | 63 ++++++++++++++++++- .../core/api/BDDSoftAssertionsTest.java | 23 +++++++ .../assertj/core/api/SoftAssertionsTest.java | 22 +++++++ ...ons_assumeThat_with_File_content_Test.java | 60 ++++++++++++++++++ ...ns_assumeThat_with_Path_content_Test.java} | 2 +- .../api/file/FileAssert_content_Test.java | 54 ++++++++++++++++ .../FileAssert_content_with_charset_Test.java | 54 ++++++++++++++++ .../api/path/PathAssert_content_Test.java | 3 +- .../PathAssert_content_with_charset_Test.java | 2 +- 9 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_File_content_Test.java rename src/test/java/org/assertj/core/api/assumptions/{Assumptions_assumeThat_with_content_Test.java => Assumptions_assumeThat_with_Path_content_Test.java} (97%) create mode 100644 src/test/java/org/assertj/core/api/file/FileAssert_content_Test.java create mode 100644 src/test/java/org/assertj/core/api/file/FileAssert_content_with_charset_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractFileAssert.java b/src/main/java/org/assertj/core/api/AbstractFileAssert.java index 9783b94832d..2b55278feb6 100644 --- a/src/main/java/org/assertj/core/api/AbstractFileAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractFileAssert.java @@ -12,14 +12,16 @@ */ package org.assertj.core.api; +import static java.lang.String.format; +import static java.nio.file.Files.readAllBytes; import static java.util.Objects.requireNonNull; import static org.assertj.core.util.Preconditions.checkArgument; import java.io.File; +import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.nio.file.FileSystem; -import java.nio.file.Path; import java.security.MessageDigest; import java.util.function.Predicate; @@ -1325,4 +1327,63 @@ public SELF isNotEmpty() { files.assertIsNotEmptyFile(info, actual); return myself; } + + /** + * Returns String assertions on the content of the actual {@code File} read with the {@link Charset#defaultCharset() default charset}. + *

+ * Example: + *

 File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();
+   *
+   * // assertion succeeds (default charset is used to read xFile content):
+   * assertThat(xFile).content().startsWith("The Truth Is ");
+   *
+   * // assertion fails:
+   * assertThat(xFile).content().contains("Elsewhere");
+ * + * @return a StringAssert object with the content of the actual {@code File} read with the default {@link Charset}. + * @throws AssertionError if the actual {@code File} is not readable. + * @throws UncheckedIOException when failing to read the actual {@code File}. + * @since 3.21.0 + */ + public AbstractStringAssert content() { + // does not call content(Charset.defaultCharset()) to avoid double proxying in soft assertions. + return internalContent(Charset.defaultCharset()); + } + + /** + * Returns String assertions on the content of the actual {@code File} read with the given {@link Charset}. + *

+ * Example: + *

 File utf8File = Files.write(Paths.get("utf8.txt"), "é à".getBytes()).toFile();
+   *
+   * // assertion succeeds:
+   * assertThat(utf8File).content(StandardCharsets.UTF_8).endsWith("é à");
+   *
+   * // assertion fails:
+   * assertThat(utf8File).content(StandardCharsets.UTF_8).contains("e");
+ * + * @param charset the {@link Charset} to use to read the actual {@link File}. + * @return a {@link StringAssert} object with the content of the actual {@code File} read with the default {@link Charset}. + * @throws AssertionError if the actual {@code File} is not readable. + * @throws UncheckedIOException when failing to read the actual {@code File}. + * @since 3.21.0 + */ + public AbstractStringAssert content(Charset charset) { + return internalContent(charset); + } + + // this method was introduced to avoid to avoid double proxying in soft assertions for content() + private AbstractStringAssert internalContent(Charset charset) { + files.assertCanRead(info, actual); + String fileContent = readFile(charset); + return new StringAssert(fileContent); + } + + private String readFile(Charset charset) { + try { + return new String(readAllBytes(actual.toPath()), charset); + } catch (IOException e) { + throw new UncheckedIOException(format("Failed to read %s content with %s charset", actual, charset), e); + } + } } diff --git a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java index 93295c30903..d44327511ad 100644 --- a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java @@ -1870,4 +1870,27 @@ void path_soft_assertions_should_report_errors_on_methods_that_switch_the_object .containsExactly("[content()] error message", "[content(UTF_8)] error message"); } + + @Test + void file_soft_assertions_should_report_errors_on_methods_that_switch_the_object_under_test() { + // GIVEN + File file = new File("src/test/resources/actual_file.txt"); + // WHEN + softly.then(file) + .overridingErrorMessage("error message") + .as("content()") + .content() + .startsWith("actual") + .startsWith("123"); + softly.then(file) + .overridingErrorMessage("error message") + .as("content(UTF_8)") + .content(UTF_8) + .startsWith("actual") + .startsWith("123"); + // THEN + then(softly.errorsCollected()).extracting(Throwable::getMessage) + .containsExactly("[content()] error message", + "[content(UTF_8)] error message"); + } } diff --git a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java index c695cba57c3..abc316278db 100644 --- a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java @@ -2526,4 +2526,26 @@ void path_soft_assertions_should_report_errors_on_methods_that_switch_the_object "[content(UTF_8)] error message"); } + @Test + void file_soft_assertions_should_report_errors_on_methods_that_switch_the_object_under_test() { + // GIVEN + File file = new File("src/test/resources/actual_file.txt"); + // WHEN + softly.assertThat(file) + .overridingErrorMessage("error message") + .as("content()") + .content() + .startsWith("actual") + .startsWith("123"); + softly.assertThat(file) + .overridingErrorMessage("error message") + .as("content(UTF_8)") + .content(UTF_8) + .startsWith("actual") + .startsWith("123"); + // THEN + then(softly.errorsCollected()).extracting(Throwable::getMessage) + .containsExactly("[content()] error message", + "[content(UTF_8)] error message"); + } } diff --git a/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_File_content_Test.java b/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_File_content_Test.java new file mode 100644 index 00000000000..9d5bfaa2f8c --- /dev/null +++ b/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_File_content_Test.java @@ -0,0 +1,60 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.assumptions; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assumptions.assumeThat; +import static org.assertj.core.api.BDDAssertions.thenCode; +import static org.assertj.core.util.AssertionsUtil.expectAssumptionNotMetException; + +import java.io.File; + +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.Test; + +class Assumptions_assumeThat_with_File_content_Test { + + private static final File FILE = new File("src/test/resources/actual_file.txt"); + + @Test + void should_run_test_when_assumption_using_file_content_succeeds() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(FILE).content().contains("actual"); + // THEN + thenCode(assumptionCode).doesNotThrowAnyException(); + } + + @Test + void should_ignore_test_when_assumption_using_file_content_fails() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(FILE).content().contains("foo"); + // THEN + expectAssumptionNotMetException(assumptionCode); + } + + @Test + void should_run_test_when_assumption_using_file_content_with_charset_succeeds() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(FILE).content(UTF_8).contains("actual"); + // THEN + thenCode(assumptionCode).doesNotThrowAnyException(); + } + + @Test + void should_ignore_test_when_assumption_using_file_content_with_charset_fails() { + // WHEN + ThrowingCallable assumptionCode = () -> assumeThat(FILE).content(UTF_8).contains("foo"); + // THEN + expectAssumptionNotMetException(assumptionCode); + } +} diff --git a/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java b/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_Path_content_Test.java similarity index 97% rename from src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java rename to src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_Path_content_Test.java index e94ce50f42e..0e90c906697 100644 --- a/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_content_Test.java +++ b/src/test/java/org/assertj/core/api/assumptions/Assumptions_assumeThat_with_Path_content_Test.java @@ -23,7 +23,7 @@ import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.Test; -class Assumptions_assumeThat_with_content_Test { +class Assumptions_assumeThat_with_Path_content_Test { private static final Path PATH = new File("src/test/resources/actual_file.txt").toPath(); diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_content_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_content_Test.java new file mode 100644 index 00000000000..6f0296f57a9 --- /dev/null +++ b/src/test/java/org/assertj/core/api/file/FileAssert_content_Test.java @@ -0,0 +1,54 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.file; + +import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import java.io.File; + +import org.assertj.core.api.AbstractStringAssert; +import org.assertj.core.api.FileAssert; +import org.assertj.core.api.FileAssertBaseTest; +import org.junit.jupiter.api.Test; + +class FileAssert_content_Test extends FileAssertBaseTest { + + @Override + protected FileAssert invoke_api_method() { + assertions.content(); + return assertions; + } + + @Override + protected void verify_internal_effects() { + verify(files).assertCanRead(getInfo(assertions), getActual(assertions)); + } + + @Override + protected FileAssert create_assertions() { + return new FileAssert(new File("src/test/resources/actual_file.txt")); + } + + @Test + public void should_return_StringAssert_on_path_content() { + // GIVEN + File file = new File("src/test/resources/actual_file.txt"); + // WHEN + AbstractStringAssert stringAssert = assertThat(file).content(); + // THEN + stringAssert.isEqualTo(format("actual%n")); + } + +} diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_content_with_charset_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_content_with_charset_Test.java new file mode 100644 index 00000000000..eabd94c940a --- /dev/null +++ b/src/test/java/org/assertj/core/api/file/FileAssert_content_with_charset_Test.java @@ -0,0 +1,54 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.file; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import java.io.File; + +import org.assertj.core.api.AbstractStringAssert; +import org.assertj.core.api.FileAssert; +import org.assertj.core.api.FileAssertBaseTest; +import org.junit.jupiter.api.Test; + +class FileAssert_content_with_charset_Test extends FileAssertBaseTest { + + @Override + protected FileAssert invoke_api_method() { + assertions.content(UTF_8); + return assertions; + } + + @Override + protected void verify_internal_effects() { + verify(files).assertCanRead(getInfo(assertions), getActual(assertions)); + } + + @Override + protected FileAssert create_assertions() { + return new FileAssert(new File("src/test/resources/utf8.txt")); + } + + @Test + public void should_return_StringAssert_on_path_content() { + // GIVEN + File file = new File("src/test/resources/utf8.txt"); + // WHEN + AbstractStringAssert stringAssert = assertThat(file).content(UTF_8); + // THEN + stringAssert.contains("é à"); + } + +} diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java index 971ce58ef58..b84de296864 100644 --- a/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java +++ b/src/test/java/org/assertj/core/api/path/PathAssert_content_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.api.path; +import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; @@ -48,7 +49,7 @@ public void should_return_StringAssert_on_path_content() { // WHEN AbstractStringAssert stringAssert = assertThat(path).content(); // THEN - stringAssert.isEqualTo("actual%n", ""); + stringAssert.isEqualTo(format("actual%n")); } } diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java index f0194c0a935..8ef6d1d3f33 100644 --- a/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java +++ b/src/test/java/org/assertj/core/api/path/PathAssert_content_with_charset_Test.java @@ -39,7 +39,7 @@ protected void verify_internal_effects() { @Override protected PathAssert create_assertions() { - return new PathAssert(new File("src/test/resources/actual_file.txt").toPath()); + return new PathAssert(new File("src/test/resources/utf8.txt").toPath()); } @Test From 91274f9f41585c784afeae51de83ccba7c1cf948 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 11 Jul 2021 22:32:30 +0200 Subject: [PATCH 034/123] Run binary compatibility only during PRs, use parameterized target (#2286) --- .github/workflows/binary-compatibility.yml | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml index cb5e4294bf9..c17ecbf8ad5 100644 --- a/.github/workflows/binary-compatibility.yml +++ b/.github/workflows/binary-compatibility.yml @@ -1,6 +1,10 @@ name: Binary Compatibility -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: jobs: japicmp: @@ -9,12 +13,12 @@ jobs: steps: - uses: actions/checkout@v2 - - name: (branch only) Checkout `main` into subfolder - if: github.ref != 'refs/heads/main' + - name: (PR only) Checkout `${{ github.base_ref }}` into subfolder + if: github.base_ref != null uses: actions/checkout@v2 with: - ref: main - path: assertj-core.main + ref: ${{ github.base_ref }} + path: assertj-core.${{ github.base_ref }} - name: Setup Java uses: actions/setup-java@v2 @@ -29,22 +33,22 @@ jobs: restore-keys: ${{ runner.os }}-maven - name: (`main` only) Compare with the latest release - if: github.ref == 'refs/heads/main' + if: github.base_ref == null run: > ./mvnw -V --no-transfer-progress -e package japicmp:cmp -DskipTests -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true - - name: (branch only) Build `main` - if: github.ref != 'refs/heads/main' - run: ./mvnw -V --no-transfer-progress -e -f assertj-core.main/pom.xml package -DskipTests - - name: (branch only) Compare with `main` - if: github.ref != 'refs/heads/main' + - name: (PR only) Build `${{ github.base_ref }}` + if: github.base_ref != null + run: ./mvnw -V --no-transfer-progress -e -f assertj-core.${{ github.base_ref }}/pom.xml package -DskipTests + - name: (PR only) Compare `${{ github.head_ref }}` with `${{ github.base_ref }}` + if: github.base_ref != null run: > ./mvnw -V --no-transfer-progress -e -Pjapicmp-branch package japicmp:cmp -DskipTests -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true - -Djapicmp.oldVersion.basedir=assertj-core.main + -Djapicmp.oldVersion.basedir=assertj-core.${{ github.base_ref }} - name: Print result if: success() || failure() From d3b14c299cca522db00bfaff839fdd319cedad5b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jul 2021 23:13:18 +0200 Subject: [PATCH 035/123] Bump memoryfilesystem from 2.1.0 to 2.2.0 (#2287) Bumps [memoryfilesystem](https://github.com/marschall/memoryfilesystem) from 2.1.0 to 2.2.0. - [Release notes](https://github.com/marschall/memoryfilesystem/releases) - [Commits](https://github.com/marschall/memoryfilesystem/compare/2.1.0...2.2.0) --- updated-dependencies: - dependency-name: com.github.marschall:memoryfilesystem dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0f8ee83d459..d2fedf9cded 100644 --- a/pom.xml +++ b/pom.xml @@ -144,7 +144,7 @@ com.github.marschall memoryfilesystem - 2.1.0 + 2.2.0 test From b3d504f8f37558fb19a73acc3f3f527c66efae7b Mon Sep 17 00:00:00 2001 From: Gily-H <67421795+Gily-H@users.noreply.github.com> Date: Mon, 12 Jul 2021 18:03:15 -0400 Subject: [PATCH 036/123] Add `hasSize` to `Path` assertions (#2243) --- .../assertj/core/api/AbstractPathAssert.java | 36 ++++++ .../assertj/core/error/ShouldHaveSize.java | 24 ++++ .../java/org/assertj/core/internal/Paths.java | 11 ++ .../api/path/PathAssert_hasSize_Test.java | 32 ++++++ .../error/ShouldHaveSize_create_Test.java | 45 ++++++-- .../paths/Paths_assertHasSize_Test.java | 107 ++++++++++++++++++ 6 files changed, 244 insertions(+), 11 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/path/PathAssert_hasSize_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index 5764449a716..16c017eef47 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -1110,6 +1110,42 @@ public SELF hasNoParentRaw() { return myself; } + /** + * Assert that the tested {@link Path} has the given size in bytes. + *

+ * Note that the actual {@link Path} must exist and be a regular file. + *

+ * + * Examples: + *
 // Given the following empty paths
+   * /root/sub-dir-1/foo.ext
+   * /root/sub-dir-1/bar.ext
+   *
+   * Path emptyPath = Paths.get("/root/sub-dir-1/foo.ext")
+   * Path nonEmptyPath = Files.write(Paths.get("/root/sub-dir-1/bar.ext"),
+   *                                 "The Quick Brown Fox.".getBytes());
+   * // the following assertions pass
+   * assertThat(emptyPath).hasSize(0);
+   * assertThat(nonEmptyPath).hasSize(20);
+   *
+   * // the following assertions fail
+   * assertThat(emptyPath).hasSize(5);
+   * assertThat(nonEmptyPath).hasSize(0);
+ * + * @param expectedSize the expected {@code Path} file size in bytes + * @return {@code this} assertion object + * @throws AssertionError is the actual {@code Path} is {@code null}. + * @throws AssertionError if the actual {@code Path} does not exist. + * @throws AssertionError if the actual {@code Path} is not a regular file. + * @throws AssertionError if the actual {@code Path} file size is not equal to the expected size. + * @throws UncheckedIOException if any I/O error occurs. + * @since 3.21.0 + */ + public SELF hasSize(long expectedSize) { + paths.assertHasSize(info, actual, expectedSize); + return myself; + } + /** * Assert that the tested {@link Path} starts with the given path. * diff --git a/src/main/java/org/assertj/core/error/ShouldHaveSize.java b/src/main/java/org/assertj/core/error/ShouldHaveSize.java index 2da8c29427d..492b0a3910e 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveSize.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveSize.java @@ -15,6 +15,9 @@ import static java.lang.String.format; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; /** * Creates an error message indicating that an assertion that verifies that a value have certain size failed. @@ -30,6 +33,13 @@ public class ShouldHaveSize extends BasicErrorMessageFactory { + "but had:%n" + " %s bytes"; + private static final String SHOULD_HAVE_PATH_SIZE = "%nExpecting path%n" + + " %s%n" + + "to have a size of:%n" + + " %s bytes%n" + + "but had:%n" + + " %s bytes"; + /** * Creates a new {@link ShouldHaveSize}. * @param actual the actual value in the failed assertion. @@ -82,4 +92,18 @@ private ShouldHaveSize(File actual, long expectedSize) { super(SHOULD_HAVE_FILE_SIZE, actual, expectedSize, actual.length()); } + /** + * Creates a new {@link ShouldHaveSize} for Path file size + * @param actual The actual path file in the failed assertion + * @param expectedSize The expected size of the path file + * @return the created {@code ErrorMessageFactory} + */ + public static ErrorMessageFactory shouldHaveSize(Path actual, long expectedSize) throws IOException { + return new ShouldHaveSize(actual, expectedSize); + } + + private ShouldHaveSize(Path actual, long expectedSize) throws IOException { + super(SHOULD_HAVE_PATH_SIZE, actual, expectedSize, Files.size(actual)); + } + } diff --git a/src/main/java/org/assertj/core/internal/Paths.java b/src/main/java/org/assertj/core/internal/Paths.java index a82a38d2876..0dbd7e89d1c 100644 --- a/src/main/java/org/assertj/core/internal/Paths.java +++ b/src/main/java/org/assertj/core/internal/Paths.java @@ -42,6 +42,7 @@ import static org.assertj.core.error.ShouldHaveNoParent.shouldHaveNoParent; import static org.assertj.core.error.ShouldHaveParent.shouldHaveParent; import static org.assertj.core.error.ShouldHaveSameContent.shouldHaveSameContent; +import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; import static org.assertj.core.error.ShouldNotExist.shouldNotExist; @@ -228,6 +229,16 @@ public void assertHasNoParentRaw(final AssertionInfo info, final Path actual) { if (actual.getParent() != null) throw failures.failure(info, shouldHaveNoParent(actual)); } + public void assertHasSize(final AssertionInfo info, final Path actual, long expectedSize) { + assertIsRegularFile(info, actual); + try { + long actualSize = nioFilesWrapper.size(actual); + if (actualSize != expectedSize) throw failures.failure(info, shouldHaveSize(actual, expectedSize)); + } catch(IOException e) { + throw new UncheckedIOException(format("unable to verify the size of the path: <%s>", actual), e); + } + } + public void assertStartsWith(final AssertionInfo info, final Path actual, final Path start) { assertNotNull(info, actual); assertExpectedStartPathIsNotNull(start); diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_hasSize_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_hasSize_Test.java new file mode 100644 index 00000000000..289722f06de --- /dev/null +++ b/src/test/java/org/assertj/core/api/path/PathAssert_hasSize_Test.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.path; + +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.PathAssert; +import org.assertj.core.api.PathAssertBaseTest; + +class PathAssert_hasSize_Test extends PathAssertBaseTest { + + @Override + protected PathAssert invoke_api_method() { + return assertions.hasSize(0L); + } + + @Override + protected void verify_internal_effects() { + verify(paths).assertHasSize(getInfo(assertions), getActual(assertions), 0L); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldHaveSize_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveSize_create_Test.java index ad3ca410aae..f22c251005a 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveSize_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveSize_create_Test.java @@ -18,42 +18,47 @@ import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; import static org.assertj.core.util.Lists.list; -import org.assertj.core.description.TextDescription; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.assertj.core.description.Description; +import org.assertj.core.internal.TestDescription; import org.assertj.core.presentation.HexadecimalRepresentation; +import org.assertj.core.presentation.Representation; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** - * Tests for {@link ShouldHaveSize#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)}. + * Tests for {@link ShouldHaveSize#create(Description, Representation)}. * * @author Alex Ruiz * @author Yvonne Wang */ -@DisplayName("ShouldHaveSize create:") class ShouldHaveSize_create_Test { private ErrorMessageFactory factory; @BeforeEach - public void setUp() { + void setUp() { factory = shouldHaveSize(list('a', 'b'), 4, 2); } @Test void should_create_error_message() { // WHEN - String message = factory.create(new TextDescription("Test"), STANDARD_REPRESENTATION); + String message = factory.create(new TestDescription("TEST"), STANDARD_REPRESENTATION); // THEN - then(message).isEqualTo(String.format("[Test] %nExpected size: 2 but was: 4 in:%n['a', 'b']")); + then(message).isEqualTo(String.format("[TEST] %nExpected size: 2 but was: 4 in:%n['a', 'b']")); } @Test void should_create_error_message_with_hexadecimal_representation() { // WHEN - String message = factory.create(new TextDescription("Test"), new HexadecimalRepresentation()); + String message = factory.create(new TestDescription("TEST"), new HexadecimalRepresentation()); // THEN - then(message).isEqualTo(String.format("[Test] %nExpected size: 2 but was: 4 in:%n['0x0061', '0x0062']")); + then(message).isEqualTo(String.format("[TEST] %nExpected size: 2 but was: 4 in:%n['0x0061', '0x0062']")); } @Test @@ -61,9 +66,9 @@ void should_create_error_message_for_incorrect_file_size() { // GIVEN ErrorMessageFactory factory = shouldHaveSize(new FakeFile("ab%sc"), 3L); // WHEN - String actualErrorMessage = factory.create(new TextDescription("Test"), STANDARD_REPRESENTATION); + String actualErrorMessage = factory.create(new TestDescription("TEST"), STANDARD_REPRESENTATION); // THEN - then(actualErrorMessage).isEqualTo(format("[Test] %n" + then(actualErrorMessage).isEqualTo(format("[TEST] %n" + "Expecting file%n" + " ab%%sc%n" + "to have a size of:%n" @@ -71,4 +76,22 @@ void should_create_error_message_for_incorrect_file_size() { + "but had:%n" + " 0L bytes")); } + + @Test + void should_create_error_message_for_incorrect_path_size(@TempDir Path tempDir) throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "content".getBytes()); + // WHEN + String actualErrorMessage = shouldHaveSize(actual, 0L).create(new TestDescription("TEST"), STANDARD_REPRESENTATION); + // THEN + then(actualErrorMessage).isEqualTo("[TEST] %n" + + "Expecting path%n" + + " %s%n" + + "to have a size of:%n" + + " 0L bytes%n" + + "but had:%n" + + " 7L bytes", + actual); + } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java new file mode 100644 index 00000000000..ebe28763cf5 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java @@ -0,0 +1,107 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +class Paths_assertHasSize_Test extends PathsBaseTest { + + @TempDir + Path tempDir; + + @BeforeEach + void setUpNioFilesWrapper() throws IOException { + given(nioFilesWrapper.exists(any())).willCallRealMethod(); + given(nioFilesWrapper.isRegularFile(any())).willCallRealMethod(); + given(nioFilesWrapper.size(any())).willCallRealMethod(); + } + + @Test + void should_fail_if_actual_is_null() { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSize(info, null, 0L)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSize(info, actual, 0L)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_regular_file() throws IOException { + // GIVEN + Path actual = Files.createDirectory(tempDir.resolve("directory")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSize(info, actual, 0L)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { + // GIVEN + Path actual = Files.createFile(tempDir.resolve("actual")); + IOException exception = new IOException("boom!"); + given(nioFilesWrapper.size(actual)).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasSize(info, actual, 0L)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasMessage("unable to verify the size of the path: <%s>", actual) + .hasCause(exception); + } + + @Test + void should_pass_if_actual_size_is_equal_to_expected_size() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "content".getBytes()); + // WHEN/THEN + paths.assertHasSize(info, actual, 7L); + } + + @Test + void should_fail_if_actual_size_is_not_equal_to_expected_size() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "content".getBytes()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSize(info, actual, 6L)); + // THEN + then(error).hasMessage(shouldHaveSize(actual, 6L).create()); + } + +} From 5547dbeaf3837310009d10630b6390f968a747e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Jul 2021 00:53:01 +0200 Subject: [PATCH 037/123] Bump commons-io from 2.10.0 to 2.11.0 (#2289) Bumps commons-io from 2.10.0 to 2.11.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d2fedf9cded..7d9d7ce6ab3 100644 --- a/pom.xml +++ b/pom.xml @@ -168,7 +168,7 @@ commons-io commons-io - 2.10.0 + 2.11.0 test From eca366febcaa88e557b1d0b0acbf7b59fbd2b65a Mon Sep 17 00:00:00 2001 From: Stefan Bischof Date: Tue, 13 Jul 2021 14:30:45 +0200 Subject: [PATCH 038/123] [MappedCondition] fix handling of mappings to null Signed-off-by: Stefan Bischof --- .../assertj/core/condition/MappedCondition.java | 13 +++++++++++-- .../core/condition/MappedConditionTest.java | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/assertj/core/condition/MappedCondition.java b/src/main/java/org/assertj/core/condition/MappedCondition.java index 597526f69c3..19eb7fe01a2 100644 --- a/src/main/java/org/assertj/core/condition/MappedCondition.java +++ b/src/main/java/org/assertj/core/condition/MappedCondition.java @@ -133,11 +133,20 @@ public boolean matches(FROM value) { protected String buildMappingDescription(FROM from, TO to) { StringBuilder sb = new StringBuilder("mapped"); if (!mappingDescription.isEmpty()) sb.append(format("%n using: %s", mappingDescription)); - sb.append(format("%n from: <%s> %s%n", from.getClass().getSimpleName(), from)); - sb.append(format(" to: <%s> %s%n", to.getClass().getSimpleName(), from, to)); + + if (from == null) sb.append(format("%n from: %s%n", from)); + else sb.append(format("%n from: <%s> %s%n", className(from), from)); + + if (to == null) sb.append(format(" to: %s%n", to)); + else sb.append(format(" to: <%s> %s%n", className(to), to)); + sb.append(" then checked:"); sb.append(format("%n %-10s", condition)); return sb.toString(); } + private static String className(Object object) { + return object.getClass().getSimpleName(); + } + } diff --git a/src/test/java/org/assertj/core/condition/MappedConditionTest.java b/src/test/java/org/assertj/core/condition/MappedConditionTest.java index 533b27d9157..d6595698a71 100644 --- a/src/test/java/org/assertj/core/condition/MappedConditionTest.java +++ b/src/test/java/org/assertj/core/condition/MappedConditionTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.condition.MappedCondition.mappedCondition; import java.util.Optional; +import java.util.function.Function; import org.assertj.core.api.Condition; import org.junit.jupiter.api.Test; @@ -112,6 +113,22 @@ void mappedCondition_with_null_description_and_should_throw_NPE() { .withMessage("The given mappingDescription should not be null"); } + @Test + void mappedCondition_should_handle_null_values_in_description() { + // GIVEN + Condition isNull = new Condition<>(o -> o == null, "is null"); + MappedCondition mapped = mappedCondition(Function.identity(), isNull, "identity"); + // WHEN + mapped.matches(null); + // THEN + then(mapped).hasToString(format("mapped%n" + + " using: identity%n" + + " from: null%n" + + " to: null%n" + + " then checked:%n" + + " is null ")); + } + @Test void example() { // GIVEN From 32fb3395831913eb3b45563324a380dc59217816 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jul 2021 07:09:02 +0200 Subject: [PATCH 039/123] Bump byte-buddy.version from 1.11.6 to 1.11.7 (#2290) Bumps `byte-buddy.version` from 1.11.6 to 1.11.7. Updates `byte-buddy` from 1.11.6 to 1.11.7 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.6...byte-buddy-1.11.7) Updates `byte-buddy-agent` from 1.11.6 to 1.11.7 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.6...byte-buddy-1.11.7) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7d9d7ce6ab3..6eb01ec5bd6 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.6 + 1.11.7 2.2 1.2.0 5.3.0 From 5fdeb979087f717112e46886c9fae83bda06b4f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jul 2021 07:09:39 +0200 Subject: [PATCH 040/123] Bump spring-core from 5.3.8 to 5.3.9 (#2291) Bumps [spring-core](https://github.com/spring-projects/spring-framework) from 5.3.8 to 5.3.9. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v5.3.8...v5.3.9) --- updated-dependencies: - dependency-name: org.springframework:spring-core dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6eb01ec5bd6..60a84936622 100644 --- a/pom.xml +++ b/pom.xml @@ -186,7 +186,7 @@ org.springframework spring-core - 5.3.8 + 5.3.9 test From 4d8a1c06e227b2f7cf0ea8c297b6dd4213dfeafb Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Thu, 15 Jul 2021 09:39:16 +0200 Subject: [PATCH 041/123] Deprecate `MockPathsBaseTest` in favor of `PathsBaseTest` and `@TempDir` --- .../org/assertj/core/internal/paths/MockPathsBaseTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java b/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java index 11d4b5e59da..d61e50abb94 100644 --- a/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java +++ b/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java @@ -39,7 +39,12 @@ import org.junit.jupiter.api.BeforeEach; import com.google.common.collect.Iterators; +import org.junit.jupiter.api.io.TempDir; +/** + * @deprecated favor tests based on {@link PathsBaseTest} and JUnit 5 {@link TempDir}. + */ +@Deprecated public class MockPathsBaseTest extends PathsBaseTest { static final AssertionInfo INFO = someInfo(); From 4191fbf0eb7c9cfc78439f007fc9f1644c7c11bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jul 2021 23:25:22 +0200 Subject: [PATCH 042/123] Bump byte-buddy.version from 1.11.7 to 1.11.8 (#2293) Bumps `byte-buddy.version` from 1.11.7 to 1.11.8. Updates `byte-buddy` from 1.11.7 to 1.11.8 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.7...byte-buddy-1.11.8) Updates `byte-buddy-agent` from 1.11.7 to 1.11.8 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.7...byte-buddy-1.11.8) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 60a84936622..1e125560784 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.7 + 1.11.8 2.2 1.2.0 5.3.0 From 7fe81ea67c6b07d139cf1bff6a37b03c57823423 Mon Sep 17 00:00:00 2001 From: Stefan Bischof Date: Wed, 14 Jul 2021 14:45:18 +0200 Subject: [PATCH 043/123] [MappedCondition] generate proper conditionDescriptionWithStatus Signed-off-by: Stefan Bischof --- .../core/condition/MappedCondition.java | 25 +++++++++++++++--- .../core/condition/MappedConditionTest.java | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/assertj/core/condition/MappedCondition.java b/src/main/java/org/assertj/core/condition/MappedCondition.java index 19eb7fe01a2..179f87f0d94 100644 --- a/src/main/java/org/assertj/core/condition/MappedCondition.java +++ b/src/main/java/org/assertj/core/condition/MappedCondition.java @@ -14,11 +14,14 @@ import static java.lang.String.format; import static java.util.Objects.requireNonNull; +import static org.assertj.core.util.Lists.list; import java.util.function.Function; import org.assertj.core.annotations.Beta; import org.assertj.core.api.Condition; +import org.assertj.core.description.Description; +import org.assertj.core.description.JoinDescription; /** * Container {@link Condition} that maps the object under test and then check the resulting mapped value against its nested {@link Condition}. @@ -131,20 +134,34 @@ public boolean matches(FROM value) { * @return the mapped condition description . */ protected String buildMappingDescription(FROM from, TO to) { + return buildMappingDescription(from, to, true); + } + + private String buildMappingDescription(FROM from, TO to, boolean withNested) { + StringBuilder sb = new StringBuilder("mapped"); if (!mappingDescription.isEmpty()) sb.append(format("%n using: %s", mappingDescription)); - + if (from == null) sb.append(format("%n from: %s%n", from)); else sb.append(format("%n from: <%s> %s%n", className(from), from)); - + if (to == null) sb.append(format(" to: %s%n", to)); else sb.append(format(" to: <%s> %s%n", className(to), to)); - + sb.append(" then checked:"); - sb.append(format("%n %-10s", condition)); + if (withNested) sb.append(format("%n %-10s", condition)); return sb.toString(); } + @Override + public Description conditionDescriptionWithStatus(FROM actual) { + TO mappedObject = mapping.apply(actual); + Description descriptionsWithStatus = condition.conditionDescriptionWithStatus(mappedObject); + Status status = status(actual); + String descriptionStart = format("%s %s", status, buildMappingDescription(actual, mappedObject, false)); + return new JoinDescription(descriptionStart, "", list(descriptionsWithStatus)); + } + private static String className(Object object) { return object.getClass().getSimpleName(); } diff --git a/src/test/java/org/assertj/core/condition/MappedConditionTest.java b/src/test/java/org/assertj/core/condition/MappedConditionTest.java index d6595698a71..91ec72170cb 100644 --- a/src/test/java/org/assertj/core/condition/MappedConditionTest.java +++ b/src/test/java/org/assertj/core/condition/MappedConditionTest.java @@ -16,12 +16,14 @@ import static java.lang.System.lineSeparator; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.BDDAssertions.thenNullPointerException; +import static org.assertj.core.condition.AllOf.allOf; import static org.assertj.core.condition.MappedCondition.mappedCondition; import java.util.Optional; import java.util.function.Function; import org.assertj.core.api.Condition; +import org.assertj.core.description.Description; import org.junit.jupiter.api.Test; class MappedConditionTest { @@ -54,6 +56,16 @@ class MappedConditionTest { " then checked:%n" + " " + INNER_CONDITION_DESCRIPTION); + private final static String FOO_CONDITION_DESCRIPTION_STATUS = format("[✗] mapped%n" + + " using: ::toString%n" + + " from: a -%n" + + " to: a -%n" + + " then checked:%n" + + " [✗] all of:[%n" + + " [✓] has -,%n" + + " [✗] is longer than 4%n" + + " ]%n"); + @Test void mappedCondition_withDescription_works() { // WHEN @@ -140,4 +152,18 @@ void example() { // THEN then(matches).isTrue(); } + + @Test + void mappedCondition_conditionDescriptionWithStatus_works() { + // GIVEN + Condition hasDash = new Condition<>(text -> text.contains("-"), "has -"); + Condition isLonger = new Condition<>(text -> text.length() > 4, "is longer than 4"); + Condition mappedCondition = mappedCondition(StringBuilder::toString, allOf(hasDash, isLonger), "::toString"); + StringBuilder theString = new StringBuilder("a -"); + // WHEN + mappedCondition.matches(theString); + Description conditionDescriptionWithStatus = mappedCondition.conditionDescriptionWithStatus(theString); + // THEN + then(conditionDescriptionWithStatus.value()).isEqualTo(FOO_CONDITION_DESCRIPTION_STATUS); + } } From 75a4160814d915b941c49fe8c499709b1893ce9b Mon Sep 17 00:00:00 2001 From: Stefan Bischof Date: Fri, 9 Jul 2021 23:57:15 +0200 Subject: [PATCH 044/123] use conditionDescriptionWithStatus on Join at the moment it is only on AllOf but not AnyOf Signed-off-by: Stefan Bischof --- .../java/org/assertj/core/error/ShouldBe.java | 8 ++--- .../org/assertj/core/error/ShouldHave.java | 8 ++--- .../Multiple_combined_conditions_Test.java | 34 ++++++++++--------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/assertj/core/error/ShouldBe.java b/src/main/java/org/assertj/core/error/ShouldBe.java index 98c8dec4d7a..46066fef642 100644 --- a/src/main/java/org/assertj/core/error/ShouldBe.java +++ b/src/main/java/org/assertj/core/error/ShouldBe.java @@ -13,7 +13,7 @@ package org.assertj.core.error; import org.assertj.core.api.Condition; -import org.assertj.core.condition.AllOf; +import org.assertj.core.condition.Join; /** * Creates an error message indicating that an assertion that verifies that a value satisfies a {@link Condition} @@ -32,7 +32,7 @@ public class ShouldBe extends BasicErrorMessageFactory { * @return the created {@code ErrorMessageFactory}. */ public static ErrorMessageFactory shouldBe(T actual, Condition condition) { - if (condition instanceof AllOf) return new ShouldBe(actual, (AllOf) condition); + if (condition instanceof Join) return new ShouldBe(actual, (Join) condition); return new ShouldBe(actual, condition); } @@ -40,12 +40,12 @@ private ShouldBe(Object actual, Condition condition) { super("%nExpecting actual:%n %s%nto be %s", actual, condition); } - private ShouldBe(T actual, AllOf allOf) { + private ShouldBe(T actual, Join join) { super("%n" + "Expecting actual:%n" + " %s%n" + // use concatenation to avoid the string to be double quoted later on - "to be:%n" + allOf.conditionDescriptionWithStatus(actual), + "to be:%n" + join.conditionDescriptionWithStatus(actual), actual); } diff --git a/src/main/java/org/assertj/core/error/ShouldHave.java b/src/main/java/org/assertj/core/error/ShouldHave.java index 64a26243d6c..e9ab4a1d4b0 100644 --- a/src/main/java/org/assertj/core/error/ShouldHave.java +++ b/src/main/java/org/assertj/core/error/ShouldHave.java @@ -13,7 +13,7 @@ package org.assertj.core.error; import org.assertj.core.api.Condition; -import org.assertj.core.condition.AllOf; +import org.assertj.core.condition.Join; /** * Creates an error message indicating that an assertion that verifies that a value satisfies a {@link Condition} @@ -32,7 +32,7 @@ public class ShouldHave extends BasicErrorMessageFactory { * @return the created {@code ErrorMessageFactory}. */ public static ErrorMessageFactory shouldHave(T actual, Condition condition) { - if (condition instanceof AllOf) return new ShouldHave(actual, (AllOf) condition); + if (condition instanceof Join) return new ShouldHave(actual, (Join) condition); return new ShouldHave(actual, condition); } @@ -40,12 +40,12 @@ private ShouldHave(Object actual, Condition condition) { super("%nExpecting actual:%n %s%nto have %s", actual, condition); } - private ShouldHave(T actual, AllOf allOf) { + private ShouldHave(T actual, Join join) { super("%n" + "Expecting actual:%n" + " %s%n" + // use concatenation to avoid the string to be double quoted later on - "to have:%n" + allOf.conditionDescriptionWithStatus(actual), + "to have:%n" + join.conditionDescriptionWithStatus(actual), actual); } } diff --git a/src/test/java/org/assertj/core/condition/Multiple_combined_conditions_Test.java b/src/test/java/org/assertj/core/condition/Multiple_combined_conditions_Test.java index fc6700d3017..e89fb849fce 100644 --- a/src/test/java/org/assertj/core/condition/Multiple_combined_conditions_Test.java +++ b/src/test/java/org/assertj/core/condition/Multiple_combined_conditions_Test.java @@ -59,14 +59,15 @@ void should_report_error_message_with_all_conditions_described() { then(assertionError).hasMessage(format("%n" + "Expecting actual:%n" + " \"Gandalf\"%n" + - "to have any of:[%n" + - " contains i,%n" + - " all of:[%n" + - " contains o,%n" + - " any of:[%n" + - " contains a,%n" + - " contains b,%n" + - " contains c%n" + + "to have:%n" + + "[✗] any of:[%n" + + " [✗] contains i,%n" + + " [✗] all of:[%n" + + " [✗] contains o,%n" + + " [✓] any of:[%n" + + " [✓] contains a,%n" + + " [✗] contains b,%n" + + " [✗] contains c%n" + " ]%n" + " ]%n" + "]")); @@ -86,14 +87,15 @@ void should_report_error_message_with_all_conditions_in_list_described() { then(assertionError).hasMessage(format("%n" + "Expecting actual:%n" + " \"Gandalf\"%n" + - "to have any of:[%n" + - " contains i,%n" + - " all of:[%n" + - " contains o,%n" + - " any of:[%n" + - " contains a,%n" + - " contains b,%n" + - " contains c%n" + + "to have:%n" + + "[✗] any of:[%n" + + " [✗] contains i,%n" + + " [✗] all of:[%n" + + " [✗] contains o,%n" + + " [✓] any of:[%n" + + " [✓] contains a,%n" + + " [✗] contains b,%n" + + " [✗] contains c%n" + " ]%n" + " ]%n" + "]")); From 5acf3e5651358935c56bbea6a7a51e95bd2e74fd Mon Sep 17 00:00:00 2001 From: RGalways17 <1123687858@qq.com> Date: Tue, 18 May 2021 22:20:50 +0800 Subject: [PATCH 045/123] Add stack trace information of Throwable that fails hasCauseInstanceOf or hasCauseExactlyInstanceOf Fixes #2209 --- .../error/ShouldHaveCauseExactlyInstance.java | 22 ++++++++++----- .../core/error/ShouldHaveCauseInstance.java | 25 ++++++++++++----- ...dHaveCauseExactlyInstance_create_Test.java | 27 +++++++++++++++--- .../ShouldHaveCauseInstance_create_Test.java | 28 ++++++++++++++++--- 4 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance.java b/src/main/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance.java index 134d7cc4265..0bb388ab45b 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance.java @@ -12,6 +12,9 @@ */ package org.assertj.core.error; +import static org.assertj.core.util.Strings.escapePercent; +import static org.assertj.core.util.Throwables.getStackTrace; + /** * Creates an error message indicating that an assertion that verifies that a {@link Throwable} have a cause * exactly instance of a certain type. @@ -28,19 +31,24 @@ public class ShouldHaveCauseExactlyInstance extends BasicErrorMessageFactory { * @return the created {@code ErrorMessageFactory}. */ public static ErrorMessageFactory shouldHaveCauseExactlyInstance(Throwable actual, - Class expectedCauseType) { - return actual.getCause() == null ? new ShouldHaveCauseExactlyInstance(expectedCauseType) + Class expectedCauseType) { + return actual.getCause() == null + ? new ShouldHaveCauseExactlyInstance(expectedCauseType) : new ShouldHaveCauseExactlyInstance(actual, expectedCauseType); } private ShouldHaveCauseExactlyInstance(Throwable actual, Class expectedCauseType) { - super("%nExpecting a throwable with cause being exactly an instance of:%n %s%nbut was an instance of:%n %s", - expectedCauseType, actual.getCause()); + super("%nExpecting a throwable with cause being exactly an instance of:%n" + + " %s%n" + + "but was an instance of:%n" + + " %s%n" + + "Throwable that failed the check:%n" + + "%n" + escapePercent(getStackTrace(actual)), + expectedCauseType, actual.getCause().getClass()); } private ShouldHaveCauseExactlyInstance(Class expectedCauseType) { - super( - "%nExpecting a throwable with cause being exactly an instance of:%n %s%nbut current throwable has no cause.", - expectedCauseType); + super("%nExpecting a throwable with cause being exactly an instance of:%n %s%nbut current throwable has no cause.", + expectedCauseType); } } diff --git a/src/main/java/org/assertj/core/error/ShouldHaveCauseInstance.java b/src/main/java/org/assertj/core/error/ShouldHaveCauseInstance.java index 7786b57519c..92ec77bb3b7 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveCauseInstance.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveCauseInstance.java @@ -12,6 +12,9 @@ */ package org.assertj.core.error; +import static org.assertj.core.util.Strings.escapePercent; +import static org.assertj.core.util.Throwables.getStackTrace; + /** * Creates an error message indicating that an assertion that verifies that a {@link Throwable} have a cause instance of * a certain type. @@ -28,18 +31,26 @@ public class ShouldHaveCauseInstance extends BasicErrorMessageFactory { * @return the created {@code ErrorMessageFactory}. */ public static ErrorMessageFactory shouldHaveCauseInstance(Throwable actual, - Class expectedCauseType) { - return actual.getCause() == null ? new ShouldHaveCauseInstance(expectedCauseType) : new ShouldHaveCauseInstance( - actual, expectedCauseType); + Class expectedCauseType) { + return actual.getCause() == null + ? new ShouldHaveCauseInstance(expectedCauseType) + : new ShouldHaveCauseInstance(actual, expectedCauseType); } private ShouldHaveCauseInstance(Throwable actual, Class expectedCauseType) { - super("%nExpecting a throwable with cause being an instance of:%n %s%nbut was an instance of:%n %s", - expectedCauseType, actual.getCause()); + super("%nExpecting a throwable with cause being an instance of:%n" + + " %s%n" + + "but was an instance of:%n" + + " %s%n" + + "Throwable that failed the check:%n" + + "%n" + escapePercent(getStackTrace(actual)), + expectedCauseType, actual.getCause().getClass()); } private ShouldHaveCauseInstance(Class expectedCauseType) { - super("%nExpecting a throwable with cause being an instance of:%n %s%nbut current throwable has no cause.", - expectedCauseType); + super("%nExpecting a throwable with cause being an instance of:%n" + + " %s%n" + + "but current throwable has no cause.", + expectedCauseType); } } diff --git a/src/test/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance_create_Test.java index f3f1cf67b45..bffe14a08c7 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveCauseExactlyInstance_create_Test.java @@ -12,11 +12,12 @@ */ package org.assertj.core.error; -import org.junit.jupiter.api.Test; - import static java.lang.String.format; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveCauseExactlyInstance.shouldHaveCauseExactlyInstance; +import static org.assertj.core.util.Throwables.getStackTrace; + +import org.junit.jupiter.api.Test; class ShouldHaveCauseExactlyInstance_create_Test { @@ -28,8 +29,26 @@ void should_create_error_message_for_no_cause() { // WHEN String message = shouldHaveCauseExactlyInstance(actual, expected.getClass()).create(); // THEN + then(message).isEqualTo("%nExpecting a throwable with cause being exactly an instance of:%n" + + " %s%n" + + "but current throwable has no cause.", expected); + } + + @Test + void should_create_error_message_for_wrong_cause() { + // GIVEN + Throwable expected = new IllegalStateException(); + Throwable cause = new IllegalArgumentException("oops...% %s %n"); + Throwable actual = new RuntimeException(cause); + // WHEN + String message = shouldHaveCauseExactlyInstance(actual, expected.getClass()).create(); + // THEN then(message).isEqualTo(format("%nExpecting a throwable with cause being exactly an instance of:%n" + - " %s%n" + - "but current throwable has no cause.", expected)); + " java.lang.IllegalStateException%n" + + "but was an instance of:%n" + + " java.lang.IllegalArgumentException%n" + + "Throwable that failed the check:%n" + + "%n" + + "%s", getStackTrace(actual))); } } diff --git a/src/test/java/org/assertj/core/error/ShouldHaveCauseInstance_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveCauseInstance_create_Test.java index abcfbbf819a..a4aa3b0d27a 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveCauseInstance_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveCauseInstance_create_Test.java @@ -12,11 +12,12 @@ */ package org.assertj.core.error; -import org.junit.jupiter.api.Test; - import static java.lang.String.format; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveCauseInstance.shouldHaveCauseInstance; +import static org.assertj.core.util.Throwables.getStackTrace; + +import org.junit.jupiter.api.Test; class ShouldHaveCauseInstance_create_Test { @@ -28,8 +29,27 @@ void should_create_error_message_for_no_cause() { // WHEN String message = shouldHaveCauseInstance(actual, expected.getClass()).create(); // THEN + then(message).isEqualTo("%nExpecting a throwable with cause being an instance of:%n" + + " %s%n" + + "but current throwable has no cause.", expected); + } + + @Test + void should_create_error_message_for_wrong_cause() { + // GIVEN + Throwable expected = new IllegalStateException(); + Throwable cause = new IllegalAccessError("oops...% %s %n"); + Throwable actual = new RuntimeException(cause); + // WHEN + String message = shouldHaveCauseInstance(actual, expected.getClass()).create(); + // THEN then(message).isEqualTo(format("%nExpecting a throwable with cause being an instance of:%n" + - " %s%n" + - "but current throwable has no cause.", expected)); + " java.lang.IllegalStateException%n" + + "but was an instance of:%n" + + " java.lang.IllegalAccessError%n" + + "Throwable that failed the check:%n" + + "%n" + + "%s", getStackTrace(actual))); + } } From e13c5fbb31501d984148ebdb2ca47b2873c215f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Jul 2021 23:55:13 +0200 Subject: [PATCH 046/123] Bump pitest-maven from 1.6.7 to 1.6.8 (#2298) Bumps [pitest-maven](https://github.com/hcoles/pitest) from 1.6.7 to 1.6.8. - [Release notes](https://github.com/hcoles/pitest/releases) - [Commits](https://github.com/hcoles/pitest/compare/1.6.7...pitest-parent-1.6.8) --- updated-dependencies: - dependency-name: org.pitest:pitest-maven dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e125560784..06b0fe5b5fd 100644 --- a/pom.xml +++ b/pom.xml @@ -613,7 +613,7 @@ org.pitest pitest-maven - 1.6.7 + 1.6.8 org.pitest From fe1c4630da8a38e378a6baa703191d9860e3df2d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Jul 2021 01:46:04 +0200 Subject: [PATCH 047/123] Bump byte-buddy.version from 1.11.8 to 1.11.9 (#2299) Bumps `byte-buddy.version` from 1.11.8 to 1.11.9. Updates `byte-buddy` from 1.11.8 to 1.11.9 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.8...byte-buddy-1.11.9) Updates `byte-buddy-agent` from 1.11.8 to 1.11.9 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.8...byte-buddy-1.11.9) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 06b0fe5b5fd..0e5a484073d 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.8 + 1.11.9 2.2 1.2.0 5.3.0 From 480a4a43e6b87597aa20f4845b8bedc3729f0b60 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Fri, 30 Jul 2021 23:04:30 +1200 Subject: [PATCH 048/123] Add satisfies with ThrowingConsumer that allow consumers to throw checked exception (#2297) --- .../org/assertj/core/api/AbstractAssert.java | 31 +++++ .../assertj/core/api/ThrowingConsumer.java | 39 ++++++ .../api/ThrowingConsumer_accept_Test.java | 53 ++++++++ ...ctAssert_satisfies_with_Consumer_Test.java | 10 +- ..._satisfies_with_ThrowingConsumer_Test.java | 115 ++++++++++++++++++ src/test/resources/empty.txt | 0 6 files changed, 244 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/assertj/core/api/ThrowingConsumer.java create mode 100644 src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java create mode 100644 src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java create mode 100644 src/test/resources/empty.txt diff --git a/src/main/java/org/assertj/core/api/AbstractAssert.java b/src/main/java/org/assertj/core/api/AbstractAssert.java index dfa42db1708..c04bc4622ba 100644 --- a/src/main/java/org/assertj/core/api/AbstractAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractAssert.java @@ -817,6 +817,37 @@ public SELF matches(Predicate predicate, String predicateDescrip * @throws NullPointerException if given Consumer is null */ public SELF satisfies(Consumer requirements) { + return internalSatisfies(requirements); + } + + /** + * Verifies that the actual object satisfied the given requirements expressed as a {@link ThrowingConsumer}. + *

+ * This is the same assertion as {@link #satisfies(java.util.function.Consumer)} except that a {@link ThrowingConsumer} rethrows checked exceptions as {@link RuntimeException}. + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are while any other {@link Throwable} are rethrown as {@link RuntimeException}. + *

+ * Example: + *

 // read() throws IOException
+   * ThrowingConsumer<Reader> hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1);
+   *
+   * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as Consumer<Reader> the following line would not compile): 
+   * assertThat(new FileReader("empty.txt")).satisfies(hasReachedEOF);
+   *
+   * // assertion fails as the file is not empty:
+   * assertThat(new FileReader("nonEmpty.txt")).satisfies(hasReachedEOF);
+ * + * @param throwingConsumer requirements to assert on the actual object - must not be null.. + * @return this assertion object. + * + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError rethrown as is by given {@link ThrowingConsumer} + */ + public SELF satisfies(ThrowingConsumer throwingConsumer) { + return internalSatisfies(throwingConsumer); + } + + private SELF internalSatisfies(Consumer requirements) { requireNonNull(requirements, "The Consumer expressing the assertions requirements must not be null"); requirements.accept(actual); return myself; diff --git a/src/main/java/org/assertj/core/api/ThrowingConsumer.java b/src/main/java/org/assertj/core/api/ThrowingConsumer.java new file mode 100644 index 00000000000..74c91943e93 --- /dev/null +++ b/src/main/java/org/assertj/core/api/ThrowingConsumer.java @@ -0,0 +1,39 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api; + +import java.util.function.Consumer; + +/** + * {@link Consumer} that deals with checked exceptions by rethrowing them as {@link RuntimeException}. + *

+ * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are while any other {@link Throwable} are rethrown as {@link RuntimeException}. + * + * @param consumed type + */ +@FunctionalInterface +public interface ThrowingConsumer extends Consumer { + + @Override + default void accept(final T input) { + try { + acceptThrows(input); + } catch (final RuntimeException | AssertionError e) { + throw e; + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + void acceptThrows(T input) throws Throwable; +} diff --git a/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java b/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java new file mode 100644 index 00000000000..e205907c713 --- /dev/null +++ b/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java @@ -0,0 +1,53 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api; + +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class ThrowingConsumer_accept_Test { + + @Test + void should_rethrow_checked_exception_as_runtime_exception() { + // GIVEN + IOException ioException = new IOException("boom!"); + ThrowingConsumer throwingConsumer = throwingConsumer(ioException); + // WHEN + Throwable throwable = catchThrowable(() -> throwingConsumer.accept(null)); + // THEN + then(throwable).isExactlyInstanceOf(RuntimeException.class) + .hasCause(ioException); + } + + @Test + void should_rethrow_runtime_exception_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + ThrowingConsumer throwingConsumer = throwingConsumer(runtimeException); + // WHEN + Throwable throwable = catchThrowable(() -> throwingConsumer.accept(null)); + // THEN + then(throwable).isSameAs(runtimeException); + } + + private static ThrowingConsumer throwingConsumer(Throwable throwable) { + return value -> { + throw throwable; + }; + } + +} diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java index c151f8616b1..58111e96a0a 100644 --- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java @@ -27,13 +27,11 @@ class AbstractAssert_satisfies_with_Consumer_Test { private Jedi yoda; - private Jedi luke; private Consumer jediRequirements; @BeforeEach void setup() { yoda = new Jedi("Yoda", "Green"); - luke = new Jedi("Luke Skywalker", "Green"); jediRequirements = jedi -> { assertThat(jedi.lightSaberColor).as("check light saber").isEqualTo("Green"); assertThat(jedi.getName()).as("check name").doesNotContain("Dark"); @@ -42,13 +40,15 @@ void setup() { @Test void should_satisfy_single_requirement() { - assertThat(yoda).satisfies(jedi -> assertThat(jedi.lightSaberColor).isEqualTo("Green")); + // GIVEN + Consumer jediRequirement = jedi -> assertThat(jedi.lightSaberColor).isEqualTo("Green"); + // WHEN/THEN + then(yoda).satisfies(jediRequirement); } @Test void should_satisfy_multiple_requirements() { assertThat(yoda).satisfies(jediRequirements); - assertThat(luke).satisfies(jediRequirements); } @Test @@ -63,7 +63,9 @@ void should_fail_according_to_requirements() { @Test void should_fail_if_consumer_is_null() { + // GIVEN Consumer nullRequirements = null; + // WHEN/THEN assertThatNullPointerException().isThrownBy(() -> assertThat(yoda).satisfies(nullRequirements)) .withMessage("The Consumer expressing the assertions requirements must not be null"); } diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..69920f32b7a --- /dev/null +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java @@ -0,0 +1,115 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.abstract_; + +import static java.nio.file.Files.isReadable; +import static java.nio.file.Files.readAllLines; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.api.BDDAssertions.thenNullPointerException; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class AbstractAssert_satisfies_with_ThrowingConsumer_Test { + + private ThrowingConsumer isEOF; + + @BeforeEach + void setup() { + isEOF = path -> { + assertThat(isReadable(path)).isTrue(); + // this would not compile if isEOF was declared as Consumer since it can throw an IOException + assertThat(readAllLines(path)).isEmpty(); + }; + } + + @Test + void should_satisfy_single_requirement() { + // GIVEN + Path emptyFile = Paths.get("src/test/resources/empty.txt"); + ThrowingConsumer isEmpty = path -> assertThat(readAllLines(path)).isEmpty(); + // WHEN/THEN + then(emptyFile).satisfies(isEmpty); + } + + @Test + void should_satisfy_multiple_requirements() { + // GIVEN + Path emptyFile = Paths.get("src/test/resources/empty.txt"); + // WHEN/THEN + then(emptyFile).satisfies(isEOF); + } + + @Test + void should_fail_according_to_requirements() { + // GIVEN + Path asciiFile = Paths.get("src/test/resources/ascii.txt"); + // WHEN + AssertionError assertionError = expectAssertionError(() -> assertThat(asciiFile).satisfies(isEOF)); + // THEN + then(assertionError).hasMessageContaining("Expecting empty but was: [\"abc\"]"); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat("foo").satisfies(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat("foo").satisfies(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + + @Test + void should_propagate_AssertionError_as_is() { + // GIVEN + AssertionError assertionError = new AssertionError("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat("foo").satisfies(throwingConsumer(assertionError))); + // THEN + then(throwable).isSameAs(assertionError); + } + + @Test + void should_fail_if_throwing_consumer_is_null() { + // GIVEN + ThrowingConsumer nullRequirements = null; + // WHEN/THEN + thenNullPointerException().isThrownBy(() -> assertThat("foo").satisfies(nullRequirements)) + .withMessage("The Consumer expressing the assertions requirements must not be null"); + } + + private static ThrowingConsumer throwingConsumer(Throwable throwable) { + return value -> { + throw throwable; + }; + } +} diff --git a/src/test/resources/empty.txt b/src/test/resources/empty.txt new file mode 100644 index 00000000000..e69de29bb2d From d76dc0406573edb224560a2f2b6a3611aef27856 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Fri, 30 Jul 2021 14:14:05 +0200 Subject: [PATCH 049/123] Add one more test to cover the rethrow of `AssertionError` --- .../core/api/ThrowingConsumer_accept_Test.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java b/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java index e205907c713..a7f1fe41714 100644 --- a/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java +++ b/src/test/java/org/assertj/core/api/ThrowingConsumer_accept_Test.java @@ -44,6 +44,17 @@ void should_rethrow_runtime_exception_as_is() { then(throwable).isSameAs(runtimeException); } + @Test + void should_rethrow_assertion_error_as_is() { + // GIVEN + AssertionError assertionError = new AssertionError("boom!"); + ThrowingConsumer throwingConsumer = throwingConsumer(assertionError); + // WHEN + Throwable throwable = catchThrowable(() -> throwingConsumer.accept(null)); + // THEN + then(throwable).isSameAs(assertionError); + } + private static ThrowingConsumer throwingConsumer(Throwable throwable) { return value -> { throw throwable; From e07d9a2b3b1c9ed86e7d34b918c440a19b5b9dfa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 31 Jul 2021 00:22:38 +0200 Subject: [PATCH 050/123] Bump cdg.pitest.version from 0.0.11 to 0.0.12 (#2301) * Bump cdg.pitest.version from 0.0.11 to 0.0.12 Bumps `cdg.pitest.version` from 0.0.11 to 0.0.12. Updates `pitest-git-plugin` from 0.0.11 to 0.0.12 Updates `pitest-git-maven-plugin` from 0.0.11 to 0.0.12 --- updated-dependencies: - dependency-name: com.groupcdg:pitest-git-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.groupcdg:pitest-git-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump pitest-github-maven-plugin from 0.0.11 to 0.0.12 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefano Cordio --- .github/workflows/pitest-updated-pr.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pitest-updated-pr.yml b/.github/workflows/pitest-updated-pr.yml index 31056107eb1..2335a563740 100644 --- a/.github/workflows/pitest-updated-pr.yml +++ b/.github/workflows/pitest-updated-pr.yml @@ -42,4 +42,4 @@ jobs: # The updatePR maven goal is used here with an explicit version. This allows us to upload without checking out # the code, but does mean the version here must be maintained. An alternative would be to checkout the code and use # the github goal. This will work as long as the artifact is extracted to the maven target directory - run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.11:updatePR + run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.12:updatePR diff --git a/pom.xml b/pom.xml index 0e5a484073d..aa4f2e1d4a5 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 2.2 1.2.0 5.3.0 - 0.0.11 + 0.0.12 4.13.2 5.7.2 From afa29a8ad03599aba0a03bed434f2ea84f50e058 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 31 Jul 2021 09:50:03 +0200 Subject: [PATCH 051/123] Add missing `@since` --- src/main/java/org/assertj/core/api/AbstractAssert.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/assertj/core/api/AbstractAssert.java b/src/main/java/org/assertj/core/api/AbstractAssert.java index c04bc4622ba..a07faa02c65 100644 --- a/src/main/java/org/assertj/core/api/AbstractAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractAssert.java @@ -841,12 +841,13 @@ public SELF satisfies(Consumer requirements) { * * @throws NullPointerException if given {@link ThrowingConsumer} is null * @throws RuntimeException rethrown as is by given {@link ThrowingConsumer} or wrapping any {@link Throwable}. - * @throws AssertionError rethrown as is by given {@link ThrowingConsumer} + * @throws AssertionError rethrown as is by given {@link ThrowingConsumer} + * @since 3.21.0 */ public SELF satisfies(ThrowingConsumer throwingConsumer) { return internalSatisfies(throwingConsumer); } - + private SELF internalSatisfies(Consumer requirements) { requireNonNull(requirements, "The Consumer expressing the assertions requirements must not be null"); requirements.accept(actual); From 8dcdba13893ba2c2baff73efc2930bd7b667568e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Aug 2021 08:59:29 +0200 Subject: [PATCH 052/123] Bump byte-buddy.version from 1.11.9 to 1.11.10 (#2302) Bumps `byte-buddy.version` from 1.11.9 to 1.11.10. Updates `byte-buddy` from 1.11.9 to 1.11.10 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.9...byte-buddy-1.11.10) Updates `byte-buddy-agent` from 1.11.9 to 1.11.10 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.9...byte-buddy-1.11.10) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aa4f2e1d4a5..f2dbc440709 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.9 + 1.11.10 2.2 1.2.0 5.3.0 From b38e518dcf3f5e3fd489158726d7a4f34a690d30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Aug 2021 08:45:24 +0200 Subject: [PATCH 053/123] Bump byte-buddy.version from 1.11.10 to 1.11.11 (#2304) Bumps `byte-buddy.version` from 1.11.10 to 1.11.11. Updates `byte-buddy` from 1.11.10 to 1.11.11 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.10...byte-buddy-1.11.11) Updates `byte-buddy-agent` from 1.11.10 to 1.11.11 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.10...byte-buddy-1.11.11) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f2dbc440709..aad9012a49b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.10 + 1.11.11 2.2 1.2.0 5.3.0 From 58def33b5b9be4e2fa710a736226074826406984 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Aug 2021 08:33:41 +0200 Subject: [PATCH 054/123] Bump byte-buddy.version from 1.11.11 to 1.11.12 (#2306) Bumps `byte-buddy.version` from 1.11.11 to 1.11.12. Updates `byte-buddy` from 1.11.11 to 1.11.12 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.11...byte-buddy-1.11.12) Updates `byte-buddy-agent` from 1.11.11 to 1.11.12 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.11...byte-buddy-1.11.12) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aad9012a49b..33b7b540d95 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.11 + 1.11.12 2.2 1.2.0 5.3.0 From 6a94817e135cf875ed4b0d53b0e6257858920545 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Mon, 9 Aug 2021 22:20:44 +1200 Subject: [PATCH 055/123] Add satisfiesAnyOf with ThrowingConsumer --- .../org/assertj/core/api/AbstractAssert.java | 43 +++++- .../AbstractAssert_satisfiesAnyOf_Test.java | 11 +- ..._satisfiesAnyOf_ThrowinConsumers_Test.java | 122 ++++++++++++++++++ 3 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractAssert.java b/src/main/java/org/assertj/core/api/AbstractAssert.java index a07faa02c65..dd3a936d248 100644 --- a/src/main/java/org/assertj/core/api/AbstractAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractAssert.java @@ -888,10 +888,47 @@ public final SELF satisfiesAnyOf(Consumer... assertions) { return satisfiesAnyOfForProxy(assertions); } + /** + * Verifies that the actual object under test satisfies at least one of the given assertions group expressed as {@link ThrowingConsumer}s. + *

+ * This allows users to perform OR like assertions since only one the assertions group has to be met. + *

+ * This is the same assertion as {@link #satisfiesAnyOf(Consumer...)} but the given consumers can throw checked exceptions.
+ * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are while any other {@link Throwable} are rethrown as {@link RuntimeException}. + *

+ * {@link #overridingErrorMessage(String, Object...) Overriding error message} is not supported as it would prevent from + * getting the error messages of the failing assertions, these are valuable to figure out what went wrong.
+ * Describing the assertion is supported (for example with {@link #as(String, Object...)}). + *

+ * Example: + *

 // read() throws IOException
+   * ThrowingConsumer<FileReader> hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1);
+   * ThrowingConsumer<FileReader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
+   *
+   * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as Consumer<Reader> the following line would not compile): 
+   * assertThat(new FileReader("empty.txt")).satisfiesAnyOf(hasReachedEOF, startsWithZ);
+   *
+   * // alphabet.txt contains: abcdefghijklmnopqrstuvwxyz  
+   * // assertion fails as alphabet.txt is not empty and starts with 'a':
+   * assertThat(new FileReader("alphabet.txt")).satisfiesAnyOf(hasReachedEOF, startsWithZ);
+ * + * @param assertions the group of assertions to run against the object under test - must not be null. + * @return this assertion object. + * + * @throws IllegalArgumentException if any given assertions group is null + * @throws RuntimeException rethrown as is by given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError rethrown as is by given {@link ThrowingConsumer} + * @since 3.21.0 + */ + @SafeVarargs + public final SELF satisfiesAnyOf(ThrowingConsumer... assertions) { + return satisfiesAnyOfForProxy(assertions); + } + // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code - protected SELF satisfiesAnyOfForProxy(Consumer[] assertionsGroups) throws AssertionError { + protected SELF satisfiesAnyOfForProxy(Consumer[] assertionsGroups) throws AssertionError { checkArgument(stream(assertionsGroups).allMatch(java.util.Objects::nonNull), "No assertions group should be null"); if (stream(assertionsGroups).anyMatch(this::satisfiesAssertions)) return myself; // none of the assertions group was met! let's report all the errors @@ -904,7 +941,7 @@ private AssertionError multipleAssertionsError(List assertionErr return assertionErrorCreator.multipleAssertionsError(info.description(), assertionErrors); } - private boolean satisfiesAssertions(Consumer assertions) { + private boolean satisfiesAssertions(Consumer assertions) { try { assertions.accept(actual); } catch (@SuppressWarnings("unused") AssertionError e) { @@ -913,7 +950,7 @@ private boolean satisfiesAssertions(Consumer assertions) { return true; } - private AssertionError catchAssertionError(Consumer assertions) { + private AssertionError catchAssertionError(Consumer assertions) { try { assertions.accept(actual); } catch (AssertionError assertionError) { diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java index b5b39397e74..37d12803559 100644 --- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java @@ -82,18 +82,15 @@ void should_pass_when_all_of_the_given_assertions_groups_are_met() { // GIVEN Consumer namesStartsWithF = tolkienCharacter -> assertThat(tolkienCharacter.getName()).startsWith("F"); // THEN - assertThat(frodo).satisfiesAnyOf(isHobbit, namesStartsWithF) - .satisfiesAnyOf(isHobbit, namesStartsWithF, isHobbit, isDragon); + assertThat(frodo).satisfiesAnyOf(isHobbit, namesStartsWithF, isHobbit); } @Test void should_fail_if_all_of_the_given_assertions_groups_fail() { // GIVEN TolkienCharacter boromir = TolkienCharacter.of("Boromir", 45, MAN); - // WHEN - AssertionError error = expectAssertionError(() -> assertThat(boromir).as("description").satisfiesAnyOf(isHobbit, isElf)); - // THEN - assertThat(error).isNotNull(); + // WHEN/THEN + expectAssertionError(() -> assertThat(boromir).as("description").satisfiesAnyOf(isHobbit, isElf)); } @Test @@ -108,7 +105,7 @@ void should_honor_description() { Consumer isEmpty = string -> assertThat(string).isEmpty(); Consumer endsWithZ = string -> assertThat(string).endsWith("Z"); ThrowingCallable failingAssertionCode = () -> assertThat("abc").as("String checks").satisfiesAnyOf(isEmpty, endsWithZ); - // THEN + // WHEN AssertionError assertionError = expectAssertionError(failingAssertionCode); // THEN assertThat(assertionError).hasMessageContaining("String checks"); diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java new file mode 100644 index 00000000000..f6647094e9e --- /dev/null +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java @@ -0,0 +1,122 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.abstract_; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; + +import java.io.FileReader; +import java.io.IOException; +import java.util.List; + +import org.assertj.core.api.AbstractAssertBaseTest; +import org.assertj.core.api.ConcreteAssert; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.assertj.core.api.ThrowingConsumer; +import org.assertj.core.description.TextDescription; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +class AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test extends AbstractAssertBaseTest { + + @Override + protected ConcreteAssert invoke_api_method() { + ThrowingConsumer isZero = i -> assertThat(i).isNull(); + ThrowingConsumer isNegative = i -> assertThat(i).isInstanceOf(String.class); + expectAssertionError(() -> assertions.as("description").satisfiesAnyOf(isZero, isNegative)); + return null; + } + + @Override + protected void verify_internal_effects() { + // checks that the code invoked in invoke_api_method called multipleAssertionsError with the correct parameters + @SuppressWarnings("unchecked") + ArgumentCaptor> errors = ArgumentCaptor.forClass(List.class); + verify(assertionErrorCreator).multipleAssertionsError(eq(new TextDescription("description")), errors.capture()); + assertThat(errors.getValue()).hasSize(2); + assertThat(errors.getValue().get(0)).hasMessageContaining("null"); + assertThat(errors.getValue().get(1)).hasMessageContaining("to be an instance of"); + } + + @Override + public void should_return_this() { + // do nothing as we have invoked a failing assertion thus not returning anything. + } + + @Test + void should_pass_when_one_of_the_given_assertions_group_is_met() throws IOException { + // GIVEN + ThrowingConsumer hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1); + ThrowingConsumer startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z'); + // THEN + then(new FileReader("src/test/resources/empty.txt")).satisfiesAnyOf(hasReachedEOF, startsWithZ); + } + + @Test + void should_pass_when_all_of_the_given_assertions_groups_are_met() throws IOException { + // GIVEN + ThrowingConsumer hasNotReachedEOF = reader -> assertThat(reader.read()).isPositive(); + ThrowingConsumer startsWitha = reader -> assertThat(reader.read()).isEqualTo('a'); + // THEN + then(new FileReader("src/test/resources/ascii.txt")).satisfiesAnyOf(hasNotReachedEOF, startsWitha); + } + + @Test + void should_fail_if_all_of_the_given_assertions_groups_fail() { + // GIVEN + ThrowingConsumer hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1); + ThrowingConsumer startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z'); + // WHEN/THEN + expectAssertionError(() -> assertThat(new FileReader("src/test/resources/ascii.txt")).satisfiesAnyOf(hasReachedEOF, + startsWithZ)); + } + + @Test + void should_throw_an_IllegalArgumentException_if_one_of_the_given_assertions_group_is_null() { + // GIVEN + ThrowingConsumer hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1); + // WHEN/THEN + assertThatIllegalArgumentException().isThrownBy(() -> assertThat(new FileReader("src/test/resources/empty.txt")).satisfiesAnyOf(hasReachedEOF, + null)) + .withMessage("No assertions group should be null"); + } + + @Test + void should_honor_description() { + // GIVEN + ThrowingConsumer isEmpty = string -> assertThat(string).isEmpty(); + ThrowingConsumer endsWithZ = string -> assertThat(string).endsWith("Z"); + ThrowingCallable failingAssertionCode = () -> assertThat("abc").as("String checks").satisfiesAnyOf(isEmpty, endsWithZ); + // THEN + AssertionError assertionError = expectAssertionError(failingAssertionCode); + // THEN + then(assertionError).hasMessageContaining("String checks"); + } + + @Test + void should_not_honor_overriding_error_message() { + // GIVEN + ThrowingConsumer isEmpty = string -> assertThat(string).overridingErrorMessage("fail empty").isEmpty(); + ThrowingConsumer endsWithZ = string -> assertThat(string).endsWith("Z"); + ThrowingCallable failingAssertionCode = () -> assertThat("abc").satisfiesAnyOf(isEmpty, endsWithZ); + // WHEN + AssertionError assertionError = expectAssertionError(failingAssertionCode); + // THEN + then(assertionError).hasMessageContaining("fail empty"); + } + +} From 0b9bef0a722117585ba2b8ad3a657b160ba3b6b6 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Wed, 11 Aug 2021 22:58:23 +1200 Subject: [PATCH 056/123] Allow specifying supertype consumers for satisfies and satisfiesAnyOf in AbstractAssert --- .../org/assertj/core/api/AbstractAssert.java | 16 ++++++------- .../AbstractAssert_satisfiesAnyOf_Test.java | 23 +++++++++++++++++++ ...atisfiesAnyOf_ThrowingConsumers_Test.java} | 12 +++++++++- ...ctAssert_satisfies_with_Consumer_Test.java | 14 ++++++++--- ..._satisfies_with_ThrowingConsumer_Test.java | 10 +++++++- 5 files changed, 62 insertions(+), 13 deletions(-) rename src/test/java/org/assertj/core/api/abstract_/{AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java => AbstractAssert_satisfiesAnyOf_ThrowingConsumers_Test.java} (91%) diff --git a/src/main/java/org/assertj/core/api/AbstractAssert.java b/src/main/java/org/assertj/core/api/AbstractAssert.java index dd3a936d248..e3765a34d27 100644 --- a/src/main/java/org/assertj/core/api/AbstractAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractAssert.java @@ -816,7 +816,7 @@ public SELF matches(Predicate predicate, String predicateDescrip * * @throws NullPointerException if given Consumer is null */ - public SELF satisfies(Consumer requirements) { + public SELF satisfies(Consumer requirements) { return internalSatisfies(requirements); } @@ -844,11 +844,11 @@ public SELF satisfies(Consumer requirements) { * @throws AssertionError rethrown as is by given {@link ThrowingConsumer} * @since 3.21.0 */ - public SELF satisfies(ThrowingConsumer throwingConsumer) { + public SELF satisfies(ThrowingConsumer throwingConsumer) { return internalSatisfies(throwingConsumer); } - private SELF internalSatisfies(Consumer requirements) { + private SELF internalSatisfies(Consumer requirements) { requireNonNull(requirements, "The Consumer expressing the assertions requirements must not be null"); requirements.accept(actual); return myself; @@ -884,7 +884,7 @@ private SELF internalSatisfies(Consumer requirements) { * @since 3.12.0 */ @SafeVarargs - public final SELF satisfiesAnyOf(Consumer... assertions) { + public final SELF satisfiesAnyOf(Consumer... assertions) { return satisfiesAnyOfForProxy(assertions); } @@ -902,8 +902,8 @@ public final SELF satisfiesAnyOf(Consumer... assertions) { *

* Example: *

 // read() throws IOException
-   * ThrowingConsumer<FileReader> hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1);
-   * ThrowingConsumer<FileReader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
+   * ThrowingConsumer<Reader> hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1);
+   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    *
    * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as Consumer<Reader> the following line would not compile): 
    * assertThat(new FileReader("empty.txt")).satisfiesAnyOf(hasReachedEOF, startsWithZ);
@@ -921,14 +921,14 @@ public final SELF satisfiesAnyOf(Consumer... assertions) {
    * @since 3.21.0
    */
   @SafeVarargs
-  public final SELF satisfiesAnyOf(ThrowingConsumer... assertions) {
+  public final SELF satisfiesAnyOf(ThrowingConsumer... assertions) {
     return satisfiesAnyOfForProxy(assertions);
   }
 
   // This method is protected in order to be proxied for SoftAssertions / Assumptions.
   // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs
   // in order to avoid compiler warning in user code
-  protected SELF satisfiesAnyOfForProxy(Consumer[] assertionsGroups) throws AssertionError {
+  protected SELF satisfiesAnyOfForProxy(Consumer[] assertionsGroups) throws AssertionError {
     checkArgument(stream(assertionsGroups).allMatch(java.util.Objects::nonNull), "No assertions group should be null");
     if (stream(assertionsGroups).anyMatch(this::satisfiesAssertions)) return myself;
     // none of the assertions group was met! let's report all the errors
diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java
index 37d12803559..2daee76b9ba 100644
--- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java
+++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_Test.java
@@ -14,6 +14,7 @@
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.assertj.core.api.BDDAssertions.then;
 import static org.assertj.core.data.TolkienCharacter.Race.DRAGON;
 import static org.assertj.core.data.TolkienCharacter.Race.DWARF;
 import static org.assertj.core.data.TolkienCharacter.Race.ELF;
@@ -23,11 +24,15 @@
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
 import java.util.List;
 import java.util.function.Consumer;
 
 import org.assertj.core.api.AbstractAssertBaseTest;
 import org.assertj.core.api.ConcreteAssert;
+import org.assertj.core.api.ThrowingConsumer;
 import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
 import org.assertj.core.data.TolkienCharacter;
 import org.assertj.core.description.TextDescription;
@@ -85,6 +90,24 @@ void should_pass_when_all_of_the_given_assertions_groups_are_met() {
     assertThat(frodo).satisfiesAnyOf(isHobbit, namesStartsWithF, isHobbit);
   }
 
+  @Test
+  void should_pass_when_all_of_the_given_supertype_consumers_assertions_are_met() {
+    // GIVEN
+    Consumer notNullObject = object -> assertThat(object).isNotNull();
+    Consumer isString = object -> assertThat(object).isInstanceOf(String.class);
+    // WHEN/THEN
+    then(frodo).satisfiesAnyOf(notNullObject, isString);
+  }
+
+  @Test
+  void should_pass_with_mix_of_consumer_and_throwing_consumer() throws IOException {
+    // GIVEN
+    ThrowingConsumer hasNotReachedEOF = reader -> assertThat(reader.read()).isPositive();
+    Consumer notNullObject = object -> assertThat(object).isNotNull();
+    // THEN
+    then(new FileReader("src/test/resources/ascii.txt")).satisfiesAnyOf(hasNotReachedEOF, notNullObject);
+  }
+  
   @Test
   void should_fail_if_all_of_the_given_assertions_groups_fail() {
     // GIVEN
diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowingConsumers_Test.java
similarity index 91%
rename from src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java
rename to src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowingConsumers_Test.java
index f6647094e9e..5175ba15f61 100644
--- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test.java
+++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfiesAnyOf_ThrowingConsumers_Test.java
@@ -21,6 +21,7 @@
 
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.util.List;
 
 import org.assertj.core.api.AbstractAssertBaseTest;
@@ -31,7 +32,7 @@
 import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentCaptor;
 
-class AbstractAssert_satisfiesAnyOf_ThrowinConsumers_Test extends AbstractAssertBaseTest {
+class AbstractAssert_satisfiesAnyOf_ThrowingConsumers_Test extends AbstractAssertBaseTest {
 
   @Override
   protected ConcreteAssert invoke_api_method() {
@@ -75,6 +76,15 @@ void should_pass_when_all_of_the_given_assertions_groups_are_met() throws IOExce
     then(new FileReader("src/test/resources/ascii.txt")).satisfiesAnyOf(hasNotReachedEOF, startsWitha);
   }
 
+  @Test
+  void should_pass_when_all_of_the_given_supertype_consumers_assertions_are_met() throws IOException {
+    // GIVEN
+    ThrowingConsumer hasNotReachedEOF = reader -> assertThat(reader.read()).isPositive();
+    ThrowingConsumer notNullObject = object -> assertThat(object).isNotNull();
+    // THEN
+    then(new FileReader("src/test/resources/ascii.txt")).satisfiesAnyOf(hasNotReachedEOF, notNullObject);
+  }
+  
   @Test
   void should_fail_if_all_of_the_given_assertions_groups_fail() {
     // GIVEN
diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java
index 58111e96a0a..593deae5c32 100644
--- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java
+++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_Consumer_Test.java
@@ -13,8 +13,8 @@
 package org.assertj.core.api.abstract_;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatNullPointerException;
 import static org.assertj.core.api.BDDAssertions.then;
+import static org.assertj.core.api.BDDAssertions.thenNullPointerException;
 import static org.assertj.core.test.ErrorMessagesForTest.shouldBeEqualMessage;
 import static org.assertj.core.util.AssertionsUtil.expectAssertionError;
 
@@ -51,6 +51,14 @@ void should_satisfy_multiple_requirements() {
     assertThat(yoda).satisfies(jediRequirements);
   }
 
+  @Test
+  void should_satisfy_supertype_consumer() {
+    // GIVEN
+    Consumer notNullObjectConsumer = jedi -> assertThat(jedi).isNotNull();
+    // WHEN/THEN
+    then(yoda).satisfies(notNullObjectConsumer);
+  }
+
   @Test
   void should_fail_according_to_requirements() {
     // GIVEN
@@ -66,7 +74,7 @@ void should_fail_if_consumer_is_null() {
     // GIVEN
     Consumer nullRequirements = null;
     // WHEN/THEN
-    assertThatNullPointerException().isThrownBy(() -> assertThat(yoda).satisfies(nullRequirements))
-                                    .withMessage("The Consumer expressing the assertions requirements must not be null");
+    thenNullPointerException().isThrownBy(() -> assertThat(yoda).satisfies(nullRequirements))
+                              .withMessage("The Consumer expressing the assertions requirements must not be null");
   }
 }
diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java
index 69920f32b7a..ba26ec2e39d 100644
--- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java
+++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java
@@ -57,6 +57,14 @@ void should_satisfy_multiple_requirements() {
     then(emptyFile).satisfies(isEOF);
   }
 
+  @Test
+  void should_satisfy_supertype_consumer() {
+    // GIVEN
+    ThrowingConsumer notNullObjectConsumer = object -> assertThat(object).isNotNull();
+    // WHEN/THEN
+    then("foo").satisfies(notNullObjectConsumer);
+  }
+
   @Test
   void should_fail_according_to_requirements() {
     // GIVEN
@@ -97,7 +105,7 @@ void should_propagate_AssertionError_as_is() {
     // THEN
     then(throwable).isSameAs(assertionError);
   }
-  
+
   @Test
   void should_fail_if_throwing_consumer_is_null() {
     // GIVEN

From bce5cfd6bc11bfed3fc59357c7273ec9d0f9bbe5 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 12 Aug 2021 23:35:27 +0200
Subject: [PATCH 057/123] Bump pitest-maven from 1.6.8 to 1.6.9 (#2308)

Bumps [pitest-maven](https://github.com/hcoles/pitest) from 1.6.8 to 1.6.9.
- [Release notes](https://github.com/hcoles/pitest/releases)
- [Commits](https://github.com/hcoles/pitest/compare/pitest-parent-1.6.8...1.6.9)

---
updated-dependencies:
- dependency-name: org.pitest:pitest-maven
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] 

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 33b7b540d95..1ae49517a1a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -613,7 +613,7 @@
       
         org.pitest
         pitest-maven
-        1.6.8
+        1.6.9
         
           
             org.pitest

From 5fc69d002aac2a97dbfedfdd6085638ff1fca3f5 Mon Sep 17 00:00:00 2001
From: Andrey Kuzmin 
Date: Fri, 13 Aug 2021 16:16:00 +0300
Subject: [PATCH 058/123] Add `isMixedCase` to `CharSequence` assertions
 (#2246)

Co-authored-by: Stefano Cordio 
---
 .../core/api/AbstractCharSequenceAssert.java  | 39 +++++++++-
 .../assertj/core/error/ShouldBeMixedCase.java | 35 +++++++++
 .../org/assertj/core/internal/Strings.java    | 20 ++++-
 .../CharSequenceAssert_isMixedCase_Test.java  | 32 ++++++++
 .../error/ShouldBeLowerCase_create_Test.java  |  3 +-
 .../error/ShouldBeMixedCase_create_Test.java  | 33 ++++++++
 .../error/ShouldBeUpperCase_create_Test.java  |  3 +-
 .../Strings_assertIsLowerCase_Test.java       |  2 -
 .../Strings_assertIsMixedCase_Test.java       | 76 +++++++++++++++++++
 .../Strings_assertIsUpperCase_Test.java       |  2 -
 10 files changed, 231 insertions(+), 14 deletions(-)
 create mode 100644 src/main/java/org/assertj/core/error/ShouldBeMixedCase.java
 create mode 100644 src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_isMixedCase_Test.java
 create mode 100644 src/test/java/org/assertj/core/error/ShouldBeMixedCase_create_Test.java
 create mode 100644 src/test/java/org/assertj/core/internal/strings/Strings_assertIsMixedCase_Test.java

diff --git a/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java b/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java
index 9a8fb90975c..4efb6e7e2f6 100644
--- a/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java
+++ b/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java
@@ -1577,7 +1577,8 @@ public SELF isEqualToIgnoringNewLines(CharSequence expected) {
   }
 
   /**
-   * Verifies that the actual {@code CharSequence} is a lowercase {@code CharSequence} by comparing it to a lowercase {@code actual} built with {@link String#toLowerCase()}.
+   * Verifies that the actual {@code CharSequence} is a lowercase {@code CharSequence} by comparing it to
+   * a lowercase {@code actual} built with {@link String#toLowerCase()}.
    * 

* Example: *

 // assertions will pass
@@ -1594,6 +1595,8 @@ public SELF isEqualToIgnoringNewLines(CharSequence expected) {
    *
    * @return {@code this} assertion object.
    * @throws AssertionError if the actual {@code CharSequence} is not lowercase.
+   * @see #isMixedCase()
+   * @see #isUpperCase()
    */
   public SELF isLowerCase() {
     strings.assertLowerCase(info, actual);
@@ -1601,7 +1604,37 @@ public SELF isLowerCase() {
   }
 
   /**
-   * Verifies that the actual {@code CharSequence} is a uppercase {@code CharSequence} by comparing it to an uppercase {@code actual} built with {@link String#toUpperCase()}.
+   * Verifies that the actual {@code CharSequence} is a mixed case {@code CharSequence}, i.e.,
+   * neither uppercase nor lowercase.
+   * 

+ * If actual is empty or contains only case-independent characters, the assertion will pass. + *

+ * Example: + *

 // assertions will pass
+   * assertThat("Capitalized").isMixedCase();
+   * assertThat("camelCase").isMixedCase();
+   * assertThat("rAndOMcAse1234").isMixedCase();
+   * assertThat("1@3$567").isMixedCase();
+   * assertThat("").isMixedCase();
+   *
+   * // assertions will fail
+   * assertThat("I AM GROOT!").isMixedCase();
+   * assertThat("please be quiet").isMixedCase();
+ * + * @return {@code this} assertion object. + * @throws AssertionError if the actual {@code CharSequence} is not mixed case. + * @see #isLowerCase() + * @see #isUpperCase() + * @since 3.21.0 + */ + public SELF isMixedCase() { + strings.assertMixedCase(info, actual); + return myself; + } + + /** + * Verifies that the actual {@code CharSequence} is an uppercase {@code CharSequence} by comparing it to + * an uppercase {@code actual} built with {@link String#toUpperCase()}. *

* Example: *

 // assertions will pass
@@ -1618,6 +1651,8 @@ public SELF isLowerCase() {
    *
    * @return {@code this} assertion object.
    * @throws AssertionError if the actual {@code CharSequence} is not uppercase.
+   * @see #isLowerCase()
+   * @see #isMixedCase()
    */
   public SELF isUpperCase() {
     strings.assertUpperCase(info, actual);
diff --git a/src/main/java/org/assertj/core/error/ShouldBeMixedCase.java b/src/main/java/org/assertj/core/error/ShouldBeMixedCase.java
new file mode 100644
index 00000000000..e5ba39c5ae8
--- /dev/null
+++ b/src/main/java/org/assertj/core/error/ShouldBeMixedCase.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ * Copyright 2012-2021 the original author or authors.
+ */
+package org.assertj.core.error;
+
+/**
+ * Creates an error message that indicates an assertion that verifies that a {@code CharSequence} is mixed case failed.
+ * 
+ * @author Andrey Kuzmin
+ */
+public class ShouldBeMixedCase extends BasicErrorMessageFactory {
+
+  /**
+   * Creates a new {@link ShouldBeMixedCase}.
+   * @param actual the actual value in the failed assertion.
+   * @return the created {@code ErrorMessageFactory}.
+   */
+  public static ErrorMessageFactory shouldBeMixedCase(CharSequence actual) {
+    return new ShouldBeMixedCase(actual);
+  }
+
+  private ShouldBeMixedCase(CharSequence actual) {
+    super("%nExpecting %s to be mixed case", actual);
+  }
+
+}
diff --git a/src/main/java/org/assertj/core/internal/Strings.java b/src/main/java/org/assertj/core/internal/Strings.java
index aea57bd2674..1c535f8b68d 100644
--- a/src/main/java/org/assertj/core/internal/Strings.java
+++ b/src/main/java/org/assertj/core/internal/Strings.java
@@ -30,6 +30,7 @@
 import static org.assertj.core.error.ShouldBeEqualNormalizingUnicode.shouldBeEqualNormalizingUnicode;
 import static org.assertj.core.error.ShouldBeEqualNormalizingWhitespace.shouldBeEqualNormalizingWhitespace;
 import static org.assertj.core.error.ShouldBeLowerCase.shouldBeLowerCase;
+import static org.assertj.core.error.ShouldBeMixedCase.shouldBeMixedCase;
 import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty;
 import static org.assertj.core.error.ShouldBeSubstring.shouldBeSubstring;
 import static org.assertj.core.error.ShouldBeUpperCase.shouldBeUpperCase;
@@ -1203,14 +1204,25 @@ public void assertIsEqualToIgnoringNewLines(AssertionInfo info, CharSequence act
 
   public void assertLowerCase(AssertionInfo info, CharSequence actual) {
     assertNotNull(info, actual);
-    if (actual.equals(actual.toString().toLowerCase())) return;
-    throw failures.failure(info, shouldBeLowerCase(actual));
+    if (!isLowerCase(actual)) throw failures.failure(info, shouldBeLowerCase(actual));
+  }
+
+  private boolean isLowerCase(CharSequence actual) {
+    return actual.equals(actual.toString().toLowerCase());
   }
 
   public void assertUpperCase(AssertionInfo info, CharSequence actual) {
     assertNotNull(info, actual);
-    if (actual.equals(actual.toString().toUpperCase())) return;
-    throw failures.failure(info, shouldBeUpperCase(actual));
+    if (!isUpperCase(actual)) throw failures.failure(info, shouldBeUpperCase(actual));
+  }
+
+  private boolean isUpperCase(CharSequence actual) {
+    return actual.equals(actual.toString().toUpperCase());
+  }
+
+  public void assertMixedCase(AssertionInfo info, CharSequence actual) {
+    assertNotNull(info, actual);
+    if (isLowerCase(actual) != isUpperCase(actual)) throw failures.failure(info, shouldBeMixedCase(actual));
   }
 
   /***
diff --git a/src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_isMixedCase_Test.java b/src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_isMixedCase_Test.java
new file mode 100644
index 00000000000..53076137e3c
--- /dev/null
+++ b/src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_isMixedCase_Test.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ * Copyright 2012-2021 the original author or authors.
+ */
+package org.assertj.core.api.charsequence;
+
+import static org.mockito.Mockito.verify;
+
+import org.assertj.core.api.CharSequenceAssert;
+import org.assertj.core.api.CharSequenceAssertBaseTest;
+
+class CharSequenceAssert_isMixedCase_Test extends CharSequenceAssertBaseTest {
+
+  @Override
+  protected CharSequenceAssert invoke_api_method() {
+    return assertions.isMixedCase();
+  }
+
+  @Override
+  protected void verify_internal_effects() {
+    verify(strings).assertMixedCase(getInfo(assertions), getActual(assertions));
+  }
+
+}
diff --git a/src/test/java/org/assertj/core/error/ShouldBeLowerCase_create_Test.java b/src/test/java/org/assertj/core/error/ShouldBeLowerCase_create_Test.java
index b3aac5298a2..ec79f86ce4f 100644
--- a/src/test/java/org/assertj/core/error/ShouldBeLowerCase_create_Test.java
+++ b/src/test/java/org/assertj/core/error/ShouldBeLowerCase_create_Test.java
@@ -21,8 +21,6 @@
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests for {@link ShouldBeLowerCase#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)}.
- *
  * @author Alex Ruiz
  */
 class ShouldBeLowerCase_create_Test {
@@ -42,4 +40,5 @@ void should_create_error_message_for_string() {
     // THEN
     then(message).isEqualTo(format("[Test] %nExpecting \"ABC\" to be a lowercase"));
   }
+
 }
diff --git a/src/test/java/org/assertj/core/error/ShouldBeMixedCase_create_Test.java b/src/test/java/org/assertj/core/error/ShouldBeMixedCase_create_Test.java
new file mode 100644
index 00000000000..2fa1a86bff2
--- /dev/null
+++ b/src/test/java/org/assertj/core/error/ShouldBeMixedCase_create_Test.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ * Copyright 2012-2021 the original author or authors.
+ */
+package org.assertj.core.error;
+
+import static java.lang.String.format;
+import static org.assertj.core.api.BDDAssertions.then;
+import static org.assertj.core.error.ShouldBeMixedCase.shouldBeMixedCase;
+import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION;
+
+import org.assertj.core.description.TextDescription;
+import org.junit.jupiter.api.Test;
+
+class ShouldBeMixedCase_create_Test {
+
+  @Test
+  void should_create_error_message() {
+    // WHEN
+    String message = shouldBeMixedCase("ABC").create(new TextDescription("Test"), STANDARD_REPRESENTATION);
+    // THEN
+    then(message).isEqualTo(format("[Test] %nExpecting \"ABC\" to be mixed case"));
+  }
+
+}
diff --git a/src/test/java/org/assertj/core/error/ShouldBeUpperCase_create_Test.java b/src/test/java/org/assertj/core/error/ShouldBeUpperCase_create_Test.java
index 8ac1ac01c50..87703b684e7 100644
--- a/src/test/java/org/assertj/core/error/ShouldBeUpperCase_create_Test.java
+++ b/src/test/java/org/assertj/core/error/ShouldBeUpperCase_create_Test.java
@@ -21,8 +21,6 @@
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests for {@link ShouldBeUpperCase#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)}.
- *
  * @author Alex Ruiz
  */
 class ShouldBeUpperCase_create_Test {
@@ -42,4 +40,5 @@ void should_create_error_message_for_string() {
     // THEN
     then(message).isEqualTo(format("[Test] %nExpecting \"abc\" to be uppercase"));
   }
+
 }
diff --git a/src/test/java/org/assertj/core/internal/strings/Strings_assertIsLowerCase_Test.java b/src/test/java/org/assertj/core/internal/strings/Strings_assertIsLowerCase_Test.java
index 5c6cf52c584..7797a43f444 100644
--- a/src/test/java/org/assertj/core/internal/strings/Strings_assertIsLowerCase_Test.java
+++ b/src/test/java/org/assertj/core/internal/strings/Strings_assertIsLowerCase_Test.java
@@ -21,8 +21,6 @@
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests for {@link org.assertj.core.internal.Strings#assertLowerCase(org.assertj.core.api.AssertionInfo, CharSequence)} .
- *
  * @author Marcel Overdijk
  */
 class Strings_assertIsLowerCase_Test extends StringsBaseTest {
diff --git a/src/test/java/org/assertj/core/internal/strings/Strings_assertIsMixedCase_Test.java b/src/test/java/org/assertj/core/internal/strings/Strings_assertIsMixedCase_Test.java
new file mode 100644
index 00000000000..805ae09949e
--- /dev/null
+++ b/src/test/java/org/assertj/core/internal/strings/Strings_assertIsMixedCase_Test.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ *
+ * Copyright 2012-2021 the original author or authors.
+ */
+package org.assertj.core.internal.strings;
+
+import static org.assertj.core.api.BDDAssertions.then;
+import static org.assertj.core.error.ShouldBeMixedCase.shouldBeMixedCase;
+import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull;
+import static org.assertj.core.test.TestData.someInfo;
+import static org.assertj.core.util.AssertionsUtil.expectAssertionError;
+
+import org.assertj.core.internal.StringsBaseTest;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * @author Andrey Kuzmin
+ */
+class Strings_assertIsMixedCase_Test extends StringsBaseTest {
+
+  @Test
+  void should_fail_if_actual_is_null() {
+    // WHEN
+    AssertionError assertionError = expectAssertionError(() -> strings.assertMixedCase(someInfo(), null));
+    // THEN
+    then(assertionError).hasMessage(shouldNotBeNull().create());
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "I AM GROOT!",
+      "P",
+  })
+  void should_fail_if_actual_is_uppercase(CharSequence actual) {
+    // WHEN
+    AssertionError assertionError = expectAssertionError(() -> strings.assertMixedCase(someInfo(), actual));
+    // THEN
+    then(assertionError).hasMessage(shouldBeMixedCase(actual).create());
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "please be quiet",
+      "p",
+  })
+  void should_fail_if_actual_is_lowercase(CharSequence actual) {
+    // WHEN
+    AssertionError assertionError = expectAssertionError(() -> strings.assertMixedCase(someInfo(), actual));
+    // THEN
+    then(assertionError).hasMessage(shouldBeMixedCase(actual).create());
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {
+      "",
+      " ",
+      "anExampleOfCamelCaseString",
+      "anEx4mpl3OfC4m3lC4s3Str1ng!", // with numbers and special characters
+      "@$#24^", // only numbers and special characters
+  })
+  void should_pass_if_actual_is_mixed_case(CharSequence actual) {
+    // WHEN/THEN
+    strings.assertMixedCase(someInfo(), actual);
+  }
+
+}
diff --git a/src/test/java/org/assertj/core/internal/strings/Strings_assertIsUpperCase_Test.java b/src/test/java/org/assertj/core/internal/strings/Strings_assertIsUpperCase_Test.java
index e71e92d05a5..3c9764fb554 100644
--- a/src/test/java/org/assertj/core/internal/strings/Strings_assertIsUpperCase_Test.java
+++ b/src/test/java/org/assertj/core/internal/strings/Strings_assertIsUpperCase_Test.java
@@ -21,8 +21,6 @@
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests for {@link org.assertj.core.internal.Strings#assertUpperCase(org.assertj.core.api.AssertionInfo, CharSequence)} .
- *
  * @author Marcel Overdijk
  */
 class Strings_assertIsUpperCase_Test extends StringsBaseTest {

From cf63f1d8cf511dc76cd5a80fa06837265b74872e Mon Sep 17 00:00:00 2001
From: EugeneLesnov <53460983+EugeneLesnov@users.noreply.github.com>
Date: Fri, 13 Aug 2021 18:47:03 +0300
Subject: [PATCH 059/123] Add `containsAnyOf` to `CharSequence` assertions
 (#2309)

---
 .../core/api/AbstractCharSequenceAssert.java  |  33 +++++-
 .../core/error/ShouldContainAnyOf.java        |  22 ++--
 .../org/assertj/core/internal/Strings.java    |   7 ++
 ...CharSequenceAssert_containsAnyOf_Test.java |  33 ++++++
 .../error/ShouldContainAnyOf_create_Test.java |   2 +-
 .../internal/Arrays_containsAnyOf_Test.java   |   2 +-
 .../Iterables_assertContainsAnyOf_Test.java   |   3 +-
 .../Strings_assertContainsAnyOf_Test.java     | 105 ++++++++++++++++++
 .../strings/Strings_assertContains_Test.java  |   4 -
 9 files changed, 191 insertions(+), 20 deletions(-)
 create mode 100644 src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_containsAnyOf_Test.java
 create mode 100644 src/test/java/org/assertj/core/internal/strings/Strings_assertContainsAnyOf_Test.java

diff --git a/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java b/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java
index 4efb6e7e2f6..ca5316295b9 100644
--- a/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java
+++ b/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java
@@ -649,18 +649,41 @@ public SELF containsOnlyOnce(CharSequence sequence) {
    * 
 assertThat("Gandalf the grey").contains("alf");
    * assertThat("Gandalf the grey").contains("alf", "grey");
* - * @param values the Strings to look for. + * @param values the values to look for. * @return {@code this} assertion object. * @throws NullPointerException if the given list of values is {@code null}. * @throws IllegalArgumentException if the list of given values is empty. * @throws AssertionError if the actual {@code CharSequence} is {@code null}. - * @throws AssertionError if the actual {@code CharSequence} does not contain all the given strings. + * @throws AssertionError if the actual {@code CharSequence} does not contain all the given values. */ public SELF contains(CharSequence... values) { strings.assertContains(info, actual, values); return myself; } + /** + * Verifies that the actual {@code CharSequence} contains any of the given values. + *

+ * Example: + *

 // assertions will pass
+   * assertThat("Gandalf the grey").containsAnyOf("grey", "black");
+   *
+   * // assertions will fail
+   * assertThat("Gandalf the grey").containsAnyOf("white", "black");
+ * + * @param values the values to look for. + * @return {@code this} assertion object. + * @throws NullPointerException if the given list of values is {@code null}. + * @throws IllegalArgumentException if the list of given values is empty. + * @throws AssertionError if the actual {@code CharSequence} is {@code null}. + * @throws AssertionError if the actual {@code CharSequence} does not contain any of the given values. + * @since 3.21.0 + */ + public SELF containsAnyOf(CharSequence... values) { + strings.assertContainsAnyOf(info, actual, values); + return myself; + } + /** * Verifies that the actual {@code CharSequence} contains all the {@code CharSequence}s of the given Iterable. *

@@ -668,7 +691,7 @@ public SELF contains(CharSequence... values) { *

 assertThat("Gandalf the grey").contains(Arrays.asList("alf"));
    * assertThat("Gandalf the grey").contains(Arrays.asList("alf", "grey"));
* - * @param values the Strings to look for. + * @param values the values to look for. * @return {@code this} assertion object. * @throws NullPointerException if the given list of values is {@code null}. * @throws IllegalArgumentException if the list of given values is empty. @@ -833,12 +856,12 @@ public SELF containsIgnoringCase(CharSequence sequence) { * // assertion fails: * assertThat("Gandalf the grey").containsIgnoringWhitespaces("alF")
* - * @param values the Strings to look for. + * @param values the values to look for. * @return {@code this} assertion object. * @throws NullPointerException if the given list of values is {@code null}. * @throws IllegalArgumentException if the list of given values is empty. * @throws AssertionError if the actual {@code CharSequence} is {@code null}. - * @throws AssertionError if the actual {@code CharSequence} does not contain all the given strings. + * @throws AssertionError if the actual {@code CharSequence} does not contain all the given values. */ public SELF containsIgnoringWhitespaces(CharSequence... values) { strings.assertContainsIgnoringWhitespaces(info, actual, values); diff --git a/src/main/java/org/assertj/core/error/ShouldContainAnyOf.java b/src/main/java/org/assertj/core/error/ShouldContainAnyOf.java index c7ba91dced6..0246ba83e08 100644 --- a/src/main/java/org/assertj/core/error/ShouldContainAnyOf.java +++ b/src/main/java/org/assertj/core/error/ShouldContainAnyOf.java @@ -13,26 +13,32 @@ package org.assertj.core.error; import org.assertj.core.internal.ComparisonStrategy; -import org.assertj.core.internal.StandardComparisonStrategy; public class ShouldContainAnyOf extends BasicErrorMessageFactory { + private static final String DEFAULT_FORMAT = "%nExpecting actual:%n" + + " %s%n" + + "to contain at least one of the following elements:%n" + + " %s%n" + + "but none were found"; + + private static final String FORMAT_WITH_COMPARISON_STRATEGY = DEFAULT_FORMAT + " %s"; + public static ErrorMessageFactory shouldContainAnyOf(Object actual, Object expected, ComparisonStrategy comparisonStrategy) { return new ShouldContainAnyOf(actual, expected, comparisonStrategy); } public static ErrorMessageFactory shouldContainAnyOf(Object actual, Object expected) { - return shouldContainAnyOf(actual, expected, StandardComparisonStrategy.instance()); + return new ShouldContainAnyOf(actual, expected); } private ShouldContainAnyOf(Object actual, Object expected, ComparisonStrategy comparisonStrategy) { - super("%nExpecting actual:%n" + - " %s%n" + - "to contain at least one of the following elements:%n" + - " %s%n" + - "but none were found %s", - actual, expected, comparisonStrategy); + super(FORMAT_WITH_COMPARISON_STRATEGY, actual, expected, comparisonStrategy); + } + + private ShouldContainAnyOf(Object actual, Object expected) { + super(DEFAULT_FORMAT, actual, expected); } } diff --git a/src/main/java/org/assertj/core/internal/Strings.java b/src/main/java/org/assertj/core/internal/Strings.java index 1c535f8b68d..24022e9785c 100644 --- a/src/main/java/org/assertj/core/internal/Strings.java +++ b/src/main/java/org/assertj/core/internal/Strings.java @@ -34,6 +34,7 @@ import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; import static org.assertj.core.error.ShouldBeSubstring.shouldBeSubstring; import static org.assertj.core.error.ShouldBeUpperCase.shouldBeUpperCase; +import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldContainCharSequence.shouldContain; import static org.assertj.core.error.ShouldContainCharSequence.shouldContainIgnoringCase; import static org.assertj.core.error.ShouldContainCharSequence.shouldContainIgnoringWhitespaces; @@ -474,6 +475,12 @@ public void assertContains(AssertionInfo info, CharSequence actual, CharSequence throw failures.failure(info, shouldContain(actual, values, notFound, comparisonStrategy)); } + public void assertContainsAnyOf(AssertionInfo info, CharSequence actual, CharSequence[] values) { + doCommonCheckForCharSequence(info, actual, values); + boolean found = stream(values).anyMatch(value -> stringContains(actual, value)); + if (!found) throw failures.failure(info, shouldContainAnyOf(actual, values, comparisonStrategy)); + } + /** * Verifies that the given {@code CharSequence} contains only digits. * diff --git a/src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_containsAnyOf_Test.java b/src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_containsAnyOf_Test.java new file mode 100644 index 00000000000..67adc8a3f96 --- /dev/null +++ b/src/test/java/org/assertj/core/api/charsequence/CharSequenceAssert_containsAnyOf_Test.java @@ -0,0 +1,33 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.charsequence; + +import static org.assertj.core.util.Arrays.array; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.CharSequenceAssert; +import org.assertj.core.api.CharSequenceAssertBaseTest; + +class CharSequenceAssert_containsAnyOf_Test extends CharSequenceAssertBaseTest { + + @Override + protected CharSequenceAssert invoke_api_method() { + return assertions.containsAnyOf("a", "b", "c"); + } + + @Override + protected void verify_internal_effects() { + verify(strings).assertContainsAnyOf(getInfo(assertions), getActual(assertions), array("a", "b", "c")); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldContainAnyOf_create_Test.java b/src/test/java/org/assertj/core/error/ShouldContainAnyOf_create_Test.java index ad68b9dc232..ec25473e6e9 100644 --- a/src/test/java/org/assertj/core/error/ShouldContainAnyOf_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldContainAnyOf_create_Test.java @@ -37,7 +37,7 @@ void should_create_error_message() { " [\"Yoda\", \"Han\", \"Han\"]%n" + "to contain at least one of the following elements:%n" + " [\"Vador\", \"Leia\"]%n" + - "but none were found ")); + "but none were found")); } @Test diff --git a/src/test/java/org/assertj/core/internal/Arrays_containsAnyOf_Test.java b/src/test/java/org/assertj/core/internal/Arrays_containsAnyOf_Test.java index 5b1e117e3d6..f6ea0a62368 100644 --- a/src/test/java/org/assertj/core/internal/Arrays_containsAnyOf_Test.java +++ b/src/test/java/org/assertj/core/internal/Arrays_containsAnyOf_Test.java @@ -91,7 +91,7 @@ void should_fail_if_actual_does_not_contain_any_of_the_given_values() { Throwable error = catchThrowable(() -> arrays.assertContainsAnyOf(info, failures, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldContainAnyOf(actual, expected)); + verify(failures).failure(info, shouldContainAnyOf(actual, expected, StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ diff --git a/src/test/java/org/assertj/core/internal/iterables/Iterables_assertContainsAnyOf_Test.java b/src/test/java/org/assertj/core/internal/iterables/Iterables_assertContainsAnyOf_Test.java index 9c66930f1b8..363683605f6 100644 --- a/src/test/java/org/assertj/core/internal/iterables/Iterables_assertContainsAnyOf_Test.java +++ b/src/test/java/org/assertj/core/internal/iterables/Iterables_assertContainsAnyOf_Test.java @@ -30,6 +30,7 @@ import org.assertj.core.api.AssertionInfo; import org.assertj.core.internal.Iterables; import org.assertj.core.internal.IterablesBaseTest; +import org.assertj.core.internal.StandardComparisonStrategy; import org.assertj.core.test.Name; import org.junit.jupiter.api.Test; @@ -110,7 +111,7 @@ void should_fail_if_actual_does_not_contain_any_of_the_given_values() { Throwable error = catchThrowable(() -> iterables.assertContainsAnyOf(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldContainAnyOf(actual, expected)); + verify(failures).failure(info, shouldContainAnyOf(actual, expected, StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ diff --git a/src/test/java/org/assertj/core/internal/strings/Strings_assertContainsAnyOf_Test.java b/src/test/java/org/assertj/core/internal/strings/Strings_assertContainsAnyOf_Test.java new file mode 100644 index 00000000000..64cc9eab766 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/strings/Strings_assertContainsAnyOf_Test.java @@ -0,0 +1,105 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.strings; + +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; +import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; +import static org.assertj.core.test.TestData.someInfo; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; + +import org.assertj.core.internal.StandardComparisonStrategy; +import org.assertj.core.internal.StringsBaseTest; +import org.junit.jupiter.api.Test; + +class Strings_assertContainsAnyOf_Test extends StringsBaseTest { + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + CharSequence actual = null; + CharSequence[] values = array("Yoda", "Luke"); + // WHEN + AssertionError assertionError = expectAssertionError(() -> strings.assertContainsAnyOf(someInfo(), actual, values)); + // THEN + then(assertionError).hasMessage(shouldNotBeNull().create()); + } + + @Test + void should_fail_if_values_is_null() { + // GIVEN + CharSequence actual = "Master Yoda"; + CharSequence[] values = null; + // WHEN + Throwable thrown = catchThrowable(() -> strings.assertContainsAnyOf(someInfo(), actual, values)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The array of values to look for should not be null"); + } + + @Test + void should_fail_if_values_is_empty() { + // GIVEN + CharSequence actual = "Master Yoda"; + CharSequence[] values = array(); + // WHEN + Throwable thrown = catchThrowable(() -> strings.assertContainsAnyOf(someInfo(), actual, values)); + // THEN + then(thrown).isInstanceOf(IllegalArgumentException.class) + .hasMessage("The array of values to look for should not be empty"); + } + + @Test + void should_fail_if_values_contains_null() { + // GIVEN + CharSequence actual = "Master Yoda"; + CharSequence[] values = array("Yoda", "Luke", null); + // WHEN + Throwable thrown = catchThrowable(() -> strings.assertContainsAnyOf(someInfo(), actual, values)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("Expecting CharSequence elements not to be null but found one at index 2"); + } + + @Test + void should_fail_if_actual_does_not_contain_any_value() { + // GIVEN + CharSequence actual = "Leia"; + CharSequence[] values = array("Yoda", "Luke"); + // WHEN + AssertionError assertionError = expectAssertionError(() -> strings.assertContainsAnyOf(someInfo(), actual, values)); + // THEN + then(assertionError).hasMessage(shouldContainAnyOf(actual, values, StandardComparisonStrategy.instance()).create()); + } + + @Test + void should_pass_if_actual_contains_any_value() { + // GIVEN + CharSequence actual = "Master Yoda"; + CharSequence[] values = array("Yoda", "Luke"); + // WHEN/THEN + strings.assertContainsAnyOf(someInfo(), actual, values); + } + + @Test + void should_pass_if_actual_contains_any_value_according_to_custom_comparison_strategy() { + // GIVEN + CharSequence actual = "Master Yoda"; + CharSequence[] values = array("YODA", "LUKE"); + // WHEN/THEN + stringsWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(someInfo(), actual, values); + } + +} diff --git a/src/test/java/org/assertj/core/internal/strings/Strings_assertContains_Test.java b/src/test/java/org/assertj/core/internal/strings/Strings_assertContains_Test.java index be683488ba1..214f2e163b2 100644 --- a/src/test/java/org/assertj/core/internal/strings/Strings_assertContains_Test.java +++ b/src/test/java/org/assertj/core/internal/strings/Strings_assertContains_Test.java @@ -21,14 +21,10 @@ import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.core.util.Sets.newLinkedHashSet; -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Strings; import org.assertj.core.internal.StringsBaseTest; import org.junit.jupiter.api.Test; /** - * Tests for {@link Strings#assertContains(AssertionInfo, CharSequence, CharSequence)}. - * * @author Alex Ruiz * @author Joel Costigliola */ From 62539afb2337c696a16e3b47a7748ac25132e44e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 23:09:54 +0200 Subject: [PATCH 060/123] Bump equalsverifier from 3.7 to 3.7.1 (#2310) Bumps [equalsverifier](https://github.com/jqno/equalsverifier) from 3.7 to 3.7.1. - [Release notes](https://github.com/jqno/equalsverifier/releases) - [Changelog](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md) - [Commits](https://github.com/jqno/equalsverifier/compare/equalsverifier-3.7...equalsverifier-3.7.1) --- updated-dependencies: - dependency-name: nl.jqno.equalsverifier:equalsverifier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1ae49517a1a..39f763c3a07 100644 --- a/pom.xml +++ b/pom.xml @@ -174,7 +174,7 @@ nl.jqno.equalsverifier equalsverifier - 3.7 + 3.7.1 test From f88123340fad5acb9a150819c2add5e4157048a3 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 14 Aug 2021 04:19:30 +0200 Subject: [PATCH 061/123] Add type parameter to `ThrowableAssert` (#2311) This allows chaining assertions like `extracting(Function)` using type-specific extractors. --- .../core/api/AbstractThrowableAssert.java | 4 +-- .../java/org/assertj/core/api/Assertions.java | 2 +- .../core/api/AssertionsForClassTypes.java | 4 +-- .../org/assertj/core/api/Assumptions.java | 4 ++- .../org/assertj/core/api/BDDAssertions.java | 2 +- .../core/api/InstanceOfAssertFactories.java | 21 +++++++++-- .../org/assertj/core/api/Java6Assertions.java | 6 ++-- .../assertj/core/api/Java6BDDAssertions.java | 4 +-- .../api/Java6BDDSoftAssertionsProvider.java | 3 +- .../Java6StandardSoftAssertionsProvider.java | 3 +- .../org/assertj/core/api/ThrowableAssert.java | 9 ++--- .../core/api/ThrowableAssertAlternative.java | 4 +-- .../org/assertj/core/api/WithAssertions.java | 2 +- .../org/assertj/core/api/WithAssumptions.java | 2 +- .../api/InstanceOfAssertFactoriesTest.java | 35 ++++++++++++------- .../core/api/ThrowableAssertBaseTest.java | 6 ++-- ...eAssert_extracting_with_Function_Test.java | 19 ++++++++++ ...Assert_hasCauseExactlyInstanceOf_Test.java | 4 +-- ...rowableAssert_hasCauseInstanceOf_Test.java | 4 +-- ...hrowableAssert_hasCauseReference_Test.java | 4 +-- .../ThrowableAssert_hasCause_Test.java | 4 +-- ...leAssert_hasMessageContainingAll_Test.java | 9 ++--- ...wableAssert_hasMessageContaining_Test.java | 9 ++--- ...aining_with_String_format_syntax_Test.java | 4 +-- ...wableAssert_hasMessageEndingWith_Test.java | 9 ++--- ...ngWith_with_String_format_syntax_Test.java | 4 +-- ...bleAssert_hasMessageFindingMatch_Test.java | 5 +-- ...leAssert_hasMessageMatchingRegex_Test.java | 4 +-- ...ssert_hasMessageNotContainingAny_Test.java | 8 ++--- ...leAssert_hasMessageNotContaining_Test.java | 8 ++--- ...bleAssert_hasMessageStartingWith_Test.java | 9 ++--- ...ngWith_with_String_format_syntax_Test.java | 4 +-- .../ThrowableAssert_hasMessage_Test.java | 9 ++--- ...essage_with_String_format_syntax_Test.java | 2 +- .../ThrowableAssert_hasNoCause_Test.java | 9 ++--- ...Assert_hasNoSuppressedExceptions_Test.java | 5 +-- ...rt_hasRootCauseExactlyInstanceOf_Test.java | 4 +-- ...bleAssert_hasRootCauseInstanceOf_Test.java | 4 +-- ...owableAssert_hasRootCauseMessage_Test.java | 2 +- ...essage_with_String_format_syntax_Test.java | 4 +-- .../ThrowableAssert_hasRootCause_Test.java | 4 +-- ...leAssert_hasStackTraceContaining_Test.java | 7 ++-- ...aining_with_String_format_syntax_Test.java | 4 +-- ...bleAssert_hasSuppressedException_Test.java | 4 +-- 44 files changed, 138 insertions(+), 139 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractThrowableAssert.java b/src/main/java/org/assertj/core/api/AbstractThrowableAssert.java index b9b347627b7..e6842627db6 100644 --- a/src/main/java/org/assertj/core/api/AbstractThrowableAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractThrowableAssert.java @@ -177,7 +177,7 @@ public SELF hasNoCause() { */ public AbstractThrowableAssert getCause() { throwables.assertHasCause(info, actual); - return new ThrowableAssert(actual.getCause()); + return new ThrowableAssert<>(actual.getCause()); } /** @@ -200,7 +200,7 @@ public SELF hasNoCause() { */ public AbstractThrowableAssert getRootCause() { throwables.assertHasRootCause(info, actual); - return new ThrowableAssert(org.assertj.core.util.Throwables.getRootCause(actual)); + return new ThrowableAssert<>(org.assertj.core.util.Throwables.getRootCause(actual)); } /** diff --git a/src/main/java/org/assertj/core/api/Assertions.java b/src/main/java/org/assertj/core/api/Assertions.java index c692844be63..5fd0e846d90 100644 --- a/src/main/java/org/assertj/core/api/Assertions.java +++ b/src/main/java/org/assertj/core/api/Assertions.java @@ -1144,7 +1144,7 @@ public static AtomicStampedReferenceAssert assertThat(AtomicStamp * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ - public static AbstractThrowableAssert assertThat(Throwable actual) { + public static AbstractThrowableAssert assertThat(T actual) { return AssertionsForClassTypes.assertThat(actual); } diff --git a/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java b/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java index f900e90f2b3..a6d7ec4f65c 100644 --- a/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java +++ b/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java @@ -694,8 +694,8 @@ public static AbstractPeriodAssert assertThat(Period period) { * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ - public static AbstractThrowableAssert assertThat(Throwable actual) { - return new ThrowableAssert(actual); + public static AbstractThrowableAssert assertThat(T actual) { + return new ThrowableAssert<>(actual); } /** diff --git a/src/main/java/org/assertj/core/api/Assumptions.java b/src/main/java/org/assertj/core/api/Assumptions.java index 5b5e23a489e..767ea6c880f 100644 --- a/src/main/java/org/assertj/core/api/Assumptions.java +++ b/src/main/java/org/assertj/core/api/Assumptions.java @@ -903,7 +903,8 @@ public static > AbstractComparableAssert a * @return the created assumption for assertion object. * @since 2.9.0 / 3.9.0 */ - public static AbstractThrowableAssert assumeThat(Throwable actual) { + @SuppressWarnings("unchecked") + public static AbstractThrowableAssert assumeThat(T actual) { return asAssumption(ThrowableAssert.class, Throwable.class, actual); } @@ -921,6 +922,7 @@ public static > AbstractComparableAssert a * @return the created assumption for assertion object. * @since 2.9.0 / 3.9.0 */ + @SuppressWarnings("unchecked") public static AbstractThrowableAssert assumeThatThrownBy(ThrowingCallable shouldRaiseThrowable) { return asAssumption(ThrowableAssert.class, Throwable.class, catchThrowable(shouldRaiseThrowable)); } diff --git a/src/main/java/org/assertj/core/api/BDDAssertions.java b/src/main/java/org/assertj/core/api/BDDAssertions.java index e075264e57b..be6a7ec3eab 100644 --- a/src/main/java/org/assertj/core/api/BDDAssertions.java +++ b/src/main/java/org/assertj/core/api/BDDAssertions.java @@ -1148,7 +1148,7 @@ public static AtomicStampedReferenceAssert then(AtomicStampedRefe * @param actual the actual value. * @return the created assertion Throwable. */ - public static AbstractThrowableAssert then(Throwable actual) { + public static AbstractThrowableAssert then(T actual) { return assertThat(actual); } diff --git a/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java b/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java index f269e49d04b..d83c1d4f930 100644 --- a/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java +++ b/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java @@ -528,7 +528,8 @@ static InstanceOfAssertFactory> PERIOD = new InstanceOfAssertFactory<>(Period.class, Assertions::assertThat); + InstanceOfAssertFactory> PERIOD = new InstanceOfAssertFactory<>(Period.class, + Assertions::assertThat); /** * {@link InstanceOfAssertFactory} for an {@link AtomicBoolean}. @@ -727,8 +728,22 @@ static InstanceOfAssertFactory> THROWABLE = new InstanceOfAssertFactory<>(Throwable.class, - Assertions::assertThat); + InstanceOfAssertFactory> THROWABLE = new InstanceOfAssertFactory<>(Throwable.class, + Assertions::assertThat); + + /** + * {@link InstanceOfAssertFactory} for a {@link Throwable}. + * + * @param the {@code Throwable} type. + * @param type the element type instance. + * @return the factory instance. + * + * @see #THROWABLE + * @since 3.21.0 + */ + static InstanceOfAssertFactory> throwable(Class type) { + return new InstanceOfAssertFactory<>(type, Assertions::assertThat); + } /** * {@link InstanceOfAssertFactory} for a {@link CharSequence}. diff --git a/src/main/java/org/assertj/core/api/Java6Assertions.java b/src/main/java/org/assertj/core/api/Java6Assertions.java index a551c1ab9ed..1c035eb01fe 100644 --- a/src/main/java/org/assertj/core/api/Java6Assertions.java +++ b/src/main/java/org/assertj/core/api/Java6Assertions.java @@ -1036,8 +1036,8 @@ public static AbstractDateAssert assertThat(Date actual) { * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ - public static AbstractThrowableAssert assertThat(Throwable actual) { - return new ThrowableAssert(actual); + public static AbstractThrowableAssert assertThat(T actual) { + return new ThrowableAssert<>(actual); } /** @@ -1080,7 +1080,7 @@ public static AbstractDateAssert assertThat(Date actual) { */ @CanIgnoreReturnValue public static AbstractThrowableAssert assertThatThrownBy(ThrowingCallable shouldRaiseThrowable) { - return new ThrowableAssert(catchThrowable(shouldRaiseThrowable)).hasBeenThrown(); + return new ThrowableAssert<>(catchThrowable(shouldRaiseThrowable)).hasBeenThrown(); } /** diff --git a/src/main/java/org/assertj/core/api/Java6BDDAssertions.java b/src/main/java/org/assertj/core/api/Java6BDDAssertions.java index e98daad8287..c0e13b2f651 100644 --- a/src/main/java/org/assertj/core/api/Java6BDDAssertions.java +++ b/src/main/java/org/assertj/core/api/Java6BDDAssertions.java @@ -901,12 +901,12 @@ public static AbstractDateAssert then(Date actual) { } /** - * Creates a new instance of {@link org.assertj.core.api.ThrowableAssert}. + * Creates a new instance of {@link ThrowableAssert}. * * @param actual the actual value. * @return the created assertion Throwable. */ - public static AbstractThrowableAssert then(Throwable actual) { + public static AbstractThrowableAssert then(T actual) { return assertThat(actual); } diff --git a/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java b/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java index 941ef7a9667..cc379b6b302 100644 --- a/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java +++ b/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java @@ -755,7 +755,8 @@ default AtomicStampedReferenceAssert then(AtomicStampedReference< * @param actual the actual value. * @return the created assertion Throwable. */ - default ThrowableAssert then(Throwable actual) { + @SuppressWarnings("unchecked") + default ThrowableAssert then(T actual) { return proxy(ThrowableAssert.class, Throwable.class, actual); } diff --git a/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java b/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java index 4fd96746561..4d220806adf 100644 --- a/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java +++ b/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java @@ -753,7 +753,8 @@ default AtomicStampedReferenceAssert assertThat(AtomicStampedRefe * @param actual the actual value. * @return the created assertion Throwable. */ - default ThrowableAssert assertThat(Throwable actual) { + @SuppressWarnings("unchecked") + default ThrowableAssert assertThat(T actual) { return proxy(ThrowableAssert.class, Throwable.class, actual); } diff --git a/src/main/java/org/assertj/core/api/ThrowableAssert.java b/src/main/java/org/assertj/core/api/ThrowableAssert.java index 45c535a0178..3eba102c530 100644 --- a/src/main/java/org/assertj/core/api/ThrowableAssert.java +++ b/src/main/java/org/assertj/core/api/ThrowableAssert.java @@ -27,13 +27,13 @@ * @author Joel Costigliola * @author Mikhail Mazursky */ -public class ThrowableAssert extends AbstractThrowableAssert { +public class ThrowableAssert extends AbstractThrowableAssert, ACTUAL> { public interface ThrowingCallable { void call() throws Throwable; } - public ThrowableAssert(Throwable actual) { + public ThrowableAssert(ACTUAL actual) { super(actual, ThrowableAssert.class); } @@ -41,7 +41,8 @@ public ThrowableAssert(Callable runnable) { super(buildThrowableAssertFromCallable(runnable), ThrowableAssert.class); } - private static Throwable buildThrowableAssertFromCallable(Callable callable) throws AssertionError { + @SuppressWarnings("unchecked") + private static THROWABLE buildThrowableAssertFromCallable(Callable callable) throws AssertionError { try { callable.call(); // fail if the expected exception was *not* thrown @@ -53,7 +54,7 @@ private static Throwable buildThrowableAssertFromCallable(Callable callab throw e; } catch (Throwable throwable) { // the throwable we will check - return throwable; + return (THROWABLE) throwable; } } diff --git a/src/main/java/org/assertj/core/api/ThrowableAssertAlternative.java b/src/main/java/org/assertj/core/api/ThrowableAssertAlternative.java index 067f190ef6a..1eaa6b62d8e 100644 --- a/src/main/java/org/assertj/core/api/ThrowableAssertAlternative.java +++ b/src/main/java/org/assertj/core/api/ThrowableAssertAlternative.java @@ -29,11 +29,11 @@ public class ThrowableAssertAlternative extends AbstractObjectAssert, ACTUAL> { - private ThrowableAssert delegate; + private final ThrowableAssert delegate; public ThrowableAssertAlternative(final ACTUAL actual) { super(actual, ThrowableAssertAlternative.class); - delegate = new ThrowableAssert(actual); + delegate = new ThrowableAssert<>(actual); } /** diff --git a/src/main/java/org/assertj/core/api/WithAssertions.java b/src/main/java/org/assertj/core/api/WithAssertions.java index bdb1cccada0..888a85145d8 100644 --- a/src/main/java/org/assertj/core/api/WithAssertions.java +++ b/src/main/java/org/assertj/core/api/WithAssertions.java @@ -416,7 +416,7 @@ default AbstractDateAssert assertThat(final Date actual) { * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ - default AbstractThrowableAssert assertThat(final Throwable actual) { + default AbstractThrowableAssert assertThat(final T actual) { return Assertions.assertThat(actual); } diff --git a/src/main/java/org/assertj/core/api/WithAssumptions.java b/src/main/java/org/assertj/core/api/WithAssumptions.java index 00a646d7bb9..3e7214966df 100644 --- a/src/main/java/org/assertj/core/api/WithAssumptions.java +++ b/src/main/java/org/assertj/core/api/WithAssumptions.java @@ -210,7 +210,7 @@ default AbstractDateAssert assumeThat(final Date actual) { * @return the created assumption for assertion object. * @since 2.9.0 / 3.9.0 */ - default AbstractThrowableAssert assumeThat(final Throwable actual) { + default AbstractThrowableAssert assumeThat(final T actual) { return Assumptions.assumeThat(actual); } diff --git a/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java b/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java index 38489d908a4..7a2bdc8da23 100644 --- a/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java +++ b/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java @@ -117,13 +117,11 @@ import static org.assertj.core.api.InstanceOfAssertFactories.optional; import static org.assertj.core.api.InstanceOfAssertFactories.predicate; import static org.assertj.core.api.InstanceOfAssertFactories.stream; +import static org.assertj.core.api.InstanceOfAssertFactories.throwable; import static org.assertj.core.api.InstanceOfAssertFactories.type; import static org.assertj.core.test.Maps.mapOf; import static org.mockito.Mockito.mock; -import org.assertj.core.util.Strings; -import org.junit.jupiter.api.Test; - import java.io.ByteArrayInputStream; import java.io.File; import java.math.BigDecimal; @@ -172,6 +170,9 @@ import java.util.stream.LongStream; import java.util.stream.Stream; +import org.assertj.core.util.Strings; +import org.junit.jupiter.api.Test; + /** * @author Stefano Cordio */ @@ -380,7 +381,7 @@ void boolean_array_factory_should_allow_boolean_array_assertions() { @Test void boolean_2d_array_factory_should_allow_boolean_2d_array_assertions() { // GIVEN - Object value = new boolean[][] {{ true, false }, { false, true }}; + Object value = new boolean[][] { { true, false }, { false, true } }; // WHEN Boolean2DArrayAssert result = assertThat(value).asInstanceOf(BOOLEAN_2D_ARRAY); // THEN @@ -410,7 +411,7 @@ void byte_array_factory_should_allow_byte_array_assertions() { @Test void byte_2d_array_factory_should_allow_byte_2d_array_assertions() { // GIVEN - Object value = new byte[][] {{ 0, 1 }, { 2, 3 }}; + Object value = new byte[][] { { 0, 1 }, { 2, 3 } }; // WHEN Byte2DArrayAssert result = assertThat(value).asInstanceOf(BYTE_2D_ARRAY); // THEN @@ -440,7 +441,7 @@ void char_array_factory_should_allow_char_array_assertions() { @Test void char_2d_array_factory_should_allow_char_2d_array_assertions() { // GIVEN - Object value = new char[][] {{ 'a', 'b' }, { 'c', 'd' }}; + Object value = new char[][] { { 'a', 'b' }, { 'c', 'd' } }; // WHEN Char2DArrayAssert result = assertThat(value).asInstanceOf(CHAR_2D_ARRAY); // THEN @@ -480,7 +481,7 @@ void double_array_factory_should_allow_double_array_assertions() { @Test void double_2d_array_factory_should_allow_double_2d_array_assertions() { // GIVEN - Object value = new double[][] {{ 0.0, 1.0 }, { 2.0, 3.0 }}; + Object value = new double[][] { { 0.0, 1.0 }, { 2.0, 3.0 } }; // WHEN Double2DArrayAssert result = assertThat(value).asInstanceOf(DOUBLE_2D_ARRAY); // THEN @@ -550,7 +551,7 @@ void float_array_factory_should_allow_float_array_assertions() { @Test void float_2d_array_factory_should_allow_float_2d_array_assertions() { // GIVEN - Object value = new float[][] {{ 0.0f, 1.0f }, { 2.0f, 3.0f }}; + Object value = new float[][] { { 0.0f, 1.0f }, { 2.0f, 3.0f } }; // WHEN Float2DArrayAssert result = assertThat(value).asInstanceOf(FLOAT_2D_ARRAY); // THEN @@ -580,7 +581,7 @@ void int_array_factory_should_allow_int_array_assertions() { @Test void int_2d_array_factory_should_allow_int_2d_array_assertions() { // GIVEN - Object value = new int[][] {{ 0, 1 }, { 2, 3 }}; + Object value = new int[][] { { 0, 1 }, { 2, 3 } }; // WHEN Int2DArrayAssert result = assertThat(value).asInstanceOf(INT_2D_ARRAY); // THEN @@ -610,7 +611,7 @@ void long_array_factory_should_allow_long_array_assertions() { @Test void long_2d_array_factory_should_allow_long_2d_array_assertions() { // GIVEN - Object value = new long[][] {{ 0L, 1L }, { 2L, 3L }}; + Object value = new long[][] { { 0L, 1L }, { 2L, 3L } }; // WHEN Long2DArrayAssert result = assertThat(value).asInstanceOf(LONG_2D_ARRAY); // THEN @@ -640,7 +641,7 @@ void array_factory_should_allow_array_assertions() { @Test void array_2d_factory_should_allow_2d_array_assertions() { // GIVEN - Object value = new Object[][] {{ 0, "" }, { 3.0, 'b'}}; + Object value = new Object[][] { { 0, "" }, { 3.0, 'b' } }; // WHEN Object2DArrayAssert result = assertThat(value).asInstanceOf(ARRAY_2D); // THEN @@ -680,7 +681,7 @@ void short_array_factory_should_allow_short_array_assertions() { @Test void short_2d_array_factory_should_allow_short_2d_array_assertions() { // GIVEN - Object value = new short[][] {{ 0, 1 }, { 2, 3 }}; + Object value = new short[][] { { 0, 1 }, { 2, 3 } }; // WHEN Short2DArrayAssert result = assertThat(value).asInstanceOf(SHORT_2D_ARRAY); // THEN @@ -998,6 +999,16 @@ void throwable_factory_should_allow_throwable_assertions() { result.hasMessage("message"); } + @Test + void typed_throwable_factory_should_allow_typed_throwable_assertions() { + // GIVEN + Object value = new RuntimeException("message"); + // WHEN + AbstractThrowableAssert result = assertThat(value).asInstanceOf(throwable(RuntimeException.class)); + // THEN + result.hasMessage("message"); + } + @Test void char_sequence_factory_should_allow_char_sequence_assertions() { // GIVEN diff --git a/src/test/java/org/assertj/core/api/ThrowableAssertBaseTest.java b/src/test/java/org/assertj/core/api/ThrowableAssertBaseTest.java index 8841b4ca4ca..78e17b1080e 100644 --- a/src/test/java/org/assertj/core/api/ThrowableAssertBaseTest.java +++ b/src/test/java/org/assertj/core/api/ThrowableAssertBaseTest.java @@ -22,12 +22,12 @@ * @author Olivier Michallat * @author Libor Ondrusek */ -public abstract class ThrowableAssertBaseTest extends BaseTestTemplate { +public abstract class ThrowableAssertBaseTest extends BaseTestTemplate, Throwable> { protected Throwables throwables; @Override - protected ThrowableAssert create_assertions() { - return new ThrowableAssert(new Throwable("throwable message")); + protected ThrowableAssert create_assertions() { + return new ThrowableAssert<>(new Throwable("throwable message")); } @Override diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java new file mode 100644 index 00000000000..4e53179cb6d --- /dev/null +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java @@ -0,0 +1,19 @@ +package org.assertj.core.api.throwable; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class ThrowableAssert_extracting_with_Function_Test { + + @Test + void should_allow_type_specific_extractor() { + // GIVEN + Exception cause = new Exception("boom!"); + ClassNotFoundException exception = new ClassNotFoundException("message", cause); + // WHEN/THEN + assertThat(exception).extracting(ClassNotFoundException::getException) + .isSameAs(cause); + } + +} diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseExactlyInstanceOf_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseExactlyInstanceOf_Test.java index 877359bda4c..bbcfd850497 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseExactlyInstanceOf_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseExactlyInstanceOf_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasCauseExactlyInstanceOf(Class)}. - * * @author Jean-Christophe Gay */ class ThrowableAssert_hasCauseExactlyInstanceOf_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasCauseExactlyInstanceOf(Exception.class); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseInstanceOf_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseInstanceOf_Test.java index 0068d1d759c..dca68e761ff 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseInstanceOf_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseInstanceOf_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasCauseInstanceOf(Class)}. - * * @author Jean-Christophe Gay */ class ThrowableAssert_hasCauseInstanceOf_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasCauseInstanceOf(Exception.class); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseReference_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseReference_Test.java index 690a8093138..cf99674d7f8 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseReference_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCauseReference_Test.java @@ -19,10 +19,10 @@ class ThrowableAssert_hasCauseReference_Test extends ThrowableAssertBaseTest { - private Throwable npe = new NullPointerException(); + private final Throwable npe = new NullPointerException(); @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasCauseReference(npe); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCause_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCause_Test.java index 89fe90e682b..e04ff201d08 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCause_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasCause_Test.java @@ -23,10 +23,10 @@ class ThrowableAssert_hasCause_Test extends ThrowableAssertBaseTest { - private Throwable npe = new NullPointerException(); + private final Throwable npe = new NullPointerException(); @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasCause(npe); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContainingAll_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContainingAll_Test.java index d0e24a99bd9..e7ccb868f67 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContainingAll_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContainingAll_Test.java @@ -12,21 +12,18 @@ */ package org.assertj.core.api.throwable; -import org.assertj.core.api.ThrowableAssert; -import org.assertj.core.api.ThrowableAssertBaseTest; - import static org.mockito.Mockito.verify; +import org.assertj.core.api.ThrowableAssert; +import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageContainingAll(CharSequence...)}. - * * @author Phillip Webb */ class ThrowableAssert_hasMessageContainingAll_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageContainingAll("able", "message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_Test.java index 71c370c5e0e..3a42da970fc 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_Test.java @@ -12,21 +12,18 @@ */ package org.assertj.core.api.throwable; -import org.assertj.core.api.ThrowableAssert; -import org.assertj.core.api.ThrowableAssertBaseTest; - import static org.mockito.Mockito.verify; +import org.assertj.core.api.ThrowableAssert; +import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageContaining(String)}. - * * @author Joel Costigliola */ class ThrowableAssert_hasMessageContaining_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageContaining("able"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_with_String_format_syntax_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_with_String_format_syntax_Test.java index b5163664995..c8ad4bcb43a 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_with_String_format_syntax_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageContaining_with_String_format_syntax_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageContaining(String, Object...)}. - * * @author Krishna Chaithanya Ganta */ class ThrowableAssert_hasMessageContaining_with_String_format_syntax_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageContaining("able %s", "message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_Test.java index 9d359787927..86d0a550fec 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_Test.java @@ -12,21 +12,18 @@ */ package org.assertj.core.api.throwable; -import org.assertj.core.api.ThrowableAssert; -import org.assertj.core.api.ThrowableAssertBaseTest; - import static org.mockito.Mockito.verify; +import org.assertj.core.api.ThrowableAssert; +import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageEndingWith(String)}. - * * @author Joel Costigliola */ class ThrowableAssert_hasMessageEndingWith_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageEndingWith("age"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_with_String_format_syntax_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_with_String_format_syntax_Test.java index 1e9bc638d68..43368541637 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_with_String_format_syntax_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageEndingWith_with_String_format_syntax_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageEndingWith(String, Object...)}. - * * @author Krishna Chaithanya Ganta */ class ThrowableAssert_hasMessageEndingWith_with_String_format_syntax_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageEndingWith("%sage", "mess"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageFindingMatch_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageFindingMatch_Test.java index ac1733360ac..3f5edf3ed0e 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageFindingMatch_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageFindingMatch_Test.java @@ -18,17 +18,14 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageFindingMatch(String)} . - * * @author David Haccoun - * */ class ThrowableAssert_hasMessageFindingMatch_Test extends ThrowableAssertBaseTest { private static final String REGEX = "dummy regex"; @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageFindingMatch(REGEX); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageMatchingRegex_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageMatchingRegex_Test.java index f184135f12a..2f1a53a18d8 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageMatchingRegex_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageMatchingRegex_Test.java @@ -18,8 +18,6 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageMatching(String)}. - * * @author Libor Ondrusek */ class ThrowableAssert_hasMessageMatchingRegex_Test extends ThrowableAssertBaseTest { @@ -27,7 +25,7 @@ class ThrowableAssert_hasMessageMatchingRegex_Test extends ThrowableAssertBaseTe public static final String REGEX = "Given id='\\d{2,4}' not exists"; @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageMatching(REGEX); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContainingAny_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContainingAny_Test.java index 119589fd0db..a55fb06bbc6 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContainingAny_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContainingAny_Test.java @@ -12,20 +12,18 @@ */ package org.assertj.core.api.throwable; +import static org.mockito.Mockito.verify; + import org.assertj.core.api.ThrowableAssert; import org.assertj.core.api.ThrowableAssertBaseTest; -import static org.mockito.Mockito.verify; - /** - * Tests for {@link ThrowableAssert#hasMessageNotContainingAny(String)}. - * * @author Phillip Webb */ class ThrowableAssert_hasMessageNotContainingAny_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageNotContainingAny("catchable", "message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContaining_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContaining_Test.java index 1fa9570be71..dfded8de7e8 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContaining_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageNotContaining_Test.java @@ -12,21 +12,19 @@ */ package org.assertj.core.api.throwable; +import static org.mockito.Mockito.verify; + import org.assertj.core.api.ThrowableAssert; import org.assertj.core.api.ThrowableAssertBaseTest; -import static org.mockito.Mockito.verify; - /** - * Tests for {@link ThrowableAssert#hasMessageNotContaining(String)}. - * * @author Sandra Parsick * @author Georg Berky */ class ThrowableAssert_hasMessageNotContaining_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageNotContaining("catchable"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_Test.java index c3ef1bcdb6f..d7483403fda 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_Test.java @@ -12,21 +12,18 @@ */ package org.assertj.core.api.throwable; -import org.assertj.core.api.ThrowableAssert; -import org.assertj.core.api.ThrowableAssertBaseTest; - import static org.mockito.Mockito.verify; +import org.assertj.core.api.ThrowableAssert; +import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageStartingWith(String)}. - * * @author Joel Costigliola */ class ThrowableAssert_hasMessageStartingWith_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageStartingWith("throw"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_with_String_format_syntax_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_with_String_format_syntax_Test.java index e53cea1da12..ed6d567e959 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_with_String_format_syntax_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessageStartingWith_with_String_format_syntax_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessageStartingWith(String, Object...)}. - * * @author Krishna Chaithanya Ganta */ class ThrowableAssert_hasMessageStartingWith_with_String_format_syntax_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessageStartingWith("throw%s", "able"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_Test.java index a89e014befd..f5b2dc4a05a 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_Test.java @@ -12,21 +12,18 @@ */ package org.assertj.core.api.throwable; -import org.assertj.core.api.ThrowableAssert; -import org.assertj.core.api.ThrowableAssertBaseTest; - import static org.mockito.Mockito.verify; +import org.assertj.core.api.ThrowableAssert; +import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasMessage(String)}. - * * @author Joel Costigliola */ class ThrowableAssert_hasMessage_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessage("throwable message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_with_String_format_syntax_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_with_String_format_syntax_Test.java index 7d295a5a955..6d1fbc7f7b2 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_with_String_format_syntax_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasMessage_with_String_format_syntax_Test.java @@ -22,7 +22,7 @@ class ThrowableAssert_hasMessage_with_String_format_syntax_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasMessage("throwable message %s", "foo"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoCause_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoCause_Test.java index 8c176a05f7d..cb0c94b4939 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoCause_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoCause_Test.java @@ -12,21 +12,18 @@ */ package org.assertj.core.api.throwable; -import org.assertj.core.api.ThrowableAssert; -import org.assertj.core.api.ThrowableAssertBaseTest; - import static org.mockito.Mockito.verify; +import org.assertj.core.api.ThrowableAssert; +import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasNoCause()}. - * * @author Joel Costigliola */ class ThrowableAssert_hasNoCause_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasNoCause(); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoSuppressedExceptions_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoSuppressedExceptions_Test.java index 1ef04e2e448..fd9a4b9ec7b 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoSuppressedExceptions_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasNoSuppressedExceptions_Test.java @@ -19,13 +19,10 @@ import org.assertj.core.api.ThrowableAssertBaseTest; import org.junit.jupiter.api.Test; -/** - * Tests for {@link org.assertj.core.api.ThrowableAssert#hasNoSuppressedExceptions()}. - */ class ThrowableAssert_hasNoSuppressedExceptions_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasNoSuppressedExceptions(); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseExactlyInstanceOf_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseExactlyInstanceOf_Test.java index 65e985aad97..8d54102d909 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseExactlyInstanceOf_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseExactlyInstanceOf_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link org.assertj.core.api.ThrowableAssert#hasRootCauseExactlyInstanceOf(Class)}. - * * @author Jean-Christophe Gay */ class ThrowableAssert_hasRootCauseExactlyInstanceOf_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasRootCauseExactlyInstanceOf(Exception.class); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseInstanceOf_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseInstanceOf_Test.java index 9af720d292a..7095dd69a5e 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseInstanceOf_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseInstanceOf_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link org.assertj.core.api.ThrowableAssert#hasRootCauseInstanceOf(Class)}. - * * @author Jean-Christophe Gay */ class ThrowableAssert_hasRootCauseInstanceOf_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasRootCauseInstanceOf(Exception.class); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java index b3d5b5c534a..26981d0bb87 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_Test.java @@ -20,7 +20,7 @@ class ThrowableAssert_hasRootCauseMessage_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasRootCauseMessage("message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_with_String_format_syntax_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_with_String_format_syntax_Test.java index b1b2dc0b87b..58ee0691f6c 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_with_String_format_syntax_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCauseMessage_with_String_format_syntax_Test.java @@ -17,14 +17,12 @@ import org.assertj.core.api.ThrowableAssert; import org.assertj.core.api.ThrowableAssertBaseTest; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("ThrowableAssert hasRootCauseMessageWithStringFormat") class ThrowableAssert_hasRootCauseMessage_with_String_format_syntax_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasRootCauseMessage("%s %s", "expected", "message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCause_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCause_Test.java index 3c8b5347537..4da28db0b58 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCause_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasRootCause_Test.java @@ -24,10 +24,10 @@ class ThrowableAssert_hasRootCause_Test extends ThrowableAssertBaseTest { - private Throwable npe = new NullPointerException(); + private final Throwable npe = new NullPointerException(); @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasRootCause(npe); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_Test.java index e00c2ab4fd9..4468f2430b7 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_Test.java @@ -17,16 +17,13 @@ import org.assertj.core.api.ThrowableAssert; import org.assertj.core.api.ThrowableAssertBaseTest; - /** - * Tests for {@link ThrowableAssert#hasStackTraceContaining(String)}. - * * @author Daniel Zlotin */ class ThrowableAssert_hasStackTraceContaining_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasStackTraceContaining("able"); } @@ -34,5 +31,5 @@ protected ThrowableAssert invoke_api_method() { protected void verify_internal_effects() { verify(throwables).assertHasStackTraceContaining(getInfo(assertions), getActual(assertions), "able"); } - + } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_with_String_format_syntax_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_with_String_format_syntax_Test.java index e33fa119450..fc1aab55b86 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_with_String_format_syntax_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasStackTraceContaining_with_String_format_syntax_Test.java @@ -18,14 +18,12 @@ import org.assertj.core.api.ThrowableAssertBaseTest; /** - * Tests for {@link ThrowableAssert#hasStackTraceContaining(String, Object...)}. - * * @author Krishna Chaithanya Ganta */ class ThrowableAssert_hasStackTraceContaining_with_String_format_syntax_Test extends ThrowableAssertBaseTest { @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasStackTraceContaining("able%s", " message"); } diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasSuppressedException_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasSuppressedException_Test.java index d9396ec102a..6775c181bce 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasSuppressedException_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_hasSuppressedException_Test.java @@ -21,10 +21,10 @@ class ThrowableAssert_hasSuppressedException_Test extends ThrowableAssertBaseTest { - private Throwable npe = new NullPointerException(); + private final Throwable npe = new NullPointerException(); @Override - protected ThrowableAssert invoke_api_method() { + protected ThrowableAssert invoke_api_method() { return assertions.hasSuppressedException(npe); } From 8c5be542422da68b333d5fd3304be4eb9b8e619d Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sat, 14 Aug 2021 16:18:00 +0200 Subject: [PATCH 062/123] Remove redundant test --- .../core/api/Assertions_sync_with_Assumptions_Test.java | 9 --------- ...ertions_sync_with_InstanceOfAssertFactories_Test.java | 3 +-- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/test/java/org/assertj/core/api/Assertions_sync_with_Assumptions_Test.java b/src/test/java/org/assertj/core/api/Assertions_sync_with_Assumptions_Test.java index 6083fe562e3..2fc66806e2b 100644 --- a/src/test/java/org/assertj/core/api/Assertions_sync_with_Assumptions_Test.java +++ b/src/test/java/org/assertj/core/api/Assertions_sync_with_Assumptions_Test.java @@ -29,13 +29,4 @@ void standard_assertions_and_assumptions_should_have_the_same_assertions_methods .containsExactlyInAnyOrder(assumeThatMethods); } - @Test - void standard_assumptions_and_with_assumptions_should_have_the_same_assertions_methods() { - Method[] assumptionsMethods = findMethodsWithName(Assumptions.class, "assumeThat"); - Method[] withAssumptionsMethods = findMethodsWithName(WithAssumptions.class, "assumeThat"); - - assertThat(withAssumptionsMethods).usingElementComparator(IGNORING_DECLARING_CLASS_ONLY) - .containsExactlyInAnyOrder(assumptionsMethods); - } - } diff --git a/src/test/java/org/assertj/core/api/Assertions_sync_with_InstanceOfAssertFactories_Test.java b/src/test/java/org/assertj/core/api/Assertions_sync_with_InstanceOfAssertFactories_Test.java index 68d1009b0ec..15cb2b5ac28 100644 --- a/src/test/java/org/assertj/core/api/Assertions_sync_with_InstanceOfAssertFactories_Test.java +++ b/src/test/java/org/assertj/core/api/Assertions_sync_with_InstanceOfAssertFactories_Test.java @@ -39,8 +39,7 @@ class Assertions_sync_with_InstanceOfAssertFactories_Test extends BaseAssertions AbstractComparableAssert.class, // The comparison of the input GenericArrayTypes will always fail, since it verifies the inner TypeVariable which // returns the defining Method as result of TypeVariable#getGenericDeclaration(). - ObjectArrayAssert.class, - Object2DArrayAssert.class, + ObjectArrayAssert.class, Object2DArrayAssert.class, // A field factory for an object is pointless. ObjectAssert.class, }; From fc4a618f6ad26a94a84baa8d2527cc6f78c3fb08 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 15 Aug 2021 11:03:08 +0200 Subject: [PATCH 063/123] Bump Maven version from 3.8.1 to 3.8.2 --- .mvn/wrapper/maven-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index ffdc10e59f8..abd303b6738 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar From 4cddfb55f5377cbaf70112c983ea5b788d6e1a5c Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 15 Aug 2021 11:33:51 +0200 Subject: [PATCH 064/123] Cache only the Maven repository subdirectory --- .github/workflows/binary-compatibility.yml | 7 ++++--- .github/workflows/cross-version.yml | 7 ++++--- .github/workflows/main.yml | 14 ++++++++------ .github/workflows/pitest-receive-pr.yml | 3 ++- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml index c17ecbf8ad5..f5ab184f82d 100644 --- a/.github/workflows/binary-compatibility.yml +++ b/.github/workflows/binary-compatibility.yml @@ -25,12 +25,13 @@ jobs: with: distribution: 'zulu' java-version: 11 - - name: Cache Maven Repository + - name: Cache local Maven repository uses: actions/cache@v2 with: - path: ~/.m2 + path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven + restore-keys: | + ${{ runner.os }}-maven- - name: (`main` only) Compare with the latest release if: github.base_ref == null diff --git a/.github/workflows/cross-version.yml b/.github/workflows/cross-version.yml index fd8fc1c5724..20cb2794243 100644 --- a/.github/workflows/cross-version.yml +++ b/.github/workflows/cross-version.yml @@ -18,11 +18,12 @@ jobs: with: distribution: 'zulu' java-version: ${{ matrix.java }} - - name: Cache Maven Repository + - name: Cache local Maven repository uses: actions/cache@v2 with: - path: ~/.m2 + path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven + restore-keys: | + ${{ runner.os }}-maven- - name: Test run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e329148529..fa08ad2362f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,12 +18,13 @@ jobs: with: distribution: 'zulu' java-version: 11 - - name: Cache Maven Repository + - name: Cache local Maven repository uses: actions/cache@v2 with: - path: ~/.m2 + path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven + restore-keys: | + ${{ runner.os }}-maven- - name: Test run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc @@ -40,12 +41,13 @@ jobs: with: distribution: 'zulu' java-version: 11 - - name: Cache Maven Repository + - name: Cache local Maven repository uses: actions/cache@v2 with: - path: ~/.m2 + path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven + restore-keys: | + ${{ runner.os }}-maven- - name: Test with Sonar run: > ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc sonar:sonar diff --git a/.github/workflows/pitest-receive-pr.yml b/.github/workflows/pitest-receive-pr.yml index a4ac9fee377..db235747b9c 100644 --- a/.github/workflows/pitest-receive-pr.yml +++ b/.github/workflows/pitest-receive-pr.yml @@ -33,7 +33,8 @@ jobs: with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-maven- + restore-keys: | + ${{ runner.os }}-maven- - name: Setup Java uses: actions/setup-java@v2 with: From d391e2019a23bbbdfd1ecd4035f9141adcc0b092 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 15 Aug 2021 12:47:08 +0200 Subject: [PATCH 065/123] Remove `MockPathsBaseTest` (#2292) --- .../assertj/core/api/AbstractPathAssert.java | 6 +- .../core/internal/NioFilesWrapper.java | 38 +--- .../java/org/assertj/core/internal/Paths.java | 176 ++++++----------- .../api/path/PathAssert_hasContent_Test.java | 16 +- .../PathAssert_hasSameContentAs_Test.java | 2 +- ...thAssert_hasSameTextualContentAs_Test.java | 4 +- .../assertj/core/internal/PathsBaseTest.java | 19 +- .../internal/paths/MockPathsBaseTest.java | 142 ------------- .../paths/Paths_assertEndsWithRaw_Test.java | 85 +++++--- .../paths/Paths_assertEndsWith_Test.java | 110 +++++++---- .../Paths_assertExistsNoFollowLinks_Test.java | 53 +++-- .../paths/Paths_assertExists_Test.java | 57 ++++-- .../Paths_assertHasBinaryContent_Test.java | 149 +++++++------- .../paths/Paths_assertHasContent_Test.java | 139 ------------- ...s_assertHasDigest_AlgorithmBytes_Test.java | 155 --------------- ..._assertHasDigest_AlgorithmString_Test.java | 155 --------------- ...aths_assertHasDigest_DigestBytes_Test.java | 155 --------------- ...ths_assertHasDigest_DigestString_Test.java | 147 -------------- ...ith_MessageDigest_and_Byte_array_Test.java | 163 +++++++++++++++ ...st_with_MessageDigest_and_String_Test.java | 163 +++++++++++++++ ...igest_with_String_and_Byte_array_Test.java | 178 +++++++++++++++++ ...HasDigest_with_String_and_String_Test.java | 178 +++++++++++++++++ .../paths/Paths_assertHasFileName_Test.java | 16 +- .../Paths_assertHasNoParentRaw_Test.java | 55 ++++-- .../paths/Paths_assertHasNoParent_Test.java | 72 ++++--- .../paths/Paths_assertHasParentRaw_Test.java | 107 ++++++---- .../paths/Paths_assertHasParent_Test.java | 154 ++++++++------- ...ths_assertHasSameBinaryContentAs_Test.java | 153 +++++++------- .../Paths_assertHasSameContentAs_Test.java | 163 --------------- ...hs_assertHasSameTextualContentAs_Test.java | 170 ++++++++++++++++ .../paths/Paths_assertHasSize_Test.java | 20 +- .../Paths_assertHasTextualContent_Test.java | 129 ++++++++++++ .../paths/Paths_assertIsAbsolute_Test.java | 46 +++-- .../paths/Paths_assertIsCanonical_Test.java | 62 +++--- ...tIsDirectoryContaining_Predicate_Test.java | 166 ---------------- ...ctoryContaining_SyntaxAndPattern_Test.java | 187 ------------------ ...rectoryContaining_with_Predicate_Test.java | 135 +++++++++++++ ...sDirectoryContaining_with_String_Test.java | 135 +++++++++++++ ...DirectoryNotContaining_Predicate_Test.java | 171 ---------------- ...ryNotContaining_SyntaxAndPattern_Test.java | 177 ----------------- ...toryNotContaining_with_Predicate_Test.java | 132 +++++++++++++ ...rectoryNotContaining_with_String_Test.java | 131 ++++++++++++ .../paths/Paths_assertIsDirectory_Test.java | 57 +++--- .../Paths_assertIsEmptyDirectory_Test.java | 81 ++++---- .../paths/Paths_assertIsEmptyFile_Test.java | 77 ++++---- .../paths/Paths_assertIsExecutable_Test.java | 60 +++--- .../paths/Paths_assertIsNormalized_Test.java | 78 ++++++-- .../Paths_assertIsNotEmptyDirectory_Test.java | 77 ++++---- .../Paths_assertIsNotEmptyFile_Test.java | 77 ++++---- .../paths/Paths_assertIsReadable_Test.java | 60 +++--- .../paths/Paths_assertIsRegularFile_Test.java | 58 +++--- .../paths/Paths_assertIsRelative_Test.java | 37 ++-- .../Paths_assertIsSymbolicLink_Test.java | 58 +++--- .../paths/Paths_assertIsWritable_Test.java | 57 +++--- .../paths/Paths_assertNotExists_Test.java | 52 +++-- .../paths/Paths_assertStartsWithRaw_Test.java | 86 +++++--- .../paths/Paths_assertStartsWith_Test.java | 131 +++++++----- 57 files changed, 2847 insertions(+), 2870 deletions(-) delete mode 100644 src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasContent_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmBytes_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmString_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestBytes_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestString_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameContentAs_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_Predicate_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_SyntaxAndPattern_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_Predicate_Test.java delete mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index 16c017eef47..a6ceeec132d 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -166,7 +166,7 @@ public SELF hasSameContentAs(Path expected) { * @since 3.15 */ public SELF hasSameTextualContentAs(Path expected) { - paths.assertHasSameContentAs(info, actual, charset, expected, Charset.defaultCharset()); + paths.assertHasSameTextualContentAs(info, actual, charset, expected, Charset.defaultCharset()); return myself; } @@ -198,7 +198,7 @@ public SELF hasSameTextualContentAs(Path expected) { * @since 3.15 */ public SELF hasSameTextualContentAs(Path expected, Charset expectedCharset) { - paths.assertHasSameContentAs(info, actual, charset, expected, expectedCharset); + paths.assertHasSameTextualContentAs(info, actual, charset, expected, expectedCharset); return myself; } @@ -377,7 +377,7 @@ public SELF usingCharset(Charset charset) { * @throws AssertionError if the content of the actual {@code Path} is not equal to the given content. */ public SELF hasContent(String expected) { - paths.assertHasContent(info, actual, expected, charset); + paths.assertHasTextualContent(info, actual, expected, charset); return myself; } diff --git a/src/main/java/org/assertj/core/internal/NioFilesWrapper.java b/src/main/java/org/assertj/core/internal/NioFilesWrapper.java index 8f31c97f014..253cb2802da 100644 --- a/src/main/java/org/assertj/core/internal/NioFilesWrapper.java +++ b/src/main/java/org/assertj/core/internal/NioFilesWrapper.java @@ -22,54 +22,18 @@ import java.util.function.Predicate; /** - * Wrapper for {@link java.nio.file.Files} to test {@link Paths}. + * Wrapper for {@link java.nio.file.Files} to test methods throwing {@link IOException}. */ public class NioFilesWrapper { private static final NioFilesWrapper INSTANCE = new NioFilesWrapper(); - /** - * Returns the singleton instance of this class. - * @return the singleton instance of this class. - */ static NioFilesWrapper instance() { return INSTANCE; } private NioFilesWrapper() {} - public boolean isRegularFile(Path path) { - return Files.isRegularFile(path); - } - - public boolean isSymbolicLink(Path path) { - return Files.isSymbolicLink(path); - } - - public boolean isDirectory(Path path) { - return Files.isDirectory(path); - } - - public boolean exists(Path path, LinkOption... options) { - return Files.exists(path, options); - } - - public boolean notExists(Path path, LinkOption... options) { - return Files.notExists(path, options); - } - - public boolean isReadable(Path path) { - return Files.isReadable(path); - } - - public boolean isWritable(Path path) { - return Files.isWritable(path); - } - - public boolean isExecutable(Path path) { - return Files.isExecutable(path); - } - public InputStream newInputStream(Path path, OpenOption... options) throws IOException { return Files.newInputStream(path, options); } diff --git a/src/main/java/org/assertj/core/internal/Paths.java b/src/main/java/org/assertj/core/internal/Paths.java index 0dbd7e89d1c..fc92bcd2597 100644 --- a/src/main/java/org/assertj/core/internal/Paths.java +++ b/src/main/java/org/assertj/core/internal/Paths.java @@ -54,6 +54,7 @@ import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.nio.file.DirectoryStream; +import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.PathMatcher; @@ -64,7 +65,6 @@ import java.util.stream.Stream; import org.assertj.core.api.AssertionInfo; -import org.assertj.core.api.exception.PathsException; import org.assertj.core.util.VisibleForTesting; import org.assertj.core.util.diff.Delta; @@ -75,12 +75,8 @@ */ public class Paths { - private static final String FAILED_TO_RESOLVE_ARGUMENT_REAL_PATH = "failed to resolve argument real path"; - private static final String FAILED_TO_RESOLVE_ACTUAL_REAL_PATH = "failed to resolve actual real path"; private static final String UNABLE_TO_COMPARE_PATH_CONTENTS = "Unable to compare contents of paths:<%s> and:<%s>"; - public static final String IOERROR_FORMAT = "I/O error attempting to process assertion for path: <%s>"; - private static final Paths INSTANCE = new Paths(); private static final Predicate ANY = any -> true; @@ -90,70 +86,62 @@ public class Paths { BinaryDiff binaryDiff = new BinaryDiff(); @VisibleForTesting Failures failures = Failures.instance(); - - private final NioFilesWrapper nioFilesWrapper; + @VisibleForTesting + NioFilesWrapper nioFilesWrapper = NioFilesWrapper.instance(); public static Paths instance() { return INSTANCE; } - @VisibleForTesting - Paths(NioFilesWrapper nioFilesWrapper) { - this.nioFilesWrapper = nioFilesWrapper; - } - private Paths() { - this(NioFilesWrapper.instance()); } public void assertIsReadable(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); assertExists(info, actual); - if (!nioFilesWrapper.isReadable(actual)) throw failures.failure(info, shouldBeReadable(actual)); + if (!Files.isReadable(actual)) throw failures.failure(info, shouldBeReadable(actual)); } public void assertIsWritable(AssertionInfo info, Path actual) { assertNotNull(info, actual); assertExists(info, actual); - if (!nioFilesWrapper.isWritable(actual)) throw failures.failure(info, shouldBeWritable(actual)); + if (!Files.isWritable(actual)) throw failures.failure(info, shouldBeWritable(actual)); } public void assertIsExecutable(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); assertExists(info, actual); - if (!nioFilesWrapper.isExecutable(actual)) throw failures.failure(info, shouldBeExecutable(actual)); + if (!Files.isExecutable(actual)) throw failures.failure(info, shouldBeExecutable(actual)); } public void assertExists(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); - if (!nioFilesWrapper.exists(actual)) throw failures.failure(info, shouldExist(actual)); + if (!Files.exists(actual)) throw failures.failure(info, shouldExist(actual)); } public void assertExistsNoFollowLinks(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); - if (!nioFilesWrapper.exists(actual, LinkOption.NOFOLLOW_LINKS)) - throw failures.failure(info, shouldExistNoFollowLinks(actual)); + if (!Files.exists(actual, LinkOption.NOFOLLOW_LINKS)) throw failures.failure(info, shouldExistNoFollowLinks(actual)); } public void assertDoesNotExist(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); - if (!nioFilesWrapper.notExists(actual, LinkOption.NOFOLLOW_LINKS)) - throw failures.failure(info, shouldNotExist(actual)); + if (!Files.notExists(actual, LinkOption.NOFOLLOW_LINKS)) throw failures.failure(info, shouldNotExist(actual)); } public void assertIsRegularFile(final AssertionInfo info, final Path actual) { assertExists(info, actual); - if (!nioFilesWrapper.isRegularFile(actual)) throw failures.failure(info, shouldBeRegularFile(actual)); + if (!Files.isRegularFile(actual)) throw failures.failure(info, shouldBeRegularFile(actual)); } public void assertIsDirectory(final AssertionInfo info, final Path actual) { assertExists(info, actual); - if (!nioFilesWrapper.isDirectory(actual)) throw failures.failure(info, shouldBeDirectory(actual)); + if (!Files.isDirectory(actual)) throw failures.failure(info, shouldBeDirectory(actual)); } public void assertIsSymbolicLink(final AssertionInfo info, final Path actual) { assertExistsNoFollowLinks(info, actual); - if (!nioFilesWrapper.isSymbolicLink(actual)) throw failures.failure(info, shouldBeSymbolicLink(actual)); + if (!Files.isSymbolicLink(actual)) throw failures.failure(info, shouldBeSymbolicLink(actual)); } public void assertIsAbsolute(final AssertionInfo info, final Path actual) { @@ -173,55 +161,28 @@ public void assertIsNormalized(final AssertionInfo info, final Path actual) { public void assertIsCanonical(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); - try { - if (!actual.equals(actual.toRealPath())) throw failures.failure(info, shouldBeCanonicalPath(actual)); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); - } + if (!actual.equals(toRealPath(actual))) throw failures.failure(info, shouldBeCanonicalPath(actual)); } public void assertHasParent(final AssertionInfo info, final Path actual, final Path expected) { assertNotNull(info, actual); checkExpectedParentPathIsNotNull(expected); - - final Path canonicalActual; - try { - canonicalActual = actual.toRealPath(); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); - } - - final Path canonicalExpected; - try { - canonicalExpected = expected.toRealPath(); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ARGUMENT_REAL_PATH, e); - } - - final Path actualParent = canonicalActual.getParent(); - if (actualParent == null) throw failures.failure(info, shouldHaveParent(actual, expected)); - if (!actualParent.equals(canonicalExpected)) - throw failures.failure(info, shouldHaveParent(actual, actualParent, expected)); + Path parent = toRealPath(actual).getParent(); + if (parent == null) throw failures.failure(info, shouldHaveParent(actual, expected)); + if (!parent.equals(toRealPath(expected))) throw failures.failure(info, shouldHaveParent(actual, parent, expected)); } public void assertHasParentRaw(final AssertionInfo info, final Path actual, final Path expected) { assertNotNull(info, actual); checkExpectedParentPathIsNotNull(expected); - - final Path actualParent = actual.getParent(); - if (actualParent == null) throw failures.failure(info, shouldHaveParent(actual, expected)); - if (!actualParent.equals(expected)) - throw failures.failure(info, shouldHaveParent(actual, actualParent, expected)); + Path parent = actual.getParent(); + if (parent == null) throw failures.failure(info, shouldHaveParent(actual, expected)); + if (!parent.equals(expected)) throw failures.failure(info, shouldHaveParent(actual, parent, expected)); } public void assertHasNoParent(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); - try { - final Path canonicalActual = actual.toRealPath(); - if (canonicalActual.getParent() != null) throw failures.failure(info, shouldHaveNoParent(actual)); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); - } + if (toRealPath(actual).getParent() != null) throw failures.failure(info, shouldHaveNoParent(actual)); } public void assertHasNoParentRaw(final AssertionInfo info, final Path actual) { @@ -234,30 +195,15 @@ public void assertHasSize(final AssertionInfo info, final Path actual, long expe try { long actualSize = nioFilesWrapper.size(actual); if (actualSize != expectedSize) throw failures.failure(info, shouldHaveSize(actual, expectedSize)); - } catch(IOException e) { - throw new UncheckedIOException(format("unable to verify the size of the path: <%s>", actual), e); + } catch (IOException e) { + throw new UncheckedIOException(e); } } - public void assertStartsWith(final AssertionInfo info, final Path actual, final Path start) { + public void assertStartsWith(final AssertionInfo info, final Path actual, final Path other) { assertNotNull(info, actual); - assertExpectedStartPathIsNotNull(start); - - final Path canonicalActual; - try { - canonicalActual = actual.toRealPath(); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); - } - - final Path canonicalOther; - try { - canonicalOther = start.toRealPath(); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ARGUMENT_REAL_PATH, e); - } - - if (!canonicalActual.startsWith(canonicalOther)) throw failures.failure(info, shouldStartWith(actual, start)); + assertExpectedStartPathIsNotNull(other); + if (!toRealPath(actual).startsWith(toRealPath(other))) throw failures.failure(info, shouldStartWith(actual, other)); } public void assertStartsWithRaw(final AssertionInfo info, final Path actual, final Path other) { @@ -266,15 +212,10 @@ public void assertStartsWithRaw(final AssertionInfo info, final Path actual, fin if (!actual.startsWith(other)) throw failures.failure(info, shouldStartWith(actual, other)); } - public void assertEndsWith(final AssertionInfo info, final Path actual, final Path end) { + public void assertEndsWith(final AssertionInfo info, final Path actual, final Path other) { assertNotNull(info, actual); - assertExpectedEndPathIsNotNull(end); - try { - final Path canonicalActual = actual.toRealPath(); - if (!canonicalActual.endsWith(end.normalize())) throw failures.failure(info, shouldEndWith(actual, end)); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); - } + assertExpectedEndPathIsNotNull(other); + if (!toRealPath(actual).endsWith(other.normalize())) throw failures.failure(info, shouldEndWith(actual, other)); } public void assertEndsWithRaw(final AssertionInfo info, final Path actual, final Path end) { @@ -289,13 +230,12 @@ public void assertHasFileName(final AssertionInfo info, Path actual, String file if (!actual.getFileName().endsWith(fileName)) throw failures.failure(info, shouldHaveName(actual, fileName)); } - public void assertHasContent(final AssertionInfo info, Path actual, String expected, Charset charset) { + public void assertHasTextualContent(final AssertionInfo info, Path actual, String expected, Charset charset) { requireNonNull(expected, "The text to compare to should not be null"); assertIsReadable(info, actual); try { List> diffs = diff.diff(actual, expected, charset); - if (diffs.isEmpty()) return; - throw failures.failure(info, shouldHaveContent(actual, charset, diffs)); + if (!diffs.isEmpty()) throw failures.failure(info, shouldHaveContent(actual, charset, diffs)); } catch (IOException e) { throw new UncheckedIOException(format("Unable to verify text contents of path:<%s>", actual), e); } @@ -306,8 +246,7 @@ public void assertHasBinaryContent(AssertionInfo info, Path actual, byte[] expec assertIsReadable(info, actual); try { BinaryDiffResult diffResult = binaryDiff.diff(actual, expected); - if (diffResult.hasNoDiff()) return; - throw failures.failure(info, shouldHaveBinaryContent(actual, diffResult)); + if (!diffResult.hasNoDiff()) throw failures.failure(info, shouldHaveBinaryContent(actual, diffResult)); } catch (IOException e) { throw new UncheckedIOException(format("Unable to verify binary contents of path:<%s>", actual), e); } @@ -315,10 +254,9 @@ public void assertHasBinaryContent(AssertionInfo info, Path actual, byte[] expec public void assertHasSameBinaryContentAs(AssertionInfo info, Path actual, Path expected) { requireNonNull(expected, "The given Path to compare actual content to should not be null"); + checkArgument(Files.exists(expected), "The given Path <%s> to compare actual content to should exist", expected); + checkArgument(Files.isReadable(expected), "The given Path <%s> to compare actual content to should be readable", expected); assertIsReadable(info, actual); - checkArgument(nioFilesWrapper.exists(expected), "The given Path <%s> to compare actual content to should exist", expected); - checkArgument(nioFilesWrapper.isReadable(expected), "The given Path <%s> to compare actual content to should be readable", - expected); try { BinaryDiffResult binaryDiffResult = binaryDiff.diff(actual, readAllBytes(expected)); if (binaryDiffResult.hasDiff()) throw failures.failure(info, shouldHaveBinaryContent(actual, binaryDiffResult)); @@ -327,17 +265,15 @@ public void assertHasSameBinaryContentAs(AssertionInfo info, Path actual, Path e } } - public void assertHasSameContentAs(AssertionInfo info, Path actual, Charset actualCharset, Path expected, - Charset expectedCharset) { + public void assertHasSameTextualContentAs(AssertionInfo info, Path actual, Charset actualCharset, Path expected, + Charset expectedCharset) { requireNonNull(expected, "The given Path to compare actual content to should not be null"); - checkArgument(nioFilesWrapper.exists(expected), "The given Path <%s> to compare actual content to should exist", expected); - checkArgument(nioFilesWrapper.isReadable(expected), "The given Path <%s> to compare actual content to should be readable", - expected); + checkArgument(Files.exists(expected), "The given Path <%s> to compare actual content to should exist", expected); + checkArgument(Files.isReadable(expected), "The given Path <%s> to compare actual content to should be readable", expected); assertIsReadable(info, actual); try { List> diffs = diff.diff(actual, actualCharset, expected, expectedCharset); - if (diffs.isEmpty()) return; - throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs)); + if (!diffs.isEmpty()) throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs)); } catch (IOException e) { throw new UncheckedIOException(format(UNABLE_TO_COMPARE_PATH_CONTENTS, actual, expected), e); } @@ -416,7 +352,25 @@ public void assertIsEmptyDirectory(AssertionInfo info, Path actual) { public void assertIsNotEmptyDirectory(AssertionInfo info, Path actual) { boolean isEmptyDirectory = directoryContent(info, actual).isEmpty(); - if (isEmptyDirectory) throw failures.failure(info, shouldNotBeEmpty()); + if (isEmptyDirectory) throw failures.failure(info, shouldNotBeEmpty(actual)); + } + + public void assertIsEmptyFile(AssertionInfo info, Path actual) { + assertIsRegularFile(info, actual); + try { + if (nioFilesWrapper.size(actual) > 0) throw failures.failure(info, shouldBeEmpty(actual)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public void assertIsNotEmptyFile(AssertionInfo info, Path actual) { + assertIsRegularFile(info, actual); + try { + if (nioFilesWrapper.size(actual) == 0) throw failures.failure(info, shouldNotBeEmpty(actual)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } public static List toPathNames(List files) { @@ -508,21 +462,11 @@ private static void assertExpectedEndPathIsNotNull(final Path end) { requireNonNull(end, "the expected end path should not be null"); } - public void assertIsEmptyFile(AssertionInfo info, Path actual) { - assertIsRegularFile(info, actual); - try { - if (nioFilesWrapper.size(actual) > 0) throw failures.failure(info, shouldBeEmpty(actual)); - } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); - } - } - - public void assertIsNotEmptyFile(AssertionInfo info, Path actual) { - assertIsRegularFile(info, actual); + private static Path toRealPath(Path path) { try { - if (nioFilesWrapper.size(actual) == 0) throw failures.failure(info, shouldNotBeEmpty(actual)); + return path.toRealPath(); } catch (IOException e) { - throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); + throw new UncheckedIOException(e); } } diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_hasContent_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_hasContent_Test.java index 864b3224153..8e862ac5550 100644 --- a/src/test/java/org/assertj/core/api/path/PathAssert_hasContent_Test.java +++ b/src/test/java/org/assertj/core/api/path/PathAssert_hasContent_Test.java @@ -16,27 +16,17 @@ import org.assertj.core.api.PathAssert; import org.assertj.core.api.PathAssertBaseTest; -import org.junit.jupiter.api.BeforeAll; -/** - * Tests for {@link PathAssert#hasContent(String)}. - */ class PathAssert_hasContent_Test extends PathAssertBaseTest { - private static String expected; - - @BeforeAll - static void beforeOnce() { - expected = "xyz"; - } - @Override protected PathAssert invoke_api_method() { - return assertions.hasContent(expected); + return assertions.hasContent("xyz"); } @Override protected void verify_internal_effects() { - verify(paths).assertHasContent(getInfo(assertions), getActual(assertions), expected, getCharset(assertions)); + verify(paths).assertHasTextualContent(getInfo(assertions), getActual(assertions), "xyz", getCharset(assertions)); } + } diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_hasSameContentAs_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_hasSameContentAs_Test.java index 65b28529106..22820b330e4 100644 --- a/src/test/java/org/assertj/core/api/path/PathAssert_hasSameContentAs_Test.java +++ b/src/test/java/org/assertj/core/api/path/PathAssert_hasSameContentAs_Test.java @@ -42,7 +42,7 @@ protected PathAssert invoke_api_method() { @Override protected void verify_internal_effects() { - verify(paths).assertHasSameContentAs(getInfo(assertions), getActual(assertions), defaultCharset, expected, defaultCharset); + verify(paths).assertHasSameTextualContentAs(getInfo(assertions), getActual(assertions), defaultCharset, expected, defaultCharset); } } diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_hasSameTextualContentAs_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_hasSameTextualContentAs_Test.java index 29d40eb8cad..ddb5c4beaef 100644 --- a/src/test/java/org/assertj/core/api/path/PathAssert_hasSameTextualContentAs_Test.java +++ b/src/test/java/org/assertj/core/api/path/PathAssert_hasSameTextualContentAs_Test.java @@ -23,10 +23,8 @@ import org.assertj.core.api.PathAssert; import org.assertj.core.api.PathAssertBaseTest; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("PathAssert hasSameTextualContentAs") class PathAssert_hasSameTextualContentAs_Test extends PathAssertBaseTest { private static Path expected; @@ -43,7 +41,7 @@ protected PathAssert invoke_api_method() { @Override protected void verify_internal_effects() { - verify(paths).assertHasSameContentAs(getInfo(assertions), getActual(assertions), defaultCharset, expected, defaultCharset); + verify(paths).assertHasSameTextualContentAs(getInfo(assertions), getActual(assertions), defaultCharset, expected, defaultCharset); } @Test diff --git a/src/test/java/org/assertj/core/internal/PathsBaseTest.java b/src/test/java/org/assertj/core/internal/PathsBaseTest.java index 613874ca473..c75315231e2 100644 --- a/src/test/java/org/assertj/core/internal/PathsBaseTest.java +++ b/src/test/java/org/assertj/core/internal/PathsBaseTest.java @@ -23,6 +23,7 @@ import org.assertj.core.api.AssertionInfo; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; @@ -54,6 +55,9 @@ */ public abstract class PathsBaseTest { + @TempDir + protected Path tempDir; + protected Failures failures; protected Paths paths; protected NioFilesWrapper nioFilesWrapper; @@ -64,15 +68,16 @@ public abstract class PathsBaseTest { @BeforeEach public void setUp() { - failures = spy(new Failures()); - nioFilesWrapper = mock(NioFilesWrapper.class); - paths = new Paths(nioFilesWrapper); + paths = Paths.instance(); + nioFilesWrapper = spy(paths.nioFilesWrapper); + paths.nioFilesWrapper = nioFilesWrapper; + failures = spy(paths.failures); paths.failures = failures; - info = someInfo(); - diff = mock(Diff.class); + diff = spy(paths.diff); paths.diff = diff; - binaryDiff = mock(BinaryDiff.class); + binaryDiff = spy(paths.binaryDiff); paths.binaryDiff = binaryDiff; + info = someInfo(); } /** @@ -102,4 +107,4 @@ public void close() { } } } -} \ No newline at end of file +} diff --git a/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java b/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java deleted file mode 100644 index d61e50abb94..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/MockPathsBaseTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.assertj.core.test.TestData.someInfo; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.willAnswer; -import static org.mockito.Mockito.mock; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.DirectoryStream; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; -import java.util.Spliterators; -import java.util.function.Predicate; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.PathsBaseTest; -import org.assertj.core.util.Strings; -import org.junit.jupiter.api.BeforeEach; - -import com.google.common.collect.Iterators; -import org.junit.jupiter.api.io.TempDir; - -/** - * @deprecated favor tests based on {@link PathsBaseTest} and JUnit 5 {@link TempDir}. - */ -@Deprecated -public class MockPathsBaseTest extends PathsBaseTest { - - static final AssertionInfo INFO = someInfo(); - - Path actual; - Path other; - - @BeforeEach - public void init() { - actual = mock(Path.class); - other = mock(Path.class); - } - - static void failIfStreamIsOpen(InputStream stream) { - try { - assertThat(stream.read()).as("Stream should be closed").isNegative(); - } catch (IOException e) { - assertThat(e).hasNoCause().hasMessage("Stream closed"); - } - } - - static DirectoryStream directoryStream(List directoryItems) { - DirectoryStream stream = mock(DirectoryStream.class); - given(stream.iterator()).will(inv -> directoryItems.iterator()); - given(stream.spliterator()).will(inv -> Spliterators.spliteratorUnknownSize(directoryItems.iterator(), 0)); - return stream; - } - - private DirectoryStream filterStream(Predicate filter, DirectoryStream source) throws IOException { - DirectoryStream stream = mock(DirectoryStream.class); - given(stream.iterator()).will(inv -> Iterators.filter(source.iterator(), filter::test)); - given(stream.spliterator()).will(inv -> Spliterators.spliteratorUnknownSize(Iterators.filter(source.iterator(), filter::test), - 0)); - willAnswer(inv -> { - source.close(); - return null; - }).given(stream).close(); - return stream; - } - - static Path mockPath(String... names) { - Path path = mock(Path.class); - given(path.toString()).willReturn(Strings.join(names).with(File.separator)); - if (names.length > 1) { - Path filename = mockPath(names[names.length - 1]); - given(path.getFileName()).willReturn(filename); - given(path.getParent()).will(inv -> mockPath(Arrays.copyOf(names, names.length - 1))); - } else { - given(path.getFileName()).willReturn(path); - given(path.getParent()).willReturn(null); - } - given(path.getNameCount()).willReturn(names.length); - given(path.getName(anyInt())).will(inv -> names[(int) inv.getArgument(0)]); - return path; - } - - Path mockEmptyRegularFile(String... names) { - Path path = mockPath(names); - given(nioFilesWrapper.exists(path)).willReturn(true); - given(nioFilesWrapper.isRegularFile(path)).willReturn(true); - try { - given(nioFilesWrapper.newInputStream(path)).willReturn(new ByteArrayInputStream(new byte[0])); - } catch (IOException e) { - fail("Should not happen"); - } - return path; - } - - Path mockNonEmptyRegularFile(String... names) { - Path path = mockPath(names); - given(nioFilesWrapper.exists(path)).willReturn(true); - given(nioFilesWrapper.isRegularFile(path)).willReturn(true); - try { - given(nioFilesWrapper.size(path)).willReturn(1L); - given(nioFilesWrapper.newInputStream(path)).willReturn(new ByteArrayInputStream(new byte[1])); - } catch (IOException e) { - fail("Should not happen"); - } - return path; - } - - Path mockDirectory(String name, List paths) { - DirectoryStream directoryItems = directoryStream(paths); - Path path = mockPath(name); - given(nioFilesWrapper.exists(path)).willReturn(true); - given(nioFilesWrapper.isDirectory(path)).willReturn(true); - try { - given(nioFilesWrapper.newDirectoryStream(eq(path), any())).will(inv -> filterStream(inv.getArgument(1), directoryItems)); - } catch (IOException e) { - fail("Should not happen"); - } - return path; - } - -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWithRaw_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWithRaw_Test.java index 47a3e341b11..3c7d1625fd5 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWithRaw_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWithRaw_Test.java @@ -12,46 +12,85 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldEndWithPath.shouldEndWith; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertEndsWithRaw_Test extends MockPathsBaseTest { +class Paths_assertEndsWithRaw_Test extends PathsBaseTest { @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertEndsWithRaw(info, null, other)) - .withMessage(actualIsNull()); + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + Path other = tempDir.resolve("other"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertEndsWithRaw(info, null, other)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_other_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertEndsWithRaw(info, actual, null)) - .withMessage("the expected end path should not be null"); + void should_fail_if_other_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertEndsWithRaw(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("the expected end path should not be null"); } @Test - void should_fail_if_actual_does_not_end_with_other() { - // This is the default, but let's make this explicit - when(actual.endsWith(other)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertEndsWithRaw(info, actual, other)); + void should_fail_if_actual_does_not_end_with_other() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = tempDir.resolve("other"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertEndsWithRaw(info, actual, other)); + // THEN + then(error).hasMessage(shouldEndWith(actual, other).create()); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldEndWith(actual, other)); + @Test + void should_pass_if_actual_ends_with_other() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = Paths.get("actual"); + // WHEN/THEN + paths.assertEndsWithRaw(info, actual, other); } @Test - void should_succeed_if_actual_ends_with_other() { - when(actual.endsWith(other)).thenReturn(true); + void should_fail_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path file = createFile(tempDir.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + Path other = Paths.get("file"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertEndsWithRaw(info, actual, other)); + // THEN + then(error).hasMessage(shouldEndWith(actual, other).create()); + } - paths.assertEndsWithRaw(info, actual, other); + @Test + void should_fail_if_other_is_not_normalized() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = Paths.get("actual", "..", "actual", "."); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertEndsWithRaw(info, actual, other)); + // THEN + then(error).hasMessage(shouldEndWith(actual, other).create()); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWith_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWith_Test.java index 99e9340f4bf..8b5055429e5 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWith_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWith_Test.java @@ -12,74 +12,98 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldEndWithPath.shouldEndWith; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; +import java.nio.file.Paths; -import org.assertj.core.api.exception.PathsException; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertEndsWith_Test extends MockPathsBaseTest { +class Paths_assertEndsWith_Test extends PathsBaseTest { @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertEndsWith(info, null, other)) - .withMessage(actualIsNull()); + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + Path other = tempDir.resolve("other"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertEndsWith(info, null, other)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_other_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertEndsWith(info, actual, null)) - .withMessage("the expected end path should not be null"); + void should_fail_if_other_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertEndsWith(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("the expected end path should not be null"); } @Test - void should_fail_with_PathsException_if_actual_cannot_be_resolved() throws IOException { - final IOException causeException = new IOException(); - when(actual.toRealPath()).thenThrow(causeException); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertEndsWith(info, actual, other)) - .withMessage("failed to resolve actual real path") - .withCause(causeException); + void should_rethrow_IOException_as_UncheckedIOException_if_actual_cannot_be_resolved() throws IOException { + // GIVEN + Path actual = mock(Path.class); + Path other = tempDir.resolve("other"); + IOException exception = new IOException("boom!"); + given(actual.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertEndsWith(info, actual, other)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test - void should_fail_if_canonical_actual_does_not_end_with_normalized_other() throws IOException { - final Path canonicalActual = mock(Path.class); - final Path normalizedOther = mock(Path.class); - - when(actual.toRealPath()).thenReturn(canonicalActual); - when(other.normalize()).thenReturn(normalizedOther); - - // This is the default, but... - when(canonicalActual.endsWith(normalizedOther)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertEndsWith(info, actual, other)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldEndWith(actual, other)); + void should_fail_if_actual_does_not_end_with_other() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = tempDir.resolve("other"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertEndsWith(info, actual, other)); + // THEN + then(error).hasMessage(shouldEndWith(actual, other).create()); } @Test - void should_succeed_if_canonical_actual_ends_with_normalized_other() throws IOException { - final Path canonicalActual = mock(Path.class); - final Path normalizedOther = mock(Path.class); - - when(actual.toRealPath()).thenReturn(canonicalActual); - when(other.normalize()).thenReturn(normalizedOther); + void should_pass_if_actual_ends_with_other() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = Paths.get("actual"); + // WHEN/THEN + paths.assertEndsWith(info, actual, other); + } - // We want the canonical versions to be compared, not the arguments - when(canonicalActual.endsWith(normalizedOther)).thenReturn(true); + @Test + void should_pass_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path file = createFile(tempDir.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + Path other = Paths.get("file"); + // WHEN/THEN + paths.assertEndsWith(info, actual, other); + } + @Test + void should_pass_if_other_is_not_normalized() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = Paths.get("actual", "..", "actual", "."); + // WHEN/THEN paths.assertEndsWith(info, actual, other); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertExistsNoFollowLinks_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertExistsNoFollowLinks_Test.java index 6ebced7965e..38971f0ee73 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertExistsNoFollowLinks_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertExistsNoFollowLinks_Test.java @@ -12,39 +12,62 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldExist.shouldExistNoFollowLinks; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.nio.file.LinkOption; +import java.io.IOException; +import java.nio.file.Path; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertExistsNoFollowLinks_Test extends MockPathsBaseTest { +class Paths_assertExistsNoFollowLinks_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertExistsNoFollowLinks(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertExistsNoFollowLinks(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual, LinkOption.NOFOLLOW_LINKS)).thenReturn(false); + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertExistsNoFollowLinks(info, actual)); + // THEN + then(error).hasMessage(shouldExistNoFollowLinks(actual).create()); + } - Throwable error = catchThrowable(() -> paths.assertExistsNoFollowLinks(info, actual)); + @Test + void should_pass_if_actual_exists() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN/THEN + paths.assertExistsNoFollowLinks(info, actual); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExistNoFollowLinks(actual)); + @Test + void should_pass_if_actual_is_a_symbolic_link_and_target_exists() throws IOException { + // GIVEN + Path target = createFile(tempDir.resolve("target")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), target); + // WHEN/THEN + paths.assertExistsNoFollowLinks(info, actual); } @Test - void should_pass_if_actual_exists() { - when(nioFilesWrapper.exists(actual, LinkOption.NOFOLLOW_LINKS)).thenReturn(true); + void should_pass_if_actual_is_a_symbolic_link_and_target_does_not_exist() throws IOException { + // GIVEN + Path target = tempDir.resolve("non-existent"); + Path actual = createSymbolicLink(tempDir.resolve("actual"), target); + // WHEN/THEN paths.assertExistsNoFollowLinks(info, actual); } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertExists_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertExists_Test.java index 90048fcd585..fd08291a685 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertExists_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertExists_Test.java @@ -12,38 +12,65 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertExists_Test extends MockPathsBaseTest { +class Paths_assertExists_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertExists(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertExists(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertExists(info, actual)); + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertExists(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(actual)); + @Test + void should_pass_if_actual_exists() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN/THEN + paths.assertExists(info, actual); } @Test - void should_pass_if_actual_exists() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); + void should_pass_if_actual_is_a_symbolic_link_and_target_exists() throws IOException { + // GIVEN + Path target = createFile(tempDir.resolve("target")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), target); + // WHEN/THEN paths.assertExists(info, actual); } + @Test + void should_fail_if_actual_is_a_symbolic_link_and_target_does_not_exist() throws IOException { + // GIVEN + Path target = tempDir.resolve("non-existent"); + Path actual = createSymbolicLink(tempDir.resolve("actual"), target); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertExists(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java index 3279b1a0ae5..cc37542e406 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java @@ -12,120 +12,109 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static java.nio.file.Files.createFile; import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.error.ShouldHaveBinaryContent.shouldHaveBinaryContent; -import static org.assertj.core.internal.BinaryDiffResult.noDiff; -import static org.assertj.core.test.TestData.someInfo; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; -import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; +import java.nio.file.Files; import java.nio.file.Path; -import org.assertj.core.api.AssertionInfo; import org.assertj.core.internal.BinaryDiffResult; -import org.assertj.core.internal.Paths; import org.assertj.core.internal.PathsBaseTest; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; -/** - * Tests for {@link Paths#assertHasBinaryContent(AssertionInfo, Path, byte[])}. - */ class Paths_assertHasBinaryContent_Test extends PathsBaseTest { - private static Path path; - private static byte[] expected; - private Path mockPath; - - @BeforeAll - static void setUpOnce() { - // Does not matter if the values binaryDiffer, the actual comparison is mocked in this test - path = new File("src/test/resources/actual_file.txt").toPath(); - expected = new byte[] { 0, 1 }; - } - - @BeforeEach - void init() { - mockPath = mock(Path.class); - } - @Test - void should_pass_if_path_has_expected_text_content() throws IOException { - when(binaryDiff.diff(path, expected)).thenReturn(noDiff()); - when(nioFilesWrapper.exists(path)).thenReturn(true); - when(nioFilesWrapper.isReadable(path)).thenReturn(true); - paths.assertHasBinaryContent(someInfo(), path, expected); + void should_fail_if_expected_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasBinaryContent(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The binary content to compare to should not be null"); } @Test - void should_throw_error_if_expected_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasBinaryContent(someInfo(), path, null)) - .withMessage("The binary content to compare to should not be null"); + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + byte[] expected = "expected".getBytes(); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasBinaryContent(info, null, expected)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasBinaryContent(someInfo(), null, expected)) - .withMessage(actualIsNull()); + void should_fail_if_actual_does_not_exist() throws IOException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + byte[] expected = "expected".getBytes(); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasBinaryContent(info, actual, expected)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_path_does_not_exist() { - AssertionInfo info = someInfo(); - when(nioFilesWrapper.exists(mockPath)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertHasBinaryContent(info, mockPath, expected)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(mockPath)); + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + byte[] expected = "expected".getBytes(); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasBinaryContent(info, actual, expected)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); } @Test - void should_fail_if_actual_is_not_a_readable_file() { - AssertionInfo info = someInfo(); - when(nioFilesWrapper.exists(mockPath)).thenReturn(true); - when(nioFilesWrapper.isReadable(mockPath)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertHasBinaryContent(info, mockPath, expected)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeReadable(mockPath)); + void should_pass_if_actual_has_expected_binary_content() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + byte[] expected = "Content".getBytes(); + // WHEN/THEN + paths.assertHasBinaryContent(info, actual, expected); } @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - IOException cause = new IOException(); - when(binaryDiff.diff(path, expected)).thenThrow(cause); - when(nioFilesWrapper.exists(path)).thenReturn(true); - when(nioFilesWrapper.isReadable(path)).thenReturn(true); - - assertThatExceptionOfType(UncheckedIOException.class).isThrownBy(() -> paths.assertHasBinaryContent(someInfo(), - path, expected)) - .withCause(cause); + void should_fail_if_actual_does_not_have_expected_binary_content() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + byte[] expected = "Another content".getBytes(); + BinaryDiffResult diff = binaryDiff.diff(actual, expected); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasBinaryContent(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveBinaryContent(actual, diff).create(info.description(), info.representation())); } @Test - void should_fail_if_path_does_not_have_expected_binary_content() throws IOException { - BinaryDiffResult binaryDiffs = new BinaryDiffResult(15, (byte) 0xCA, (byte) 0xFE); - when(binaryDiff.diff(path, expected)).thenReturn(binaryDiffs); - when(nioFilesWrapper.exists(path)).thenReturn(true); - when(nioFilesWrapper.isReadable(path)).thenReturn(true); - AssertionInfo info = someInfo(); - - Throwable error = catchThrowable(() -> paths.assertHasBinaryContent(info, path, expected)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveBinaryContent(path, binaryDiffs)); + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + byte[] expected = "expected".getBytes(); + IOException exception = new IOException("boom!"); + given(binaryDiff.diff(actual, expected)).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasBinaryContent(info, actual, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasMessage("Unable to verify binary contents of path:<%s>", actual) + .hasCause(exception); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasContent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasContent_Test.java deleted file mode 100644 index c88afae1780..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasContent_Test.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldHaveContent.shouldHaveContent; -import static org.assertj.core.test.TestData.someInfo; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.newArrayList; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; -import org.assertj.core.internal.PathsBaseTest; -import org.assertj.core.util.diff.Delta; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertHasContent(AssertionInfo, Path, String, Charset)}. - * - * @author Olivier Michallat - * @author Joel Costigliola - */ -class Paths_assertHasContent_Test extends PathsBaseTest { - - private static Path path; - private static String expected; - private static Charset charset; - private Path mockPath; - - @BeforeAll - static void setUpOnce() { - // Does not matter if the values differ, the actual comparison is mocked in this test - path = new File("src/test/resources/actual_file.txt").toPath(); - expected = "xyz"; - charset = Charset.defaultCharset(); - } - - @BeforeEach - void init() { - mockPath = mock(Path.class); - } - - @Test - void should_pass_if_path_has_expected_text_content() throws IOException { - when(diff.diff(path, expected, charset)).thenReturn(new ArrayList<>()); - when(nioFilesWrapper.exists(path)).thenReturn(true); - when(nioFilesWrapper.isReadable(path)).thenReturn(true); - paths.assertHasContent(someInfo(), path, expected, charset); - } - - @Test - void should_throw_error_if_expected_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasContent(someInfo(), path, null, charset)) - .withMessage("The text to compare to should not be null"); - } - - @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasContent(someInfo(), null, expected, charset)) - .withMessage(actualIsNull()); - } - - @Test - void should_fail_if_actual_path_does_not_exist() { - AssertionInfo info = someInfo(); - when(nioFilesWrapper.exists(mockPath)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertHasContent(info, mockPath, expected, charset)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(mockPath)); - } - - @Test - void should_fail_if_actual_is_not_a_readable_file() { - AssertionInfo info = someInfo(); - when(nioFilesWrapper.exists(mockPath)).thenReturn(true); - when(nioFilesWrapper.isReadable(mockPath)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertHasContent(info, mockPath, expected, charset)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeReadable(mockPath)); - } - - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - IOException cause = new IOException(); - when(diff.diff(path, expected, charset)).thenThrow(cause); - when(nioFilesWrapper.exists(path)).thenReturn(true); - when(nioFilesWrapper.isReadable(path)).thenReturn(true); - - assertThatExceptionOfType(UncheckedIOException.class).isThrownBy(() -> paths.assertHasContent(someInfo(), path, - expected, charset)) - .withCause(cause); - } - - @Test - void should_fail_if_path_does_not_have_expected_text_content() throws IOException { - List> diffs = newArrayList((Delta) mock(Delta.class)); - when(diff.diff(path, expected, charset)).thenReturn(diffs); - when(nioFilesWrapper.exists(path)).thenReturn(true); - when(nioFilesWrapper.isReadable(path)).thenReturn(true); - AssertionInfo info = someInfo(); - - Throwable error = catchThrowable(() -> paths.assertHasContent(info, path, expected, charset)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveContent(path, charset, diffs)); - } -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmBytes_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmBytes_Test.java deleted file mode 100644 index cf0625faf64..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmBytes_Test.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; -import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.DigestDiff; -import org.assertj.core.internal.Digests; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertHasDigest(AssertionInfo, Path, String, byte[])} - * - * @author Valeriy Vyrva - */ -class Paths_assertHasDigest_AlgorithmBytes_Test extends MockPathsBaseTest { - private final String algorithm = "MD5"; - private final byte[] expected = new byte[0]; - private final String real = "3AC1AFA2A89B7E4F1866502877BF1DC5"; - - @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasDigest(info, null, algorithm, expected)) - .withMessage(actualIsNull()); - } - - @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_file() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldBeRegularFile(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_readable() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldBeReadable(actual)); - } - - @Test - void should_throw_error_if_digest_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, (MessageDigest) null, expected)) - .withMessage("The message digest algorithm should not be null"); - } - - @Test - void should_throw_error_if_expected_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, algorithm, (byte[]) null)) - .withMessage("The binary representation of digest to compare to should not be null"); - } - - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_throw_error_wrapping_caught_NoSuchAlgorithmException() { - // GIVEN - String unknownDigestAlgorithm = "UnknownDigestAlgorithm"; - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, unknownDigestAlgorithm, expected)); - // THEN - assertThat(error).isInstanceOf(IllegalStateException.class) - .hasMessage("Unable to find digest implementation for: "); - } - - @Test - void should_fail_if_actual_does_not_have_expected_digest() throws IOException, NoSuchAlgorithmException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldHaveDigest(actual, new DigestDiff(real, "", MessageDigest.getInstance(algorithm)))); - failIfStreamIsOpen(stream); - } - - @Test - void should_pass_if_actual_has_expected_digest() throws IOException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - // WHEN - paths.assertHasDigest(INFO, actual, algorithm, Digests.fromHex(real)); - // THEN - failIfStreamIsOpen(stream); - } -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmString_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmString_Test.java deleted file mode 100644 index b12bcb14800..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_AlgorithmString_Test.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; -import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.DigestDiff; -import org.assertj.core.internal.Digests; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertHasDigest(AssertionInfo, Path, String, String)} - * - * @author Valeriy Vyrva - */ -class Paths_assertHasDigest_AlgorithmString_Test extends MockPathsBaseTest { - private final String algorithm = "MD5"; - private final String expected = ""; - private final String real = "3AC1AFA2A89B7E4F1866502877BF1DC5"; - - @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasDigest(info, null, algorithm, expected)) - .withMessage(actualIsNull()); - } - - @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_file() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldBeRegularFile(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_readable() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldBeReadable(actual)); - } - - @Test - void should_throw_error_if_digest_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, (MessageDigest) null, expected)) - .withMessage("The message digest algorithm should not be null"); - } - - @Test - void should_throw_error_if_expected_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, algorithm, (byte[]) null)) - .withMessage("The binary representation of digest to compare to should not be null"); - } - - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_throw_error_wrapping_caught_NoSuchAlgorithmException() { - // GIVEN - String unknownDigestAlgorithm = "UnknownDigestAlgorithm"; - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, unknownDigestAlgorithm, expected)); - // THEN - assertThat(error).isInstanceOf(IllegalStateException.class) - .hasMessage("Unable to find digest implementation for: "); - } - - @Test - void should_fail_if_actual_does_not_have_expected_digest() throws IOException, NoSuchAlgorithmException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, algorithm, expected)); - // THEN - verify(failures).failure(INFO, shouldHaveDigest(actual, new DigestDiff(real, "", MessageDigest.getInstance(algorithm)))); - failIfStreamIsOpen(stream); - } - - @Test - void should_pass_if_actual_has_expected_digest() throws IOException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - // WHEN - paths.assertHasDigest(INFO, actual, algorithm, Digests.fromHex(real)); - // THEN - failIfStreamIsOpen(stream); - } -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestBytes_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestBytes_Test.java deleted file mode 100644 index 91705abeada..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestBytes_Test.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; -import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.security.MessageDigest; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.DigestDiff; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertHasDigest(AssertionInfo, Path, MessageDigest, byte[])} - * - * @author Valeriy Vyrva - */ -class Paths_assertHasDigest_DigestBytes_Test extends MockPathsBaseTest { - private final MessageDigest digest = mock(MessageDigest.class); - private final byte[] expected = new byte[0]; - - @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasDigest(info, null, digest, expected)) - .withMessage(actualIsNull()); - } - - @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_file() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldBeRegularFile(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_readable() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldBeReadable(actual)); - } - - @Test - void should_throw_error_if_digest_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, (MessageDigest) null, expected)) - .withMessage("The message digest algorithm should not be null"); - } - - @Test - void should_throw_error_if_expected_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, digest, (byte[]) null)) - .withMessage("The binary representation of digest to compare to should not be null"); - } - - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_throw_error_wrapping_caught_NoSuchAlgorithmException() { - // GIVEN - String unknownDigestAlgorithm = "UnknownDigestAlgorithm"; - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, unknownDigestAlgorithm, expected)); - // THEN - assertThat(error).isInstanceOf(IllegalStateException.class) - .hasMessage("Unable to find digest implementation for: "); - } - - @Test - void should_fail_if_actual_does_not_have_expected_digest() throws IOException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - given(digest.digest()).willReturn(new byte[] { 0, 1 }); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldHaveDigest(actual, new DigestDiff("0001", "", digest))); - failIfStreamIsOpen(stream); - } - - @Test - void should_pass_if_actual_has_expected_digest() throws IOException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - given(digest.digest()).willReturn(expected); - // WHEN - paths.assertHasDigest(INFO, actual, digest, expected); - // THEN - failIfStreamIsOpen(stream); - } -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestString_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestString_Test.java deleted file mode 100644 index 7f26ea4207d..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_DigestString_Test.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; -import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.security.MessageDigest; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.DigestDiff; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertHasDigest(AssertionInfo, Path, MessageDigest, String)} - * - * @author Valeriy Vyrva - */ -class Paths_assertHasDigest_DigestString_Test extends MockPathsBaseTest { - private final MessageDigest digest = mock(MessageDigest.class); - private final String expected = ""; - - @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_file() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldBeRegularFile(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_readable() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(false); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldBeReadable(actual)); - } - - @Test - void should_throw_error_if_digest_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, (MessageDigest) null, expected)) - .withMessage("The message digest algorithm should not be null"); - } - - @Test - void should_throw_error_if_expected_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasDigest(INFO, null, digest, (byte[]) null)) - .withMessage("The binary representation of digest to compare to should not be null"); - } - - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_throw_error_wrapping_caught_NoSuchAlgorithmException() { - // GIVEN - String unknownDigestAlgorithm = "UnknownDigestAlgorithm"; - // WHEN - Throwable error = catchThrowable(() -> paths.assertHasDigest(INFO, actual, unknownDigestAlgorithm, expected)); - // THEN - assertThat(error).isInstanceOf(IllegalStateException.class) - .hasMessage("Unable to find digest implementation for: "); - } - - @Test - void should_fail_if_actual_does_not_have_expected_digest() throws IOException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - given(digest.digest()).willReturn(new byte[] { 0, 1 }); - // WHEN - catchThrowable(() -> paths.assertHasDigest(INFO, actual, digest, expected)); - // THEN - verify(failures).failure(INFO, shouldHaveDigest(actual, new DigestDiff("0001", "", digest))); - failIfStreamIsOpen(stream); - } - - @Test - void should_pass_if_actual_has_expected_digest() throws IOException { - // GIVEN - InputStream stream = getClass().getResourceAsStream("/red.png"); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.newInputStream(actual)).willReturn(stream); - given(digest.digest()).willReturn(expected.getBytes()); - // WHEN - paths.assertHasDigest(INFO, actual, digest, expected); - // THEN - failIfStreamIsOpen(stream); - } -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java new file mode 100644 index 00000000000..cb8ac785405 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java @@ -0,0 +1,163 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.readAllBytes; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; +import static org.assertj.core.internal.Digests.toHex; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.assertj.core.internal.DigestDiff; +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test extends PathsBaseTest { + + @Test + void should_fail_if_digest_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + MessageDigest digest = null; + byte[] expected = {}; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The message digest algorithm should not be null"); + } + + @Test + void should_fail_if_expected_is_null() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The binary representation of digest to compare to should not be null"); + } + + @Test + void should_fail_if_actual_is_null() throws NoSuchAlgorithmException { + // GIVEN + Path actual = null; + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() throws NoSuchAlgorithmException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_regular_file() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = {}; + IOException cause = new IOException("boom!"); + given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_fail_if_actual_does_not_have_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = digest.digest("Another content".getBytes()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldHaveDigest(actual, new DigestDiff(toHex(digest.digest(readAllBytes(actual))), + toHex(expected), + digest)).create()); + } + + @Test + void should_pass_if_actual_has_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + MessageDigest digest = MessageDigest.getInstance("MD5"); + byte[] expected = digest.digest(readAllBytes(actual)); + // WHEN/THEN + paths.assertHasDigest(info, actual, digest, expected); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java new file mode 100644 index 00000000000..8037ac36ebd --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java @@ -0,0 +1,163 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.readAllBytes; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; +import static org.assertj.core.internal.Digests.toHex; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.assertj.core.internal.DigestDiff; +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertHasDigest_with_MessageDigest_and_String_Test extends PathsBaseTest { + + @Test + void should_fail_if_digest_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + MessageDigest digest = null; + String expected = ""; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The message digest algorithm should not be null"); + } + + @Test + void should_fail_if_expected_is_null() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The string representation of digest to compare to should not be null"); + } + + @Test + void should_fail_if_actual_is_null() throws NoSuchAlgorithmException { + // GIVEN + Path actual = null; + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() throws NoSuchAlgorithmException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_regular_file() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = ""; + IOException cause = new IOException("boom!"); + given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_fail_if_actual_does_not_have_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = toHex(digest.digest("Another content".getBytes())); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, digest, expected)); + // THEN + then(error).hasMessage(shouldHaveDigest(actual, new DigestDiff(toHex(digest.digest(readAllBytes(actual))), + expected, + digest)).create()); + } + + @Test + void should_pass_if_actual_has_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + MessageDigest digest = MessageDigest.getInstance("MD5"); + String expected = toHex(digest.digest(readAllBytes(actual))); + // WHEN/THEN + paths.assertHasDigest(info, actual, digest, expected); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java new file mode 100644 index 00000000000..46722a9c595 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java @@ -0,0 +1,178 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.readAllBytes; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; +import static org.assertj.core.internal.Digests.toHex; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.assertj.core.internal.DigestDiff; +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertHasDigest_with_String_and_Byte_array_Test extends PathsBaseTest { + + @Test + void should_fail_if_algorithm_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = null; + byte[] expected = {}; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The message digest algorithm should not be null"); + } + + @Test + void should_fail_if_algorithm_is_invalid() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = "invalid"; + byte[] expected = {}; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(IllegalStateException.class) + .hasMessage("Unable to find digest implementation for: ") + .hasCauseInstanceOf(NoSuchAlgorithmException.class); + } + + @Test + void should_fail_if_expected_is_null() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = "MD5"; + byte[] expected = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The binary representation of digest to compare to should not be null"); + } + + @Test + void should_fail_if_actual_is_null() throws NoSuchAlgorithmException { + // GIVEN + Path actual = null; + String algorithm = "MD5"; + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() throws NoSuchAlgorithmException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + String algorithm = "MD5"; + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_regular_file() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + String algorithm = "MD5"; + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + String algorithm = "MD5"; + byte[] expected = {}; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = "MD5"; + byte[] expected = {}; + IOException cause = new IOException("boom!"); + given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_fail_if_actual_does_not_have_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + String algorithm = "MD5"; + MessageDigest digest = MessageDigest.getInstance(algorithm); + byte[] expected = digest.digest("Another content".getBytes()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldHaveDigest(actual, new DigestDiff(toHex(digest.digest(readAllBytes(actual))), + toHex(expected), + digest)).create()); + } + + @Test + void should_pass_if_actual_has_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + String algorithm = "MD5"; + byte[] expected = MessageDigest.getInstance(algorithm).digest(readAllBytes(actual)); + // WHEN/THEN + paths.assertHasDigest(info, actual, algorithm, expected); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java new file mode 100644 index 00000000000..c7f207c03f0 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java @@ -0,0 +1,178 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.readAllBytes; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; +import static org.assertj.core.internal.Digests.toHex; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.assertj.core.internal.DigestDiff; +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertHasDigest_with_String_and_String_Test extends PathsBaseTest { + + @Test + void should_fail_if_algorithm_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = null; + String expected = ""; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The message digest algorithm should not be null"); + } + + @Test + void should_fail_if_algorithm_is_invalid() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = "invalid"; + String expected = ""; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(IllegalStateException.class) + .hasMessage("Unable to find digest implementation for: ") + .hasCauseInstanceOf(NoSuchAlgorithmException.class); + } + + @Test + void should_fail_if_expected_is_null() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = "MD5"; + String expected = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The string representation of digest to compare to should not be null"); + } + + @Test + void should_fail_if_actual_is_null() throws NoSuchAlgorithmException { + // GIVEN + Path actual = null; + String algorithm = "MD5"; + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() throws NoSuchAlgorithmException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + String algorithm = "MD5"; + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_regular_file() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + String algorithm = "MD5"; + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + String algorithm = "MD5"; + String expected = ""; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String algorithm = "MD5"; + String expected = ""; + IOException cause = new IOException("boom!"); + given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_fail_if_actual_does_not_have_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + String algorithm = "MD5"; + MessageDigest digest = MessageDigest.getInstance(algorithm); + String expected = toHex(digest.digest("Another content".getBytes())); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasDigest(info, actual, algorithm, expected)); + // THEN + then(error).hasMessage(shouldHaveDigest(actual, new DigestDiff(toHex(digest.digest(readAllBytes(actual))), + expected, + digest)).create()); + } + + @Test + void should_pass_if_actual_has_expected_digest() throws Exception { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + String algorithm = "MD5"; + String expected = toHex(MessageDigest.getInstance(algorithm).digest(readAllBytes(actual))); + // WHEN/THEN + paths.assertHasDigest(info, actual, algorithm, expected); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java index ae80e27b8bc..b668ee3f6ca 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java @@ -12,13 +12,15 @@ */ package org.assertj.core.internal.paths; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.util.FailureMessages.actualIsNull; import java.io.IOException; import java.nio.file.FileSystem; -import java.nio.file.Files; import java.nio.file.Path; import org.assertj.core.internal.PathsBaseTest; @@ -44,18 +46,18 @@ static void initPaths() throws IOException { existingDirectory = fs.getPath("/dir1/dir2"); symlinkToExistingDirectory = fs.getPath("/symlinkToExistingDirectory"); - Files.createDirectory(fs.getPath("/dir1")); - Files.createDirectory(existingDirectory); - Files.createSymbolicLink(symlinkToExistingDirectory, existingDirectory); + createDirectory(fs.getPath("/dir1")); + createDirectory(existingDirectory); + createSymbolicLink(symlinkToExistingDirectory, existingDirectory); existingFile = fs.getPath("/dir1/dir2/gc.log"); symlinkToExistingFile = fs.getPath("/dir1/good-symlink"); - Files.createFile(existingFile); - Files.createSymbolicLink(symlinkToExistingFile, existingFile); + createFile(existingFile); + createSymbolicLink(symlinkToExistingFile, existingFile); nonExistingPath = fs.getPath("/dir1/fake.log"); symlinkToNonExistingPath = fs.getPath("/dir1/bad-symlink"); - Files.createSymbolicLink(symlinkToNonExistingPath, nonExistingPath); + createSymbolicLink(symlinkToNonExistingPath, nonExistingPath); } @AfterAll diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParentRaw_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParentRaw_Test.java index 376f39640f0..9d70be9e895 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParentRaw_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParentRaw_Test.java @@ -12,43 +12,56 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveNoParent.shouldHaveNoParent; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; import java.nio.file.Path; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertHasNoParentRaw_Test extends MockPathsBaseTest { +class Paths_assertHasNoParentRaw_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasNoParentRaw(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoParentRaw(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_has_parent() { - final Path parent = mock(Path.class); - when(actual.getParent()).thenReturn(parent); - - Throwable error = catchThrowable(() -> paths.assertHasNoParentRaw(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveNoParent(actual)); + void should_fail_if_actual_has_parent() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoParentRaw(info, actual)); + // THEN + then(error).hasMessage(shouldHaveNoParent(actual).create()); } @Test - void should_succeed_if_actual_has_no_parent() { - // This is the default, but let's make that clear - when(actual.getParent()).thenReturn(null); - + void should_pass_if_actual_has_no_parent() { + // GIVEN + Path actual = tempDir.getRoot(); + // WHEN/THEN paths.assertHasNoParentRaw(info, actual); } + + @Test + void should_fail_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path root = tempDir.getRoot(); + Path actual = createSymbolicLink(tempDir.resolve("actual"), root); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoParentRaw(info, actual)); + // THEN + then(error).hasMessage(shouldHaveNoParent(actual).create()); + } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParent_Test.java index 5e3e793fac8..2653dce0ad2 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParent_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParent_Test.java @@ -12,59 +12,71 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveNoParent.shouldHaveNoParent; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; -import org.assertj.core.api.exception.PathsException; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertHasNoParent_Test extends MockPathsBaseTest { +class Paths_assertHasNoParent_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasNoParent(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoParent(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_throw_PathsException_if_actual_cannot_be_canonicalized() throws IOException { - final IOException exception = new IOException(); - when(actual.toRealPath()).thenThrow(exception); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertHasNoParent(info, actual)) - .withMessage("failed to resolve actual real path") - .withCause(exception); + void should_rethrow_IOException_as_UncheckedIOException_if_actual_cannot_be_resolved() throws IOException { + // GIVEN + Path actual = mock(Path.class); + IOException exception = new IOException("boom!"); + given(actual.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasNoParent(info, actual)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test void should_fail_if_actual_has_parent() throws IOException { - final Path canonicalActual = mock(Path.class); - final Path parent = mock(Path.class); - when(actual.toRealPath()).thenReturn(canonicalActual); - when(canonicalActual.getParent()).thenReturn(parent); - - Throwable error = catchThrowable(() -> paths.assertHasNoParent(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveNoParent(actual)); + // GIVEN + Path actual = createFile(tempDir.resolve("actual")).toRealPath(); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoParent(info, actual)); + // THEN + then(error).hasMessage(shouldHaveNoParent(actual).create()); } @Test - void should_succeed_if_actual_has_no_parent() throws IOException { - final Path canonicalActual = mock(Path.class); - when(actual.toRealPath()).thenReturn(canonicalActual); - // This is the default, but let's make that clear - when(canonicalActual.getParent()).thenReturn(null); + void should_pass_if_actual_has_no_parent() { + // GIVEN + Path actual = tempDir.getRoot(); + // WHEN/THEN + paths.assertHasNoParent(info, actual); + } + @Test + void should_pass_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path root = tempDir.getRoot(); + Path actual = createSymbolicLink(tempDir.resolve("actual"), root); + // WHEN/THEN paths.assertHasNoParent(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParentRaw_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParentRaw_Test.java index fbf22a5f322..5c72b2742c7 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParentRaw_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParentRaw_Test.java @@ -12,70 +12,97 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveParent.shouldHaveParent; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; import java.nio.file.Path; -import org.junit.jupiter.api.BeforeEach; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertHasParentRaw_Test extends MockPathsBaseTest { - - private Path expectedParent; - - @Override - @BeforeEach - public void init() { - super.init(); - expectedParent = mock(Path.class); - } +class Paths_assertHasParentRaw_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasParentRaw(info, null, expectedParent)) - .withMessage(actualIsNull()); + // GIVEN + Path expected = tempDir.resolve("expected"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParentRaw(info, null, expected)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_provided_parent_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasParentRaw(info, actual, null)) - .withMessage("expected parent path should not be null"); + void should_fail_if_expected_is_null() { + // GIVEN + Path actual = tempDir.resolve("actual"); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasParentRaw(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("expected parent path should not be null"); } @Test void should_fail_if_actual_has_no_parent() { - // This is the default, but... - when(actual.getParent()).thenReturn(null); - - Throwable error = catchThrowable(() -> paths.assertHasParentRaw(info, actual, expectedParent)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveParent(actual, expectedParent)); + // GIVEN + Path actual = tempDir.getRoot(); + Path expected = tempDir.resolve("expected"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParentRaw(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveParent(actual, expected).create()); } @Test - void should_fail_if_actual_parent_is_not_expected_parent() { - final Path actualParent = mock(Path.class); - when(actual.getParent()).thenReturn(actualParent); - - Throwable error = catchThrowable(() -> paths.assertHasParentRaw(info, actual, expectedParent)); + void should_fail_if_actual_parent_is_not_expected_parent() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path expected = createFile(tempDir.resolve("expected")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParentRaw(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveParent(actual, actual.getParent(), expected).create()); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveParent(actual, actualParent, expectedParent)); + @Test + void should_pass_if_actual_has_expected_parent() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path expected = tempDir; + // WHEN + paths.assertHasParentRaw(info, actual, expected); } @Test - void should_succeed_if_parent_is_expected_parent() { - when(actual.getParent()).thenReturn(expectedParent); + void should_fail_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path expected = createDirectory(tempDir.resolve("expected")); + Path file = createFile(expected.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParentRaw(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveParent(actual, actual.getParent(), expected).create()); + } - paths.assertHasParentRaw(info, actual, expectedParent); + @Test + void should_fail_if_expected_is_not_canonical() throws IOException { + // GIVEN + Path directory = createDirectory(tempDir.resolve("directory")); + Path expected = createSymbolicLink(tempDir.resolve("expected"), directory); + Path actual = createFile(directory.resolve("actual")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParentRaw(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveParent(actual, actual.getParent(), expected).create()); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParent_Test.java index f8179142466..aa88b0143c7 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParent_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParent_Test.java @@ -12,108 +12,124 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveParent.shouldHaveParent; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; -import org.assertj.core.api.exception.PathsException; -import org.junit.jupiter.api.BeforeEach; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertHasParent_Test extends MockPathsBaseTest { - - private Path canonicalActual; - private Path expected; - private Path canonicalExpected; - - @Override - @BeforeEach - public void init() { - super.init(); - canonicalActual = mock(Path.class); - expected = mock(Path.class); - canonicalExpected = mock(Path.class); - } +class Paths_assertHasParent_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasParent(info, null, expected)) - .withMessage(actualIsNull()); + // GIVEN + Path expected = tempDir.resolve("expected"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParent(info, null, expected)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_given_parent_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasParent(info, actual, null)) - .withMessage("expected parent path should not be null"); + void should_fail_if_expected_is_null() { + // GIVEN + Path actual = tempDir.resolve("actual"); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasParent(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("expected parent path should not be null"); } @Test - void should_fail_if_actual_cannot_be_canonicalized() throws IOException { - final IOException exception = new IOException(); - when(actual.toRealPath()).thenThrow(exception); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertHasParent(info, actual, expected)) - .withMessage("failed to resolve actual real path") - .withCause(exception); + void should_fail_if_actual_has_no_parent() { + // GIVEN + Path actual = tempDir.getRoot(); + Path expected = tempDir.resolve("expected"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParent(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveParent(actual, expected).create()); } @Test - void should_fail_if_expected_parent_cannot_be_canonicalized() throws IOException { - final IOException exception = new IOException(); - - when(actual.toRealPath()).thenReturn(canonicalActual); - when(expected.toRealPath()).thenThrow(exception); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertHasParent(info, actual, expected)) - .withMessage("failed to resolve argument real path") - .withCause(exception); + void should_rethrow_IOException_as_UncheckedIOException_if_actual_cannot_be_resolved() throws IOException { + // GIVEN + Path actual = mock(Path.class); + Path expected = createFile(tempDir.resolve("expected")); + IOException exception = new IOException("boom!"); + given(actual.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasParent(info, actual, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test - void should_fail_if_actual_has_no_parent() throws IOException { - when(actual.toRealPath()).thenReturn(canonicalActual); - when(expected.toRealPath()).thenReturn(canonicalExpected); - - // This is the default, but... - when(canonicalActual.getParent()).thenReturn(null); - - Throwable error = catchThrowable(() -> paths.assertHasParent(info, actual, expected)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveParent(actual, expected)); + void should_rethrow_IOException_as_UncheckedIOException_if_other_cannot_be_resolved() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path expected = mock(Path.class); + IOException exception = new IOException("boom!"); + given(expected.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasParent(info, actual, expected)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test void should_fail_if_actual_parent_is_not_expected_parent() throws IOException { - final Path actualParent = mock(Path.class); - - when(actual.toRealPath()).thenReturn(canonicalActual); - when(expected.toRealPath()).thenReturn(canonicalExpected); - - when(canonicalActual.getParent()).thenReturn(actualParent); - - Throwable error = catchThrowable(() -> paths.assertHasParent(info, actual, expected)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveParent(actual, actualParent, expected)); + // GIVEN + Path actual = createFile(tempDir.resolve("actual")).toRealPath(); + Path expected = createFile(tempDir.resolve("expected")).toRealPath(); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasParent(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveParent(actual, actual.getParent(), expected).create()); } @Test - void should_succeed_if_canonical_actual_has_expected_parent() throws IOException { - when(actual.toRealPath()).thenReturn(canonicalActual); - when(expected.toRealPath()).thenReturn(canonicalExpected); + void should_pass_if_actual_has_expected_parent() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")).toRealPath(); + Path expected = tempDir.toRealPath(); + // WHEN/THEN + paths.assertHasParent(info, actual, expected); + } - when(canonicalActual.getParent()).thenReturn(canonicalExpected); + @Test + void should_pass_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path expected = createDirectory(tempDir.resolve("expected")); + Path file = createFile(expected.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + // WHEN/THEN + paths.assertHasParent(info, actual, expected); + } + @Test + void should_pass_if_expected_is_not_canonical() throws IOException { + // GIVEN + Path directory = createDirectory(tempDir.resolve("directory")); + Path expected = createSymbolicLink(tempDir.resolve("expected"), directory); + Path actual = createFile(directory.resolve("actual")); + // WHEN/THEN paths.assertHasParent(info, actual, expected); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java index 2805539b6de..c3a5eeb2b40 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java @@ -12,140 +12,151 @@ */ package org.assertj.core.internal.paths; -import static java.nio.charset.Charset.defaultCharset; -import static java.nio.file.Files.readAllBytes; -import static org.assertj.core.api.Assertions.catchThrowableOfType; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.error.ShouldHaveBinaryContent.shouldHaveBinaryContent; -import static org.assertj.core.internal.BinaryDiffResult.noDiff; -import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.TempFileUtil.createTempPathWithContent; +import static org.junit.jupiter.api.condition.OS.WINDOWS; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; import java.io.UncheckedIOException; +import java.nio.charset.Charset; +import java.nio.file.Files; import java.nio.file.Path; import org.assertj.core.internal.BinaryDiffResult; import org.assertj.core.internal.PathsBaseTest; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; class Paths_assertHasSameBinaryContentAs_Test extends PathsBaseTest { - private Path actual; - private Path expected; - private byte[] expectedBytes; - - @BeforeEach - void setUpOnce() throws IOException { - // Does not matter if the values differ, the actual comparison is mocked in this test - actual = createTempPathWithContent("foo", defaultCharset()); - expected = createTempPathWithContent("bar", defaultCharset()); - expectedBytes = readAllBytes(expected); - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isReadable(actual)).thenReturn(true); - when(nioFilesWrapper.exists(expected)).thenReturn(true); - when(nioFilesWrapper.isReadable(expected)).thenReturn(true); - } - @Test - void should_pass_if_path_has_same_binary_content_as_expected() throws IOException { + void should_fail_if_expected_is_null() throws IOException { // GIVEN - given(binaryDiff.diff(actual, expectedBytes)).willReturn(noDiff()); - // WHEN/THEN - paths.assertHasSameBinaryContentAs(someInfo(), actual, expected); + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasSameBinaryContentAs(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The given Path to compare actual content to should not be null"); } @Test - void should_throw_error_if_expected_is_null() { + void should_fail_if_expected_does_not_exist() throws IOException { // GIVEN - Path nullExpected = null; + Path actual = createFile(tempDir.resolve("actual")); + Path expected = tempDir.resolve("non-existent"); // WHEN - NullPointerException npe = catchThrowableOfType(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, nullExpected), - NullPointerException.class); + Throwable thrown = catchThrowable(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN - then(npe).hasMessage("The given Path to compare actual content to should not be null"); + then(thrown).isInstanceOf(IllegalArgumentException.class) + .hasMessage("The given Path <%s> to compare actual content to should exist", expected); } @Test - void should_fail_if_actual_is_null() { + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_expected_is_not_readable() throws IOException { // GIVEN - Path path = null; + Path actual = createFile(tempDir.resolve("actual")); + Path expected = createFile(tempDir.resolve("expected")); + expected.toFile().setReadable(false); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertHasSameBinaryContentAs(someInfo(), path, expected)); + Throwable thrown = catchThrowable(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN - then(error).hasMessage(actualIsNull()); + then(thrown).isInstanceOf(IllegalArgumentException.class) + .hasMessage("The given Path <%s> to compare actual content to should be readable", expected); } @Test - void should_fail_if_actual_path_does_not_exist() { + void should_fail_if_actual_is_null() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); + Path expected = createFile(tempDir.resolve("expected")); // WHEN - expectAssertionError(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, expected)); + AssertionError error = expectAssertionError(() -> paths.assertHasSameBinaryContentAs(info, null, expected)); // THEN - verify(failures).failure(someInfo(), shouldExist(actual)); + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_is_not_readable() { + void should_fail_if_actual_does_not_exist() throws IOException { // GIVEN - when(nioFilesWrapper.isReadable(actual)).thenReturn(false); + Path actual = tempDir.resolve("non-existent"); + Path expected = createFile(tempDir.resolve("expected")); // WHEN - expectAssertionError(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, expected)); + AssertionError error = expectAssertionError(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN - verify(failures).failure(someInfo(), shouldBeReadable(actual)); + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_expected_path_is_does_not_exist() { + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { // GIVEN - when(nioFilesWrapper.exists(expected)).thenReturn(false); + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + Path expected = createFile(tempDir.resolve("expected")); // WHEN - IllegalArgumentException iae = catchThrowableOfType(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, expected), - IllegalArgumentException.class); + AssertionError error = expectAssertionError(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN - then(iae).hasMessage("The given Path <%s> to compare actual content to should exist", expected); + then(error).hasMessage(shouldBeReadable(actual).create()); } - @Test - void should_fail_if_expected_path_is_not_readable() { + @ParameterizedTest + @CsvSource({ + "Content, US-ASCII, US-ASCII", + "Content, US-ASCII, ISO_8859_1", + "Content, US-ASCII, UTF-8", + }) + void should_pass_if_actual_has_the_same_content_as_expected(String content, + Charset actualCharset, + Charset expectedCharset) throws IOException { // GIVEN - when(nioFilesWrapper.isReadable(expected)).thenReturn(false); - // WHEN - IllegalArgumentException iae = catchThrowableOfType(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, expected), - IllegalArgumentException.class); - // THEN - then(iae).hasMessage("The given Path <%s> to compare actual content to should be readable", expected); + Path actual = Files.write(tempDir.resolve("actual"), content.getBytes(actualCharset)); + Path expected = Files.write(tempDir.resolve("expected"), content.getBytes(expectedCharset)); + // WHEN/THEN + paths.assertHasSameBinaryContentAs(info, actual, expected); } - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { + @ParameterizedTest + @CsvSource({ + "Content, US-ASCII, Content, UTF-16", + "Content, US-ASCII, Another content, US-ASCII", + }) + void should_fail_if_actual_does_not_have_the_same_binary_content_as_expected(String actualContent, + Charset actualCharset, + String expectedContent, + Charset expectedCharset) throws IOException { // GIVEN - IOException cause = new IOException(); - given(binaryDiff.diff(actual, expectedBytes)).willThrow(cause); + Path actual = Files.write(tempDir.resolve("actual"), actualContent.getBytes(actualCharset)); + Path expected = Files.write(tempDir.resolve("expected"), expectedContent.getBytes(expectedCharset)); + BinaryDiffResult diff = binaryDiff.diff(actual, expectedContent.getBytes(expectedCharset)); // WHEN - UncheckedIOException uioe = catchThrowableOfType(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, expected), - UncheckedIOException.class); + AssertionError error = expectAssertionError(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN - then(uioe).hasCause(cause); + then(error).hasMessage(shouldHaveBinaryContent(actual, diff).create(info.description(), info.representation())); } @Test - void should_fail_if_path_does_not_have_expected_binary_content() throws IOException { + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN - BinaryDiffResult diff = new BinaryDiffResult(15, (byte) 0xCA, (byte) 0xFE); - when(binaryDiff.diff(actual, expectedBytes)).thenReturn(diff); + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); + Path expected = Files.write(tempDir.resolve("expected"), "Content".getBytes()); + IOException exception = new IOException("boom!"); + given(binaryDiff.diff(actual, "Content".getBytes())).willThrow(exception); // WHEN - expectAssertionError(() -> paths.assertHasSameBinaryContentAs(someInfo(), actual, expected)); + Throwable thrown = catchThrowable(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN - verify(failures).failure(someInfo(), shouldHaveBinaryContent(actual, diff)); + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameContentAs_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameContentAs_Test.java deleted file mode 100644 index adfc6b48655..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameContentAs_Test.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static java.nio.charset.Charset.defaultCharset; -import static java.util.Collections.emptyList; -import static org.assertj.core.api.Assertions.catchThrowableOfType; -import static org.assertj.core.api.BDDAssertions.then; -import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldHaveSameContent.shouldHaveSameContent; -import static org.assertj.core.test.TestData.someInfo; -import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.list; -import static org.assertj.core.util.TempFileUtil.createTempPathWithContent; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.util.List; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; -import org.assertj.core.util.diff.Delta; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertHasSameContentAs(AssertionInfo, Path, Charset, Path, Charset)}. - */ -class Paths_assertHasSameContentAs_Test extends MockPathsBaseTest { - - private static final Charset CHARSET = defaultCharset(); - private Path actual; - private Path expected; - - @BeforeEach - void setUpOnce() throws IOException { - // Does not matter if the values differ, the actual comparison is mocked in this test - actual = createTempPathWithContent("foo", CHARSET); - expected = createTempPathWithContent("bar", CHARSET); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isReadable(actual)).willReturn(true); - given(nioFilesWrapper.exists(expected)).willReturn(true); - given(nioFilesWrapper.isReadable(expected)).willReturn(true); - } - - @Test - void should_pass_if_path_has_same_textual_content_as_expected() throws IOException { - // GIVEN - given(diff.diff(actual, CHARSET, expected, CHARSET)).willReturn(emptyList()); - // WHEN/THEN - paths.assertHasSameContentAs(someInfo(), actual, CHARSET, expected, CHARSET); - } - - @Test - void should_throw_error_if_expected_is_null() { - // GIVEN - Path nullExpected = null; - // WHEN - NullPointerException npe = catchThrowableOfType(() -> paths.assertHasSameContentAs(someInfo(), actual, CHARSET, nullExpected, - CHARSET), - NullPointerException.class); - // THEN - then(npe).hasMessage("The given Path to compare actual content to should not be null"); - } - - @Test - void should_fail_if_actual_is_null() { - // GIVEN - Path path = null; - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertHasSameContentAs(someInfo(), path, CHARSET, expected, - CHARSET)); - // THEN - then(error).hasMessage(actualIsNull()); - } - - @Test - void should_fail_if_actual_path_does_not_exist() { - // GIVEN - AssertionInfo info = someInfo(); - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertHasSameContentAs(info, actual, CHARSET, expected, CHARSET)); - // THEN - verify(failures).failure(info, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_is_not_a_readable_file() { - // GIVEN - given(nioFilesWrapper.isReadable(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertHasSameContentAs(someInfo(), actual, CHARSET, expected, CHARSET)); - // THEN - verify(failures).failure(someInfo(), shouldBeReadable(actual)); - } - - @Test - void should_fail_if_expected_path_is_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(expected)).willReturn(false); - // WHEN - IllegalArgumentException iae = catchThrowableOfType(() -> paths.assertHasSameContentAs(someInfo(), actual, CHARSET, - expected, CHARSET), - IllegalArgumentException.class); - // THEN - then(iae).hasMessage("The given Path <%s> to compare actual content to should exist", expected); - } - - @Test - void should_fail_if_expected_path_is_not_readable() { - // GIVEN - given(nioFilesWrapper.isReadable(expected)).willReturn(false); - // WHEN - IllegalArgumentException iae = catchThrowableOfType(() -> paths.assertHasSameContentAs(someInfo(), actual, CHARSET, - expected, CHARSET), - IllegalArgumentException.class); - // THEN - then(iae).hasMessage("The given Path <%s> to compare actual content to should be readable", expected); - } - - @Test - void should_throw_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(diff.diff(actual, CHARSET, expected, CHARSET)).willThrow(cause); - // WHEN - UncheckedIOException uioe = catchThrowableOfType(() -> paths.assertHasSameContentAs(someInfo(), actual, CHARSET, - expected, CHARSET), - UncheckedIOException.class); - // THEN - then(uioe).hasCause(cause); - } - - @Test - void should_fail_if_actual_and_given_path_does_not_have_the_same_content() throws IOException { - // GIVEN - List> diffs = list((Delta) mock(Delta.class)); - given(diff.diff(actual, CHARSET, expected, CHARSET)).willReturn(diffs); - AssertionInfo info = someInfo(); - // WHEN - expectAssertionError(() -> paths.assertHasSameContentAs(someInfo(), actual, CHARSET, expected, CHARSET)); - // THEN - verify(failures).failure(info, shouldHaveSameContent(actual, expected, diffs)); - } -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java new file mode 100644 index 00000000000..9f1dafe7cb0 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java @@ -0,0 +1,170 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.charset.Charset.defaultCharset; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveSameContent.shouldHaveSameContent; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.assertj.core.internal.PathsBaseTest; +import org.assertj.core.util.diff.Delta; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class Paths_assertHasSameTextualContentAs_Test extends PathsBaseTest { + + private static final Charset CHARSET = defaultCharset(); + + @Test + void should_fail_if_expected_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, null, CHARSET)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The given Path to compare actual content to should not be null"); + } + + @Test + void should_fail_if_expected_does_not_exist() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path expected = tempDir.resolve("non-existent"); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, CHARSET)); + // THEN + then(thrown).isInstanceOf(IllegalArgumentException.class) + .hasMessage("The given Path <%s> to compare actual content to should exist", expected); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_expected_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path expected = createFile(tempDir.resolve("expected")); + expected.toFile().setReadable(false); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, CHARSET)); + // THEN + then(thrown).isInstanceOf(IllegalArgumentException.class) + .hasMessage("The given Path <%s> to compare actual content to should be readable", expected); + } + + @Test + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + Path expected = createFile(tempDir.resolve("expected")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSameTextualContentAs(info, null, CHARSET, expected, + CHARSET)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() throws IOException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + Path expected = createFile(tempDir.resolve("expected")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, + CHARSET)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + Path expected = createFile(tempDir.resolve("expected")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, + CHARSET)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); + } + + @ParameterizedTest + @CsvSource({ + "Content, US-ASCII, US-ASCII", + "Content, US-ASCII, ISO_8859_1", + "Content, US-ASCII, UTF-8", + "Content, US-ASCII, UTF-16", + }) + void should_pass_if_actual_has_the_same_content_as_expected(String content, + Charset actualCharset, + Charset expectedCharset) throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), content.getBytes(actualCharset)); + Path expected = Files.write(tempDir.resolve("expected"), content.getBytes(expectedCharset)); + // WHEN/THEN + paths.assertHasSameTextualContentAs(info, actual, actualCharset, expected, expectedCharset); + } + + @ParameterizedTest + @CsvSource({ + "Content, US-ASCII, Another content, US-ASCII", + }) + void should_fail_if_actual_does_not_have_the_same_content_as_expected(String actualContent, + Charset actualCharset, + String expectedContent, + Charset expectedCharset) throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), actualContent.getBytes(actualCharset)); + Path expected = Files.write(tempDir.resolve("expected"), expectedContent.getBytes(expectedCharset)); + List> diffs = diff.diff(actual, actualCharset, expected, expectedCharset); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasSameTextualContentAs(info, actual, actualCharset, + expected, expectedCharset)); + // THEN + then(error).hasMessage(shouldHaveSameContent(actual, expected, diffs).create(info.description(), info.representation())); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path expected = createFile(tempDir.resolve("expected")); + IOException exception = new IOException("boom!"); + given(diff.diff(actual, CHARSET, expected, CHARSET)).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, CHARSET)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java index ebe28763cf5..3402f177e2a 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSize_Test.java @@ -12,6 +12,8 @@ */ package org.assertj.core.internal.paths; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; @@ -19,7 +21,6 @@ import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import java.io.IOException; @@ -28,22 +29,10 @@ import java.nio.file.Path; import org.assertj.core.internal.PathsBaseTest; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; class Paths_assertHasSize_Test extends PathsBaseTest { - @TempDir - Path tempDir; - - @BeforeEach - void setUpNioFilesWrapper() throws IOException { - given(nioFilesWrapper.exists(any())).willCallRealMethod(); - given(nioFilesWrapper.isRegularFile(any())).willCallRealMethod(); - given(nioFilesWrapper.size(any())).willCallRealMethod(); - } - @Test void should_fail_if_actual_is_null() { // WHEN @@ -65,7 +54,7 @@ void should_fail_if_actual_does_not_exist() { @Test void should_fail_if_actual_is_not_regular_file() throws IOException { // GIVEN - Path actual = Files.createDirectory(tempDir.resolve("directory")); + Path actual = createDirectory(tempDir.resolve("directory")); // WHEN AssertionError error = expectAssertionError(() -> paths.assertHasSize(info, actual, 0L)); // THEN @@ -75,14 +64,13 @@ void should_fail_if_actual_is_not_regular_file() throws IOException { @Test void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN - Path actual = Files.createFile(tempDir.resolve("actual")); + Path actual = createFile(tempDir.resolve("actual")); IOException exception = new IOException("boom!"); given(nioFilesWrapper.size(actual)).willThrow(exception); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasSize(info, actual, 0L)); // THEN then(thrown).isInstanceOf(UncheckedIOException.class) - .hasMessage("unable to verify the size of the path: <%s>", actual) .hasCause(exception); } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java new file mode 100644 index 00000000000..32827fedc81 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java @@ -0,0 +1,129 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.charset.Charset.defaultCharset; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveContent.shouldHaveContent; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import static org.mockito.BDDMockito.given; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.assertj.core.internal.PathsBaseTest; +import org.assertj.core.util.diff.Delta; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; + +/** + * @author Olivier Michallat + * @author Joel Costigliola + */ +class Paths_assertHasTextualContent_Test extends PathsBaseTest { + + private static final Charset CHARSET = defaultCharset(); + + @Test + void should_fail_if_expected_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasTextualContent(info, actual, null, CHARSET)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The text to compare to should not be null"); + } + + @Test + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + String expected = "expected"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasTextualContent(info, null, expected, CHARSET)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() throws IOException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + String expected = "expected"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasTextualContent(info, actual, expected, CHARSET)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + String expected = "expected"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasTextualContent(info, actual, expected, CHARSET)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); + } + + @Test + void should_pass_if_actual_has_expected_textual_content() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes(CHARSET)); + String expected = "Content"; + // WHEN/THEN + paths.assertHasTextualContent(info, actual, expected, CHARSET); + } + + @Test + void should_fail_if_actual_does_not_have_expected_textual_content() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes(CHARSET)); + String expected = "Another content"; + List> diffs = diff.diff(actual, expected, CHARSET); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasTextualContent(info, actual, expected, CHARSET)); + // THEN + then(error).hasMessage(shouldHaveContent(actual, CHARSET, diffs).create(info.description(), info.representation())); + } + + @Test + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + String expected = "expected"; + IOException exception = new IOException("boom!"); + given(diff.diff(actual, expected, CHARSET)).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasTextualContent(info, actual, expected, CHARSET)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasMessage("Unable to verify text contents of path:<%s>", actual) + .hasCause(exception); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsAbsolute_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsAbsolute_Test.java index 83ec627cc65..15d34fb288a 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsAbsolute_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsAbsolute_Test.java @@ -12,38 +12,52 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeAbsolutePath.shouldBeAbsolutePath; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.stream.Stream; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -class Paths_assertIsAbsolute_Test extends MockPathsBaseTest { +class Paths_assertIsAbsolute_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsAbsolute(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsAbsolute(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } - @Test + @ParameterizedTest + @MethodSource("nonAbsolutePaths") void should_fail_if_actual_is_not_absolute() { - // This is the default, but make it explicit - when(actual.isAbsolute()).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsAbsolute(info, actual)); + // GIVEN + Path actual = Paths.get("relative"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsAbsolute(info, actual)); + // THEN + then(error).hasMessage(shouldBeAbsolutePath(actual).create()); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeAbsolutePath(actual)); + private static Stream nonAbsolutePaths() { + return Stream.of(Paths.get("foo"), + Paths.get("foo", "bar")); } @Test void should_pass_if_actual_is_absolute() { - when(actual.isAbsolute()).thenReturn(true); + // GIVEN + Path actual = tempDir.getRoot().resolve("foo").resolve("bar"); + // WHEN/THEN paths.assertIsAbsolute(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsCanonical_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsCanonical_Test.java index b63bf97de5a..0d3c6183dc2 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsCanonical_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsCanonical_Test.java @@ -12,53 +12,63 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeCanonicalPath.shouldBeCanonicalPath; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; -import org.assertj.core.api.exception.PathsException; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertIsCanonical_Test extends MockPathsBaseTest { +class Paths_assertIsCanonical_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsCanonical(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsCanonical(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_throw_PathsException_on_io_error() throws IOException { - final IOException exception = new IOException(); - when(actual.toRealPath()).thenThrow(exception); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertIsCanonical(info, actual)) - .withMessage("failed to resolve actual real path") - .withCause(exception); + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { + // GIVEN + Path actual = mock(Path.class); + IOException exception = new IOException("boom!"); + given(actual.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsCanonical(info, actual)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test - void should_fail_if_actual_real_path_differs_from_actual() throws IOException { - final Path other = mock(Path.class); - when(actual.toRealPath()).thenReturn(other); - - Throwable error = catchThrowable(() -> paths.assertIsCanonical(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeCanonicalPath(actual)); + void should_fail_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path file = createFile(tempDir.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsCanonical(info, actual)); + // THEN + then(error).hasMessage(shouldBeCanonicalPath(actual).create()); } @Test - void should_succeed_if_actual_real_path_is_same_as_actual() throws IOException { - when(actual.toRealPath()).thenReturn(actual); + void should_pass_if_actual_is_canonical() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")).toRealPath(); + // WHEN/THEN paths.assertIsCanonical(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_Predicate_Test.java deleted file mode 100644 index 4e9fc68e1c0..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_Predicate_Test.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; -import static org.assertj.core.error.ShouldContain.directoryShouldContain; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.internal.Paths.toPathNames; -import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; -import static org.assertj.core.util.Lists.list; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertIsDirectoryContaining(AssertionInfo, Path, Predicate)} - * - * @author Valeriy Vyrva - */ -class Paths_assertIsDirectoryContaining_Predicate_Test extends MockPathsBaseTest { - - /** - * We will check count call to {@link Path#getFileName()} - */ - private static final Predicate JAVA_SOURCE = path -> Optional.ofNullable(path.getFileName()) - .map(Path::toString) - .filter(pathName -> pathName.endsWith(".java")) - .isPresent(); - - @Test - void should_pass_if_actual_contains_a_file_matching_the_given_predicate() { - // GIVEN - Path file = mockEmptyRegularFile("Test.java"); - Path actual = mockDirectory("root", list(file)); - // THEN - paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE); - } - - @Test - void should_pass_if_all_actual_files_match_the_given_predicate() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.java"); - Path file2 = mockEmptyRegularFile("Utils.java"); - Path actual = mockDirectory("root", list(file1, file2)); - // THEN - paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE); - } - - @Test - void should_pass_if_actual_contains_at_least_one_file_matching_the_given_predicate() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.class"); - Path file2 = mockEmptyRegularFile("Test.java"); - Path file3 = mockEmptyRegularFile("Utils.class"); - Path file4 = mockEmptyRegularFile("Utils.java"); - Path file5 = mockEmptyRegularFile("application.yml"); - Path actual = mockDirectory("root", list(file1, file2, file3, file4, file5)); - // THEN - paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE); - } - - @Test - void should_throw_error_if_filter_is_null() { - // GIVEN - Predicate filter = null; - // THEN - assertThatNullPointerException().isThrownBy(() -> paths.assertIsDirectoryContaining(INFO, null, filter)) - .withMessage("The paths filter should not be null"); - } - - @Test - void should_fail_if_actual_is_null() { - // GIVEN - Path actual = null; - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); - // THEN - assertThat(error).hasMessage(actualIsNull()); - } - - @Test - void should_fail_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_directory() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, shouldBeDirectory(actual)); - } - - @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(true); - given(nioFilesWrapper.newDirectoryStream(eq(actual), any())).willThrow(cause); - // WHEN - Throwable error = catchThrowable(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_fail_if_actual_is_empty() { - // GIVEN - List emptyList = emptyList(); - Path actual = mockDirectory("root", emptyList); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, directoryShouldContain(actual, emptyList(), "the given filter")); - } - - @Test - void should_fail_if_actual_does_not_contain_any_files_matching_the_given_predicate() { - // GIVEN - Path file = mockEmptyRegularFile("root", "Test.class"); - List files = list(file); - Path actual = mockDirectory("root", files); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, directoryShouldContain(actual, toPathNames(files), "the given filter")); - } - -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_SyntaxAndPattern_Test.java deleted file mode 100644 index 249854d4390..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_SyntaxAndPattern_Test.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static java.lang.String.format; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; -import static org.assertj.core.error.ShouldContain.directoryShouldContain; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.internal.Paths.toPathNames; -import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; -import static org.assertj.core.util.Lists.list; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.FileSystem; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.util.List; -import java.util.Optional; -import java.util.regex.Pattern; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertIsDirectoryContaining(AssertionInfo, Path, String)} - * - * @author Valeriy Vyrva - */ -class Paths_assertIsDirectoryContaining_SyntaxAndPattern_Test extends MockPathsBaseTest { - - private static final String JAVA_SOURCE_PATTERN = "regex:.+\\.java"; - private static final String JAVA_SOURCE_PATTERN_DESCRIPTION = format("the '%s' pattern", JAVA_SOURCE_PATTERN); - - @Test - void should_pass_if_actual_contains_a_file_matching_the_given_pattern() { - // GIVEN - Path file = mockEmptyRegularFile("Test.java"); - Path actual = mockDirectory("root", list(file)); - mockPathMatcher(actual); - // THEN - paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN); - } - - @Test - void should_pass_if_all_actual_files_match_the_given_pattern() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.java"); - Path file2 = mockEmptyRegularFile("Utils.java"); - Path actual = mockDirectory("root", list(file1, file2)); - mockPathMatcher(actual); - // THEN - paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN); - } - - @Test - void should_pass_if_actual_contains_at_least_one_file_matching_the_given_pattern() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.class"); - Path file2 = mockEmptyRegularFile("Test.java"); - Path file3 = mockEmptyRegularFile("Utils.class"); - Path file4 = mockEmptyRegularFile("Utils.java"); - Path file5 = mockEmptyRegularFile("application.yml"); - Path actual = mockDirectory("root", list(file1, file2, file3, file4, file5)); - mockPathMatcher(actual); - // THEN - paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN); - } - - @Test - void should_throw_error_if_filter_is_null() { - // GIVEN - String filter = null; - // THEN - assertThatNullPointerException().isThrownBy(() -> paths.assertIsDirectoryContaining(INFO, null, filter)) - .withMessage("The syntax and pattern should not be null"); - } - - @Test - void should_fail_if_actual_is_null() { - // GIVEN - Path actual = null; - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - assertThat(error).hasMessage(actualIsNull()); - } - - @Test - void should_fail_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_directory() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, shouldBeDirectory(actual)); - } - - @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(true); - given(nioFilesWrapper.newDirectoryStream(eq(actual), any())).willThrow(cause); - mockPathMatcher(actual); - // WHEN - Throwable error = catchThrowable(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_fail_if_actual_is_empty() { - // GIVEN - List emptyList = emptyList(); - Path actual = mockDirectory("root", emptyList); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, directoryShouldContain(actual, emptyList(), JAVA_SOURCE_PATTERN_DESCRIPTION)); - } - - @Test - void should_fail_if_actual_does_not_contain_any_files_matching_the_given_predicate() { - // GIVEN - Path file = mockEmptyRegularFile("root", "Test.class"); - List files = list(file); - Path actual = mockDirectory("root", files); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, directoryShouldContain(actual, toPathNames(files), JAVA_SOURCE_PATTERN_DESCRIPTION)); - } - - static void mockPathMatcher(Path actual) { - FileSystem fileSystem = mock(FileSystem.class); - given(fileSystem.getPathMatcher(anyString())).will(inv -> { - String regex = inv.getArgument(0).toString().split(":")[1]; - Pattern pattern = Pattern.compile("^" + regex + "$", Pattern.CASE_INSENSITIVE); - return (PathMatcher) path -> Optional.ofNullable(path.getFileName()) - .map(Path::toString) - .filter(pattern.asPredicate()) - .isPresent(); - }); - given(actual.getFileSystem()).willReturn(fileSystem); - } - -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java new file mode 100644 index 00000000000..603a3366019 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java @@ -0,0 +1,135 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; +import static org.assertj.core.error.ShouldContain.directoryShouldContain; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Lists.emptyList; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.willThrow; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.function.Predicate; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertIsDirectoryContaining_with_Predicate_Test extends PathsBaseTest { + + @Test + void should_fail_if_filter_is_null() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Predicate filter = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The paths filter should not be null"); + } + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_directory() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file")); + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(error).hasMessage(shouldBeDirectory(actual).create()); + } + + @Test + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Predicate filter = path -> true; + IOException cause = new IOException("boom!"); + willThrow(cause).given(nioFilesWrapper).newDirectoryStream(any(), any()); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_fail_if_actual_is_empty() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(error).hasMessage(directoryShouldContain(actual, emptyList(), "the given filter").create()); + } + + @Test + void should_pass_if_actual_contains_at_least_one_path_matching_the_given_predicate() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + createFile(actual.resolve("file")); + Predicate filter = Files::isRegularFile; + // WHEN/THEN + paths.assertIsDirectoryContaining(info, actual, filter); + } + + @Test + void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_predicate() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Path directory = createDirectory(actual.resolve("directory")); + Predicate filter = Files::isRegularFile; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, filter)); + // THEN + then(error).hasMessage(directoryShouldContain(actual, singletonList(directory.toString()), "the given filter").create()); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java new file mode 100644 index 00000000000..8ec4f544a69 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java @@ -0,0 +1,135 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; +import static org.assertj.core.error.ShouldContain.directoryShouldContain; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Lists.emptyList; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.willThrow; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertIsDirectoryContaining_with_String_Test extends PathsBaseTest { + + @Test + void should_fail_if_syntaxAndPattern_is_null() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + String syntaxAndPattern = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The syntax and pattern should not be null"); + } + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_directory() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file")); + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(shouldBeDirectory(actual).create()); + } + + @Test + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + String syntaxAndPattern = "glob:*"; + IOException cause = new IOException("boom!"); + willThrow(cause).given(nioFilesWrapper).newDirectoryStream(any(), any()); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_fail_if_actual_is_empty() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(directoryShouldContain(actual, emptyList(), "the 'glob:**' pattern").create()); + } + + @Test + void should_pass_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + createFile(actual.resolve("file")); + createDirectory(actual.resolve("directory")); + String syntaxAndPattern = "glob:**file"; + // WHEN/THEN + paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern); + } + + @Test + void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Path directory = createDirectory(actual.resolve("directory")); + String syntaxAndPattern = "glob:**file"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(directoryShouldContain(actual, singletonList(directory.toString()), + "the 'glob:**file' pattern").create()); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_Predicate_Test.java deleted file mode 100644 index 78a60b45382..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_Predicate_Test.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; -import static org.assertj.core.internal.Paths.toPathNames; -import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; -import static org.assertj.core.util.Lists.list; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertIsDirectoryNotContaining(AssertionInfo, Path, Predicate)} - * - * @author Valeriy Vyrva - */ -class Paths_assertIsDirectoryNotContaining_Predicate_Test extends MockPathsBaseTest { - - /** - * We will check count call to {@link Path#getFileName()} - */ - private static final Predicate JAVA_SOURCE = path -> Optional.ofNullable(path.getFileName()) - .map(Path::toString) - .filter(fileName -> fileName.endsWith(".java")) - .isPresent(); - - @Test - void should_pass_if_actual_does_not_contain_files_matching_the_given_filter() { - // GIVEN - Path file = mockEmptyRegularFile("root", "Test.class"); - List items = list(file); - Path actual = mockDirectory("root", items); - // THEN - paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE); - } - - @Test - void should_pass_if_actual_is_empty() { - // GIVEN - List items = emptyList(); - Path actual = mockDirectory("root", items); - // THEN - paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE); - } - - @Test - void should_throw_error_if_filter_is_null() { - // GIVEN - Predicate filter = null; - // THEN - assertThatNullPointerException().isThrownBy(() -> paths.assertIsDirectoryNotContaining(INFO, null, filter)) - .withMessage("The paths filter should not be null"); - } - - @Test - void should_fail_if_actual_is_null() { - // GIVEN - Path actual = null; - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - assertThat(error).hasMessage(actualIsNull()); - } - - @Test - void should_fail_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_directory() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, shouldBeDirectory(actual)); - } - - @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(true); - given(nioFilesWrapper.newDirectoryStream(eq(actual), any())).willThrow(cause); - // WHEN - Throwable error = catchThrowable(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_fail_if_one_actual_file_matches_the_filter() { - // GIVEN - Path file = mockEmptyRegularFile("Test.java"); - List items = list(file); - Path actual = mockDirectory("root", items); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toPathNames(items), "the given filter")); - } - - @Test - void should_fail_if_all_actual_files_match_the_filter() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.java"); - Path file2 = mockEmptyRegularFile("Utils.java"); - List items = list(file1, file2); - Path actual = mockDirectory("root", items); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toPathNames(items), "the given filter")); - } - - @Test - void should_fail_if_some_actual_files_match_the_filter() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.class"); - Path file2 = mockEmptyRegularFile("Test.java"); - Path file3 = mockEmptyRegularFile("Utils.class"); - Path file4 = mockEmptyRegularFile("Utils.java"); - Path file5 = mockEmptyRegularFile("application.yml"); - List items = list(file1, file2, file3, file4, file5); - Path actual = mockDirectory("root", items); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); - // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toPathNames(list(file2, file4)), "the given filter")); - } - -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java deleted file mode 100644 index a3dea60de01..00000000000 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.internal.paths; - -import static java.lang.String.format; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; -import static org.assertj.core.error.ShouldExist.shouldExist; -import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; -import static org.assertj.core.internal.Paths.toPathNames; -import static org.assertj.core.internal.paths.Paths_assertIsDirectoryContaining_SyntaxAndPattern_Test.mockPathMatcher; -import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; -import static org.assertj.core.util.Lists.list; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.util.List; - -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link Paths#assertIsDirectoryNotContaining(AssertionInfo, Path, String)} - * - * @author Valeriy Vyrva - */ -class Paths_assertIsDirectoryNotContaining_SyntaxAndPattern_Test extends MockPathsBaseTest { - - private static final String JAVA_SOURCE_PATTERN = "regex:.+\\.java"; - private static final String JAVA_SOURCE_PATTERN_DESCRIPTION = format("the '%s' pattern", JAVA_SOURCE_PATTERN); - - @Test - void should_pass_if_actual_does_not_contain_files_matching_the_given_pattern() { - // GIVEN - Path file = mockEmptyRegularFile("root", "Test.class"); - List items = singletonList(file); - Path actual = mockDirectory("root", items); - mockPathMatcher(actual); - // THEN - paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN); - } - - @Test - void should_pass_if_actual_is_empty() { - // GIVEN - List items = emptyList(); - Path actual = mockDirectory("root", items); - mockPathMatcher(actual); - // THEN - paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN); - } - - @Test - void should_throw_error_if_pattern_is_null() { - // GIVEN - String pattern = null; - // THEN - assertThatNullPointerException().isThrownBy(() -> paths.assertIsDirectoryNotContaining(INFO, null, pattern)) - .withMessage("The syntax and pattern should not be null"); - } - - @Test - void should_fail_if_actual_is_null() { - // GIVEN - Path actual = null; - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - assertThat(error).hasMessage(actualIsNull()); - } - - @Test - void should_fail_if_actual_does_not_exist() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); - } - - @Test - void should_fail_if_actual_exists_but_is_not_directory() { - // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, shouldBeDirectory(actual)); - } - - @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { - // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(true); - given(nioFilesWrapper.newDirectoryStream(eq(actual), any())).willThrow(cause); - mockPathMatcher(actual); - // WHEN - Throwable error = catchThrowable(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); - } - - @Test - void should_fail_if_one_actual_file_matches_the_given_pattern() { - // GIVEN - Path file = mockEmptyRegularFile("Test.java"); - List items = list(file); - Path actual = mockDirectory("root", items); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toPathNames(items), JAVA_SOURCE_PATTERN_DESCRIPTION)); - } - - @Test - void should_fail_if_actual_contains_only_not_expected() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.java"); - Path file2 = mockEmptyRegularFile("Utils.java"); - List items = list(file1, file2); - Path actual = mockDirectory("root", items); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toPathNames(items), JAVA_SOURCE_PATTERN_DESCRIPTION)); - } - - @Test - void should_fail_if_some_actual_files_match_the_filter() { - // GIVEN - Path file1 = mockEmptyRegularFile("Test.class"); - Path file2 = mockEmptyRegularFile("Test.java"); - Path file3 = mockEmptyRegularFile("Utils.class"); - Path file4 = mockEmptyRegularFile("Utils.java"); - Path file5 = mockEmptyRegularFile("application.yml"); - List items = list(file1, file2, file3, file4, file5); - Path actual = mockDirectory("root", items); - mockPathMatcher(actual); - // WHEN - expectAssertionError(() -> paths.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); - // THEN - verify(failures).failure(INFO, - directoryShouldNotContain(actual, toPathNames(list(file2, file4)), JAVA_SOURCE_PATTERN_DESCRIPTION)); - } - -} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java new file mode 100644 index 00000000000..91cd31ed350 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java @@ -0,0 +1,132 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.willThrow; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.function.Predicate; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertIsDirectoryNotContaining_with_Predicate_Test extends PathsBaseTest { + + @Test + void should_fail_if_filter_is_null() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Predicate filter = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The paths filter should not be null"); + } + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_directory() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file")); + Predicate filter = path -> true; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); + // THEN + then(error).hasMessage(shouldBeDirectory(actual).create()); + } + + @Test + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Predicate filter = path -> true; + IOException cause = new IOException("boom!"); + willThrow(cause).given(nioFilesWrapper).newDirectoryStream(any(), any()); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_pass_if_actual_is_empty() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Predicate filter = path -> true; + // WHEN/THEN + paths.assertIsDirectoryNotContaining(info, actual, filter); + } + + @Test + void should_fail_if_actual_contains_at_least_one_path_matching_the_given_predicate() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Path file = createFile(actual.resolve("file")); + Predicate filter = Files::isRegularFile; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); + // THEN + then(error).hasMessage(directoryShouldNotContain(actual, singletonList(file.toString()), "the given filter").create()); + } + + @Test + void should_pass_if_actual_does_not_contain_any_paths_matching_the_given_predicate() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + createDirectory(actual.resolve("directory")); + Predicate filter = Files::isRegularFile; + // WHEN/THEN + paths.assertIsDirectoryNotContaining(info, actual, filter); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java new file mode 100644 index 00000000000..e4abaf148e6 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java @@ -0,0 +1,131 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.willThrow; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; + +/** + * @author Valeriy Vyrva + */ +class Paths_assertIsDirectoryNotContaining_with_String_Test extends PathsBaseTest { + + @Test + void should_fail_if_syntaxAndPattern_is_null() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + String syntaxAndPattern = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The syntax and pattern should not be null"); + } + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_directory() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file")); + String syntaxAndPattern = "glob:**"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(shouldBeDirectory(actual).create()); + } + + @Test + void should_rethrow_IOException_as_UncheckedIOException() throws Exception { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + String syntaxAndPattern = "glob:*"; + IOException cause = new IOException("boom!"); + willThrow(cause).given(nioFilesWrapper).newDirectoryStream(any(), any()); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(cause); + } + + @Test + void should_pass_if_actual_is_empty() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + String syntaxAndPattern = "glob:**"; + // WHEN/THEN + paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern); + } + + @Test + void should_fail_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Path file = createFile(actual.resolve("file")); + String syntaxAndPattern = "glob:**file"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(directoryShouldNotContain(actual, singletonList(file.toString()), + "the 'glob:**file' pattern").create()); + } + + @Test + void should_pass_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + createDirectory(actual.resolve("directory")); + String syntaxAndPattern = "glob:**file"; + // WHEN/THEN + paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectory_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectory_Test.java index fc6d353e67a..dc557fbe768 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectory_Test.java @@ -12,50 +12,55 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertIsDirectory_Test extends MockPathsBaseTest { +class Paths_assertIsDirectory_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsDirectory(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectory(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsDirectory(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(actual)); + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectory(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_target_exists_but_is_not_a_directory() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isDirectory(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsDirectory(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeDirectory(actual)); + void should_fail_if_actual_is_not_a_directory() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectory(info, actual)); + // THEN + then(error).hasMessage(shouldBeDirectory(actual).create()); } @Test - void should_succeed_if_actual_is_a_directory() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isDirectory(actual)).thenReturn(true); + void should_pass_if_actual_is_a_directory() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + // WHEN/THEN paths.assertIsDirectory(info, actual); } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java index 01f83ce53b5..50e829d721f 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java @@ -12,99 +12,90 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldBeEmptyDirectory.shouldBeEmptyDirectory; import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; -import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Path; -import java.util.List; -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; /** - * Tests for {@link Paths#assertIsEmptyDirectory(AssertionInfo, Path)} - * * @author Valeriy Vyrva */ -class Paths_assertIsEmptyDirectory_Test extends MockPathsBaseTest { +class Paths_assertIsEmptyDirectory_Test extends PathsBaseTest { @Test - void should_pass_if_actual_is_empty() { - // GIVEN - List pathList = emptyList(); - Path actual = mockDirectory("root", pathList); + void should_fail_if_actual_is_null() { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyDirectory(info, null)); // THEN - paths.assertIsEmptyDirectory(INFO, actual); + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_is_not_empty() { + void should_fail_if_actual_does_not_exist() { // GIVEN - Path file = mockEmptyRegularFile("root", "Test.class"); - List files = list(file); - Path actual = mockDirectory("root", files); + Path actual = tempDir.resolve("non-existent"); // WHEN - expectAssertionError(() -> paths.assertIsEmptyDirectory(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyDirectory(info, actual)); // THEN - verify(failures).failure(INFO, shouldBeEmptyDirectory(actual, files)); + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_is_null() { + void should_fail_if_actual_is_not_a_directory() throws IOException { // GIVEN - Path actual = null; + Path actual = createFile(tempDir.resolve("file")); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsEmptyDirectory(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyDirectory(info, actual)); // THEN - assertThat(error).hasMessage(actualIsNull()); + then(error).hasMessage(shouldBeDirectory(actual).create()); } @Test - void should_fail_if_actual_does_not_exist() { + void should_pass_if_actual_is_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertIsEmptyDirectory(INFO, actual)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); + Path actual = createDirectory(tempDir.resolve("actual")); + // WHEN/THEN + paths.assertIsEmptyDirectory(info, actual); } @Test - void should_fail_if_actual_exists_but_is_not_directory() { + void should_fail_if_actual_is_not_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); + Path actual = createDirectory(tempDir.resolve("actual")); + Path file = createFile(actual.resolve("file")); // WHEN - expectAssertionError(() -> paths.assertIsEmptyDirectory(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyDirectory(info, actual)); // THEN - verify(failures).failure(INFO, shouldBeDirectory(actual)); + then(error).hasMessage(shouldBeEmptyDirectory(actual, singletonList(file)).create()); } @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(true); - given(nioFilesWrapper.newDirectoryStream(eq(actual), any())).willThrow(cause); + Path actual = createDirectory(tempDir.resolve("actual")); + IOException exception = new IOException("boom!"); + willThrow(exception).given(nioFilesWrapper).newDirectoryStream(eq(actual), any()); // WHEN - Throwable error = catchThrowable(() -> paths.assertIsEmptyDirectory(INFO, actual)); + Throwable thrown = catchThrowable(() -> paths.assertIsEmptyDirectory(info, actual)); // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyFile_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyFile_Test.java index 9d329273ffd..ed232ed58d9 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyFile_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyFile_Test.java @@ -12,6 +12,8 @@ */ package org.assertj.core.internal.paths; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; @@ -22,83 +24,72 @@ import static org.mockito.BDDMockito.given; import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; import java.nio.file.Path; -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.api.exception.PathsException; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.DisplayName; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -/** - * Tests for {@link Paths#assertIsEmptyFile(AssertionInfo, Path)} - * - * @author Stefano Cordio - */ -@DisplayName("Paths assertIsEmptyFile") -class Paths_assertIsEmptyFile_Test extends MockPathsBaseTest { +class Paths_assertIsEmptyFile_Test extends PathsBaseTest { @Test - void should_pass_if_actual_is_empty() { - // GIVEN - Path actual = mockEmptyRegularFile("file"); - // WHEN/THEN - paths.assertIsEmptyFile(INFO, actual); + void should_fail_if_actual_is_null() { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_is_not_empty() { + void should_fail_if_actual_does_not_exist() { // GIVEN - Path actual = mockNonEmptyRegularFile("file"); + Path actual = tempDir.resolve("non-existent"); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(info, actual)); // THEN - then(error).hasMessage(shouldBeEmpty(actual).create()); + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_is_null() { + void should_fail_if_actual_is_not_regular_file() throws IOException { // GIVEN - Path actual = null; + Path actual = createDirectory(tempDir.resolve("directory")); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(info, actual)); // THEN - then(error).hasMessage(actualIsNull()); + then(error).hasMessage(shouldBeRegularFile(actual).create()); } @Test - void should_fail_if_actual_does_not_exist() { + void should_pass_if_actual_is_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(INFO, actual)); - // THEN - then(error).hasMessage(shouldExist(actual).create()); + Path actual = createFile(tempDir.resolve("actual")); + // WHEN/THEN + paths.assertIsEmptyFile(info, actual); } @Test - void should_fail_if_actual_exists_but_is_not_regular_file() { + void should_fail_if_actual_is_not_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(false); + Path actual = Files.write(tempDir.resolve("actual"), "content".getBytes()); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsEmptyFile(info, actual)); // THEN - then(error).hasMessage(shouldBeRegularFile(actual).create()); + then(error).hasMessage(shouldBeEmpty(actual).create()); } @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.size(actual)).willThrow(cause); + Path actual = createFile(tempDir.resolve("actual")); + IOException exception = new IOException("boom!"); + given(nioFilesWrapper.size(actual)).willThrow(exception); // WHEN - Throwable error = catchThrowable(() -> paths.assertIsEmptyFile(INFO, actual)); + Throwable thrown = catchThrowable(() -> paths.assertIsEmptyFile(info, actual)); // THEN - then(error).isInstanceOf(PathsException.class) - .hasCause(cause); + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsExecutable_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsExecutable_Test.java index e07170e1c32..f02b2b2b969 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsExecutable_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsExecutable_Test.java @@ -12,50 +12,58 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeExecutable.shouldBeExecutable; import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; -class Paths_assertIsExecutable_Test extends MockPathsBaseTest { +class Paths_assertIsExecutable_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsExecutable(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsExecutable(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsExecutable(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(actual)); + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsExecutable(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_exists_but_is_not_executable() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isExecutable(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsExecutable(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeExecutable(actual)); + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_executable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsExecutable(info, actual)); + // THEN + then(error).hasMessage(shouldBeExecutable(actual).create()); } @Test - void should_succeed_if_actual_exist_and_is_executable() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isExecutable(actual)).thenReturn(true); + void should_pass_if_actual_is_executable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setExecutable(true); + // WHEN/THEN paths.assertIsExecutable(info, actual); } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNormalized_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNormalized_Test.java index fab20e5c466..6843b51deb1 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNormalized_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNormalized_Test.java @@ -12,41 +12,81 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeNormalized.shouldBeNormalized; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.condition.OS.WINDOWS; import java.nio.file.Path; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; -class Paths_assertIsNormalized_Test extends MockPathsBaseTest { +class Paths_assertIsNormalized_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsNormalized(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsNormalized(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } - @Test - void should_fail_if_actual_is_not_normalized() { - when(actual.normalize()).thenReturn(mock(Path.class)); - - Throwable error = catchThrowable(() -> paths.assertIsNormalized(info, actual)); + @ParameterizedTest + @DisabledOnOs(WINDOWS) + @CsvSource({ + "/a/./b", + "c/d/..", + "/../../e", + }) + void should_fail_on_unix_if_actual_is_not_normalized(Path actual) { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsNormalized(info, actual)); + // THEN + then(error).hasMessage(shouldBeNormalized(actual).create()); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeNormalized(actual)); + @ParameterizedTest + @EnabledOnOs(WINDOWS) + @CsvSource({ + "C:\\a\\.\\b", + "c\\d\\..", + "C:\\..\\..\\e", + }) + void should_fail_on_windows_if_actual_is_not_normalized(Path actual) { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsNormalized(info, actual)); + // THEN + then(error).hasMessage(shouldBeNormalized(actual).create()); } - @Test - void should_pass_if_actual_is_normalized() { - when(actual.normalize()).thenReturn(actual); + @ParameterizedTest + @DisabledOnOs(WINDOWS) + @CsvSource({ + "/usr/lib", + "a/b/c", + "../d", + }) + void should_pass_on_unix_if_actual_is_normalized(Path actual) { + // WHEN/THEN + paths.assertIsNormalized(info, actual); + } + @ParameterizedTest + @EnabledOnOs(WINDOWS) + @CsvSource({ + "C:\\usr\\lib", + "a\\b\\c", + "..\\d", + }) + void should_pass_on_windows_if_actual_is_normalized(Path actual) { + // WHEN/THEN paths.assertIsNormalized(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java index 2742f96104d..77f4efdc732 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java @@ -12,98 +12,89 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; -import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Path; -import java.util.List; -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Paths; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; /** - * Tests for {@link Paths#assertIsNotEmptyDirectory(AssertionInfo, Path)} - * * @author Valeriy Vyrva */ -class Paths_assertIsNotEmptyDirectory_Test extends MockPathsBaseTest { +class Paths_assertIsNotEmptyDirectory_Test extends PathsBaseTest { @Test - void should_pass_if_actual_is_not_empty() { - // GIVEN - List files = list(mockEmptyRegularFile("root", "Test.class")); - Path actual = mockDirectory("root", files); + void should_fail_if_actual_is_null() { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyDirectory(info, null)); // THEN - paths.assertIsNotEmptyDirectory(INFO, actual); + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_is_empty() { + void should_fail_if_actual_does_not_exist() { // GIVEN - Path actual = mockDirectory("root", emptyList()); + Path actual = tempDir.resolve("non-existent"); // WHEN - expectAssertionError(() -> paths.assertIsNotEmptyDirectory(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyDirectory(info, actual)); // THEN - verify(failures).failure(INFO, shouldNotBeEmpty()); + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_is_null() { + void should_fail_if_actual_is_not_a_directory() throws IOException { // GIVEN - Path actual = null; + Path actual = createFile(tempDir.resolve("file")); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyDirectory(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyDirectory(info, actual)); // THEN - assertThat(error).hasMessage(actualIsNull()); + then(error).hasMessage(shouldBeDirectory(actual).create()); } @Test - void should_fail_if_actual_does_not_exist() { + void should_pass_if_actual_is_not_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - expectAssertionError(() -> paths.assertIsNotEmptyDirectory(INFO, actual)); - // THEN - verify(failures).failure(INFO, shouldExist(actual)); + Path actual = createDirectory(tempDir.resolve("actual")); + createFile(actual.resolve("file")); + // WHEN/THEN + paths.assertIsNotEmptyDirectory(info, actual); } @Test - void should_fail_if_actual_exists_but_is_not_directory() { + void should_fail_if_actual_is_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(false); + Path actual = createDirectory(tempDir.resolve("actual")); // WHEN - expectAssertionError(() -> paths.assertIsNotEmptyDirectory(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyDirectory(info, actual)); // THEN - verify(failures).failure(INFO, shouldBeDirectory(actual)); + then(error).hasMessage(shouldNotBeEmpty(actual).create()); } @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isDirectory(actual)).willReturn(true); - given(nioFilesWrapper.newDirectoryStream(eq(actual), any())).willThrow(cause); + Path actual = createDirectory(tempDir.resolve("actual")); + IOException exception = new IOException("boom!"); + willThrow(exception).given(nioFilesWrapper).newDirectoryStream(eq(actual), any()); // WHEN - Throwable error = catchThrowable(() -> paths.assertIsNotEmptyDirectory(INFO, actual)); + Throwable thrown = catchThrowable(() -> paths.assertIsNotEmptyDirectory(info, actual)); // THEN - assertThat(error).isInstanceOf(UncheckedIOException.class) - .hasCause(cause); + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyFile_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyFile_Test.java index 1463d325b13..21d61da0057 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyFile_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyFile_Test.java @@ -12,6 +12,8 @@ */ package org.assertj.core.internal.paths; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; @@ -22,83 +24,72 @@ import static org.mockito.BDDMockito.given; import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; import java.nio.file.Path; -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.api.exception.PathsException; -import org.assertj.core.internal.Paths; -import org.junit.jupiter.api.DisplayName; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -/** - * Tests for {@link Paths#assertIsNotEmptyFile(AssertionInfo, Path)} - * - * @author Stefano Cordio - */ -@DisplayName("Paths assertIsNotEmptyFile") -class Paths_assertIsNotEmptyFile_Test extends MockPathsBaseTest { +class Paths_assertIsNotEmptyFile_Test extends PathsBaseTest { @Test - void should_pass_if_actual_is_empty() { - // GIVEN - Path actual = mockNonEmptyRegularFile("file"); - // WHEN/THEN - paths.assertIsNotEmptyFile(INFO, actual); + void should_fail_if_actual_is_null() { + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_is_not_empty() { + void should_fail_if_actual_does_not_exist() { // GIVEN - Path actual = mockEmptyRegularFile("file"); + Path actual = tempDir.resolve("non-existent"); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(info, actual)); // THEN - then(error).hasMessage(shouldNotBeEmpty(actual).create()); + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_is_null() { + void should_fail_if_actual_is_not_regular_file() throws IOException { // GIVEN - Path actual = null; + Path actual = createDirectory(tempDir.resolve("directory")); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(info, actual)); // THEN - then(error).hasMessage(actualIsNull()); + then(error).hasMessage(shouldBeRegularFile(actual).create()); } @Test - void should_fail_if_actual_does_not_exist() { + void should_pass_if_actual_is_not_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(false); - // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(INFO, actual)); - // THEN - then(error).hasMessage(shouldExist(actual).create()); + Path actual = Files.write(tempDir.resolve("actual"), "content".getBytes()); + // WHEN/THEN + paths.assertIsNotEmptyFile(info, actual); } @Test - void should_fail_if_actual_exists_but_is_not_regular_file() { + void should_fail_if_actual_is_empty() throws IOException { // GIVEN - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(false); + Path actual = createFile(tempDir.resolve("actual")); // WHEN - AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(INFO, actual)); + AssertionError error = expectAssertionError(() -> paths.assertIsNotEmptyFile(info, actual)); // THEN - then(error).hasMessage(shouldBeRegularFile(actual).create()); + then(error).hasMessage(shouldNotBeEmpty(actual).create()); } @Test - void should_throw_runtime_error_wrapping_caught_IOException() throws IOException { + void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN - IOException cause = new IOException(); - given(nioFilesWrapper.exists(actual)).willReturn(true); - given(nioFilesWrapper.isRegularFile(actual)).willReturn(true); - given(nioFilesWrapper.size(actual)).willThrow(cause); + Path actual = createFile(tempDir.resolve("actual")); + IOException exception = new IOException("boom!"); + given(nioFilesWrapper.size(actual)).willThrow(exception); // WHEN - Throwable error = catchThrowable(() -> paths.assertIsNotEmptyFile(INFO, actual)); + Throwable thrown = catchThrowable(() -> paths.assertIsNotEmptyFile(info, actual)); // THEN - then(error).isInstanceOf(PathsException.class) - .hasCause(cause); + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsReadable_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsReadable_Test.java index 3faafb2845c..e96b6e47c79 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsReadable_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsReadable_Test.java @@ -12,50 +12,58 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeReadable.shouldBeReadable; import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.condition.OS.WINDOWS; +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; -class Paths_assertIsReadable_Test extends MockPathsBaseTest { +class Paths_assertIsReadable_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsReadable(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsReadable(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsReadable(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(actual)); + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsReadable(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_exists_but_is_not_readable() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isReadable(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsReadable(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeReadable(actual)); + @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") + void should_fail_if_actual_is_not_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setReadable(false); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsReadable(info, actual)); + // THEN + then(error).hasMessage(shouldBeReadable(actual).create()); } @Test - void should_succeed_if_actual_exist_and_is_readable() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isReadable(actual)).thenReturn(true); + void should_pass_if_actual_is_readable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN/THEN paths.assertIsReadable(info, actual); } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRegularFile_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRegularFile_Test.java index 080fc5c26d7..98caffab651 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRegularFile_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRegularFile_Test.java @@ -12,50 +12,56 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createDirectory; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertIsRegularFile_Test extends MockPathsBaseTest { +class Paths_assertIsRegularFile_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsRegularFile(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsRegularFile(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsRegularFile(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(actual)); + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsRegularFile(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_target_exists_but_is_not_a_regular_file() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isRegularFile(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsRegularFile(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeRegularFile(actual)); + void should_fail_if_actual_is_not_a_regular_file() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsRegularFile(info, actual)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); } @Test - void should_succeed_if_actual_is_an_existing_regular_file() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isRegularFile(actual)).thenReturn(true); + void should_pass_if_actual_is_a_regular_file() throws IOException { + // GIVEN + Path actual = Files.write(tempDir.resolve("actual"), "content".getBytes()); + // WHEN/THEN paths.assertIsRegularFile(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRelative_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRelative_Test.java index eb91d221db4..8632bac42dc 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRelative_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsRelative_Test.java @@ -12,38 +12,43 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeRelativePath.shouldBeRelativePath; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertIsRelative_Test extends MockPathsBaseTest { +class Paths_assertIsRelative_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsRelative(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsRelative(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test void should_fail_if_actual_is_not_relative() { - // This is the default, but make it explicit - when(actual.isAbsolute()).thenReturn(true); - - Throwable error = catchThrowable(() -> paths.assertIsRelative(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeRelativePath(actual)); + // GIVEN + Path actual = tempDir.getRoot().resolve("absolute"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsRelative(info, actual)); + // THEN + then(error).hasMessage(shouldBeRelativePath(actual).create()); } @Test void should_pass_if_actual_is_relative() { - when(actual.isAbsolute()).thenReturn(false); + // GIVEN + Path actual = Paths.get("relative"); + // WHEN/THEN paths.assertIsRelative(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsSymbolicLink_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsSymbolicLink_Test.java index 1e5b6351708..e6b810e336d 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsSymbolicLink_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsSymbolicLink_Test.java @@ -12,52 +12,56 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeSymbolicLink.shouldBeSymbolicLink; import static org.assertj.core.error.ShouldExist.shouldExistNoFollowLinks; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.nio.file.LinkOption; +import java.io.IOException; +import java.nio.file.Path; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertIsSymbolicLink_Test extends MockPathsBaseTest { +class Paths_assertIsSymbolicLink_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsSymbolicLink(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsSymbolicLink(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual, LinkOption.NOFOLLOW_LINKS)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsSymbolicLink(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExistNoFollowLinks(actual)); + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsSymbolicLink(info, actual)); + // THEN + then(error).hasMessage(shouldExistNoFollowLinks(actual).create()); } @Test - void should_fail_if_actual_exists_but_is_not_a_symbolic_link() { - when(nioFilesWrapper.exists(actual, LinkOption.NOFOLLOW_LINKS)).thenReturn(true); - when(nioFilesWrapper.isSymbolicLink(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsSymbolicLink(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeSymbolicLink(actual)); + void should_fail_if_actual_is_not_a_symbolic_link() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsSymbolicLink(info, actual)); + // THEN + then(error).hasMessage(shouldBeSymbolicLink(actual).create()); } @Test - void should_succeed_if_actual_is_a_symbolic_link() { - when(nioFilesWrapper.exists(actual, LinkOption.NOFOLLOW_LINKS)).thenReturn(true); - when(nioFilesWrapper.isSymbolicLink(actual)).thenReturn(true); + void should_succeed_if_actual_is_a_symbolic_link() throws IOException { + // GIVEN + Path actual = createSymbolicLink(tempDir.resolve("actual"), tempDir.resolve("target")); + // WHEN/THEN paths.assertIsSymbolicLink(info, actual); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsWritable_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsWritable_Test.java index c7bb1221d4c..5fc64c4ce09 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsWritable_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsWritable_Test.java @@ -12,50 +12,55 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeWritable.shouldBeWritable; import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertIsWritable_Test extends MockPathsBaseTest { +class Paths_assertIsWritable_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertIsWritable(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsWritable(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_with_should_exist_error_if_actual_does_not_exist() { - when(nioFilesWrapper.exists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsWritable(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldExist(actual)); + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsWritable(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); } @Test - void should_fail_if_actual_exists_but_is_not_writable() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isWritable(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertIsWritable(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeWritable(actual)); + void should_fail_if_actual_is_not_writable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + actual.toFile().setWritable(false); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsWritable(info, actual)); + // THEN + then(error).hasMessage(shouldBeWritable(actual).create()); } @Test - void should_succeed_if_actual_exist_and_is_writable() { - when(nioFilesWrapper.exists(actual)).thenReturn(true); - when(nioFilesWrapper.isWritable(actual)).thenReturn(true); + void should_pass_if_actual_is_writable() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN/THEN paths.assertIsWritable(info, actual); } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertNotExists_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertNotExists_Test.java index 2255b74b618..2d523563b49 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertNotExists_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertNotExists_Test.java @@ -12,40 +12,56 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldNotExist.shouldNotExist; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.nio.file.LinkOption; +import java.io.IOException; +import java.nio.file.Path; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertNotExists_Test extends MockPathsBaseTest { +class Paths_assertNotExists_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertDoesNotExist(info, null)) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertDoesNotExist(info, null)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_actual_exists() { - when(nioFilesWrapper.notExists(actual)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertDoesNotExist(info, actual)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldNotExist(actual)); + void should_fail_if_actual_exists() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertDoesNotExist(info, actual)); + // THEN + then(error).hasMessage(shouldNotExist(actual).create()); } @Test - void should_pass_if_actual_does_not_exists() { - when(nioFilesWrapper.notExists(actual, LinkOption.NOFOLLOW_LINKS)).thenReturn(true); + void should_pass_if_actual_does_not_exist() throws IOException { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN/THEN paths.assertDoesNotExist(info, actual); } + @Test + void should_fail_if_actual_is_a_symbolic_link_and_target_does_not_exist() throws IOException { + // GIVEN + Path target = tempDir.resolve("non-existent"); + Path actual = createSymbolicLink(tempDir.resolve("actual"), target); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertDoesNotExist(info, actual)); + // THEN + then(error).hasMessage(shouldNotExist(actual).create()); + } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWithRaw_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWithRaw_Test.java index b0ad798c082..15bc272bb7a 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWithRaw_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWithRaw_Test.java @@ -12,46 +12,86 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldStartWithPath.shouldStartWith; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertStartsWithRaw_Test extends MockPathsBaseTest { +class Paths_assertStartsWithRaw_Test extends PathsBaseTest { @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertStartsWithRaw(info, null, other)) - .withMessage(actualIsNull()); + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + Path other = createFile(tempDir.resolve("other")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertStartsWithRaw(info, null, other)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_other_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertStartsWithRaw(info, actual, null)) - .withMessage("the expected start path should not be null"); + void should_fail_if_other_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertStartsWithRaw(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("the expected start path should not be null"); } @Test - void should_fail_if_actual_does_not_start_with_other() { - // This is the default, but let's make this explicit - when(actual.startsWith(other)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertStartsWithRaw(info, actual, other)); + void should_fail_if_actual_does_not_start_with_other() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = createFile(tempDir.resolve("other")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertStartsWithRaw(info, actual, other)); + // THEN + then(error).hasMessage(shouldStartWith(actual, other).create()); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldStartWith(actual, other)); + @Test + void should_pass_if_actual_starts_with_other() throws IOException { + // GIVEN + Path other = createDirectory(tempDir.resolve("other")).toRealPath(); + Path actual = createFile(other.resolve("actual")).toRealPath(); + // WHEN/THEN + paths.assertStartsWithRaw(info, actual, other); } @Test - void should_succeed_if_actual_starts_with_other() { - when(actual.startsWith(other)).thenReturn(true); + void should_fail_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path other = createDirectory(tempDir.resolve("other")); + Path file = createFile(other.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertStartsWithRaw(info, actual, other)); + // THEN + then(error).hasMessage(shouldStartWith(actual, other).create()); + } - paths.assertStartsWithRaw(info, actual, other); + @Test + void should_fail_if_other_is_not_canonical() throws IOException { + // GIVEN + Path directory = createDirectory(tempDir.resolve("directory")); + Path other = createSymbolicLink(tempDir.resolve("other"), directory); + Path actual = createFile(directory.resolve("actual")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertStartsWithRaw(info, actual, other)); + // THEN + then(error).hasMessage(shouldStartWith(actual, other).create()); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWith_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWith_Test.java index 09fc59ad0fd..a4ea502fecd 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWith_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertStartsWith_Test.java @@ -12,89 +12,112 @@ */ package org.assertj.core.internal.paths; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; -import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static java.nio.file.Files.createSymbolicLink; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldStartWithPath.shouldStartWith; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Path; -import org.assertj.core.api.exception.PathsException; -import org.junit.jupiter.api.BeforeEach; +import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; -class Paths_assertStartsWith_Test extends MockPathsBaseTest { - - private Path canonicalActual; - private Path canonicalOther; - - @Override - @BeforeEach - public void init() { - super.init(); - canonicalActual = mock(Path.class); - canonicalOther = mock(Path.class); - } +class Paths_assertStartsWith_Test extends PathsBaseTest { @Test - void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertStartsWith(info, null, other)) - .withMessage(actualIsNull()); + void should_fail_if_actual_is_null() throws IOException { + // GIVEN + Path other = createFile(tempDir.resolve("other")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertStartsWith(info, null, other)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_other_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertStartsWith(info, actual, null)) - .withMessage("the expected start path should not be null"); + void should_fail_if_other_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertStartsWith(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("the expected start path should not be null"); } @Test - void should_throw_PathsException_if_actual_cannot_be_resolved() throws IOException { - final IOException exception = new IOException(); - when(actual.toRealPath()).thenThrow(exception); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertStartsWith(info, actual, other)) - .withMessage("failed to resolve actual real path") - .withCause(exception); + void should_rethrow_IOException_as_UncheckedIOException_if_actual_cannot_be_resolved() throws IOException { + // GIVEN + Path actual = mock(Path.class); + Path other = createFile(tempDir.resolve("other")); + IOException exception = new IOException("boom!"); + given(actual.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertStartsWith(info, actual, other)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test - void should_throw_PathsException_if_other_cannot_be_resolved() throws IOException { - final IOException exception = new IOException(); - when(actual.toRealPath()).thenReturn(canonicalActual); - when(other.toRealPath()).thenThrow(exception); - - assertThatExceptionOfType(PathsException.class).isThrownBy(() -> paths.assertStartsWith(info, actual, other)) - .withMessage("failed to resolve argument real path") - .withCause(exception); + void should_rethrow_IOException_as_UncheckedIOException_if_other_cannot_be_resolved() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = mock(Path.class); + IOException exception = new IOException("boom!"); + given(other.toRealPath()).willThrow(exception); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertStartsWith(info, actual, other)); + // THEN + then(thrown).isInstanceOf(UncheckedIOException.class) + .hasCause(exception); } @Test void should_fail_if_actual_does_not_start_with_other() throws IOException { - when(actual.toRealPath()).thenReturn(canonicalActual); - when(other.toRealPath()).thenReturn(canonicalOther); - // This is the default, but let's make this explicit - when(canonicalActual.startsWith(canonicalOther)).thenReturn(false); - - Throwable error = catchThrowable(() -> paths.assertStartsWith(info, actual, other)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldStartWith(actual, other)); + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + Path other = createFile(tempDir.resolve("other")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertStartsWith(info, actual, other)); + // THEN + then(error).hasMessage(shouldStartWith(actual, other).create()); } @Test - void should_succeed_if_actual_starts_with_other() throws IOException { - when(actual.toRealPath()).thenReturn(canonicalActual); - when(other.toRealPath()).thenReturn(canonicalOther); + void should_pass_if_actual_starts_with_other() throws IOException { + // GIVEN + Path other = createDirectory(tempDir.resolve("other")).toRealPath(); + Path actual = createFile(other.resolve("actual")).toRealPath(); + // WHEN/THEN + paths.assertStartsWith(info, actual, other); + } - when(canonicalActual.startsWith(canonicalOther)).thenReturn(true); + @Test + void should_pass_if_actual_is_not_canonical() throws IOException { + // GIVEN + Path other = createDirectory(tempDir.resolve("other")); + Path file = createFile(other.resolve("file")); + Path actual = createSymbolicLink(tempDir.resolve("actual"), file); + // WHEN/THEN + paths.assertStartsWith(info, actual, other); + } + @Test + void should_pass_if_other_is_not_canonical() throws IOException { + // GIVEN + Path directory = createDirectory(tempDir.resolve("directory")); + Path other = createSymbolicLink(tempDir.resolve("other"), directory); + Path actual = createFile(directory.resolve("actual")); + // WHEN/THEN paths.assertStartsWith(info, actual, other); } From 396cdad234625127a3bef97bf3f4b3646cb74450 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 16 Aug 2021 08:43:24 +0200 Subject: [PATCH 066/123] Invert stubbing calls for `Path` assertion tests See #2312. --- .../internal/paths/Paths_assertHasBinaryContent_Test.java | 5 ++--- ...rtHasDigest_with_MessageDigest_and_Byte_array_Test.java | 5 ++--- ...assertHasDigest_with_MessageDigest_and_String_Test.java | 5 ++--- ...hs_assertHasDigest_with_String_and_Byte_array_Test.java | 5 ++--- .../Paths_assertHasDigest_with_String_and_String_Test.java | 5 ++--- .../paths/Paths_assertHasSameBinaryContentAs_Test.java | 5 ++--- .../paths/Paths_assertHasSameTextualContentAs_Test.java | 5 ++--- .../internal/paths/Paths_assertHasTextualContent_Test.java | 5 ++--- .../internal/paths/Paths_assertIsEmptyDirectory_Test.java | 7 +++---- .../paths/Paths_assertIsNotEmptyDirectory_Test.java | 7 +++---- 10 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java index cc37542e406..bbae9c30472 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasBinaryContent_Test.java @@ -21,7 +21,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -102,13 +102,12 @@ void should_fail_if_actual_does_not_have_expected_binary_content() throws IOExce } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN Path actual = createFile(tempDir.resolve("actual")); byte[] expected = "expected".getBytes(); IOException exception = new IOException("boom!"); - given(binaryDiff.diff(actual, expected)).willThrow(exception); + willThrow(exception).given(binaryDiff).diff(actual, expected); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasBinaryContent(info, actual, expected)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java index cb8ac785405..e8b1c414be0 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_Byte_array_Test.java @@ -25,7 +25,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -121,14 +121,13 @@ void should_fail_if_actual_is_not_readable() throws Exception { } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws Exception { // GIVEN Path actual = createFile(tempDir.resolve("actual")); MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] expected = {}; IOException cause = new IOException("boom!"); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + willThrow(cause).given(nioFilesWrapper).newInputStream(actual); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java index 8037ac36ebd..c9f4d678df5 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_MessageDigest_and_String_Test.java @@ -25,7 +25,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -121,14 +121,13 @@ void should_fail_if_actual_is_not_readable() throws Exception { } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws Exception { // GIVEN Path actual = createFile(tempDir.resolve("actual")); MessageDigest digest = MessageDigest.getInstance("MD5"); String expected = ""; IOException cause = new IOException("boom!"); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + willThrow(cause).given(nioFilesWrapper).newInputStream(actual); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, digest, expected)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java index 46722a9c595..d22269131c8 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_Byte_array_Test.java @@ -25,7 +25,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -135,14 +135,13 @@ void should_fail_if_actual_is_not_readable() throws IOException { } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws Exception { // GIVEN Path actual = createFile(tempDir.resolve("actual")); String algorithm = "MD5"; byte[] expected = {}; IOException cause = new IOException("boom!"); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + willThrow(cause).given(nioFilesWrapper).newInputStream(actual); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java index c7f207c03f0..eabf21b257b 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasDigest_with_String_and_String_Test.java @@ -25,7 +25,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -135,14 +135,13 @@ void should_fail_if_actual_is_not_readable() throws IOException { } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws Exception { // GIVEN Path actual = createFile(tempDir.resolve("actual")); String algorithm = "MD5"; String expected = ""; IOException cause = new IOException("boom!"); - given(nioFilesWrapper.newInputStream(actual)).willThrow(cause); + willThrow(cause).given(nioFilesWrapper).newInputStream(actual); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasDigest(info, actual, algorithm, expected)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java index c3a5eeb2b40..882e114af71 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameBinaryContentAs_Test.java @@ -21,7 +21,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -145,13 +145,12 @@ void should_fail_if_actual_does_not_have_the_same_binary_content_as_expected(Str } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN Path actual = Files.write(tempDir.resolve("actual"), "Content".getBytes()); Path expected = Files.write(tempDir.resolve("expected"), "Content".getBytes()); IOException exception = new IOException("boom!"); - given(binaryDiff.diff(actual, "Content".getBytes())).willThrow(exception); + willThrow(exception).given(binaryDiff).diff(actual, "Content".getBytes()); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasSameBinaryContentAs(info, actual, expected)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java index 9f1dafe7cb0..6f28d31507c 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasSameTextualContentAs_Test.java @@ -22,7 +22,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -153,13 +153,12 @@ void should_fail_if_actual_does_not_have_the_same_content_as_expected(String act } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN Path actual = createFile(tempDir.resolve("actual")); Path expected = createFile(tempDir.resolve("expected")); IOException exception = new IOException("boom!"); - given(diff.diff(actual, CHARSET, expected, CHARSET)).willThrow(exception); + willThrow(exception).given(diff).diff(actual, CHARSET, expected, CHARSET); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasSameTextualContentAs(info, actual, CHARSET, expected, CHARSET)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java index 32827fedc81..d20d6b83693 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasTextualContent_Test.java @@ -22,7 +22,7 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; import java.io.IOException; import java.io.UncheckedIOException; @@ -111,13 +111,12 @@ void should_fail_if_actual_does_not_have_expected_textual_content() throws IOExc } @Test - @DisabledOnOs(value = WINDOWS, disabledReason = "gh-2312") void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN Path actual = createFile(tempDir.resolve("actual")); String expected = "expected"; IOException exception = new IOException("boom!"); - given(diff.diff(actual, expected, CHARSET)).willThrow(exception); + willThrow(exception).given(diff).diff(actual, expected, CHARSET); // WHEN Throwable thrown = catchThrowable(() -> paths.assertHasTextualContent(info, actual, expected, CHARSET)); // THEN diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java index 50e829d721f..14beb118d84 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsEmptyDirectory_Test.java @@ -23,7 +23,6 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.willThrow; import java.io.IOException; @@ -89,13 +88,13 @@ void should_fail_if_actual_is_not_empty() throws IOException { void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); - IOException exception = new IOException("boom!"); - willThrow(exception).given(nioFilesWrapper).newDirectoryStream(eq(actual), any()); + IOException cause = new IOException("boom!"); + willThrow(cause).given(nioFilesWrapper).newDirectoryStream(any(), any()); // WHEN Throwable thrown = catchThrowable(() -> paths.assertIsEmptyDirectory(info, actual)); // THEN then(thrown).isInstanceOf(UncheckedIOException.class) - .hasCause(exception); + .hasCause(cause); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java index 77f4efdc732..b1a8dd08926 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsNotEmptyDirectory_Test.java @@ -22,7 +22,6 @@ import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.willThrow; import java.io.IOException; @@ -88,13 +87,13 @@ void should_fail_if_actual_is_empty() throws IOException { void should_rethrow_IOException_as_UncheckedIOException() throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); - IOException exception = new IOException("boom!"); - willThrow(exception).given(nioFilesWrapper).newDirectoryStream(eq(actual), any()); + IOException cause = new IOException("boom!"); + willThrow(cause).given(nioFilesWrapper).newDirectoryStream(any(), any()); // WHEN Throwable thrown = catchThrowable(() -> paths.assertIsNotEmptyDirectory(info, actual)); // THEN then(thrown).isInstanceOf(UncheckedIOException.class) - .hasCause(exception); + .hasCause(cause); } } From a0624b452560973f2e5c80a7b93b57a459fa2f71 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 16 Aug 2021 09:12:00 +0200 Subject: [PATCH 067/123] Sync `BDDAssumptions` with `Assumptions` (#2313) --- .../org/assertj/core/api/Assumptions.java | 1 + .../org/assertj/core/api/BDDAssumptions.java | 45 ++++++++++++-- ..._is_in_sync_with_WithAssumptions_Test.java | 52 ---------------- .../core/api/Assumptions_sync_Test.java | 61 +++++++++++++++++++ 4 files changed, 102 insertions(+), 57 deletions(-) delete mode 100644 src/test/java/org/assertj/core/api/Assumptions_is_in_sync_with_WithAssumptions_Test.java create mode 100644 src/test/java/org/assertj/core/api/Assumptions_sync_Test.java diff --git a/src/main/java/org/assertj/core/api/Assumptions.java b/src/main/java/org/assertj/core/api/Assumptions.java index 767ea6c880f..6f594b3a71b 100644 --- a/src/main/java/org/assertj/core/api/Assumptions.java +++ b/src/main/java/org/assertj/core/api/Assumptions.java @@ -899,6 +899,7 @@ public static > AbstractComparableAssert a /** * Creates a new instance of {@link ThrowableAssert} assumption. * + * @param the type of actual. * @param actual the actual value. * @return the created assumption for assertion object. * @since 2.9.0 / 3.9.0 diff --git a/src/main/java/org/assertj/core/api/BDDAssumptions.java b/src/main/java/org/assertj/core/api/BDDAssumptions.java index 066ac6aceea..e6c34861733 100644 --- a/src/main/java/org/assertj/core/api/BDDAssumptions.java +++ b/src/main/java/org/assertj/core/api/BDDAssumptions.java @@ -66,6 +66,7 @@ import java.util.stream.Stream; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.assertj.core.configuration.PreferredAssumptionException; import org.assertj.core.util.CheckReturnValue; /** @@ -1383,10 +1384,8 @@ public static ObjectAssert givenObject(T actual) { * @return the {@link AbstractComparableAssert} assertion object to be used for validation. * @since 3.14.0 */ - @SuppressWarnings("unchecked") - public static > AbstractComparableAssert given(Comparable actual) { - // cast needed to call AbstractComparableAssert assumeThat(T actual) - return assumeThat((T) actual); + public static > AbstractComparableAssert given(T actual) { + return assumeThat(actual); } /** @@ -1410,11 +1409,12 @@ public static > AbstractComparableAssert g * // ... *} * + * @param the type of the actual throwable. * @param actual the actual {@link Throwable} value to be validated. * @return the {@link AbstractThrowableAssert} assertion object to be used for validation. * @since 3.14.0 */ - public static AbstractThrowableAssert given(Throwable actual) { + public static AbstractThrowableAssert given(T actual) { return assumeThat(actual); } @@ -2874,4 +2874,39 @@ public static AbstractUriAssert given(URI actual) { public static AbstractUrlAssert given(URL actual) { return assumeThat(actual); } + + /** + * Sets which exception is thrown if an assumption is not met. + *

+ * This method is useful if you are using a testing framework that supports assumptions and expect a specific exception to be thrown when an assumption is not met. + *

+ * You can choose one of: + *

    + *
  • {@link PreferredAssumptionException#TEST_NG} to throw a {@code org.testng.SkipException} if you are using TestNG
  • + *
  • {@link PreferredAssumptionException#JUNIT4} to throw a {@code org.junit.AssumptionViolatedException} if you are using JUnit 4
  • + *
  • {@link PreferredAssumptionException#JUNIT5} a {@code org.opentest4j.TestAbortedException} if you are using JUnit 5
  • + *
  • {@link PreferredAssumptionException#AUTO_DETECT} to get the default behavior where AssertJ tries different exception (explained later on)
  • + *
+ *

+ * Make sure that the exception you choose can be found in the classpath otherwise AssertJ will throw an {@link IllegalStateException}. + *

+ * For example JUnit4 expects {@code org.junit.AssumptionViolatedException}, you can tell AssertJ to use it as shown below: + *

 // after this call, AssertJ will throw an org.junit.AssumptionViolatedException when an assumption is not met
+   * Assertions.setPreferredAssumptionExceptions(PreferredAssumptionException.JUNIT4);
+   * 
+ *

+ * By default, AssertJ uses the {@link PreferredAssumptionException#AUTO_DETECT AUTO_DETECT} mode and tries to throw one of the following exceptions, in this order: + *

    + *
  1. {@code org.testng.SkipException} for TestNG (if available in the classpath)
  2. + *
  3. {@code org.junit.AssumptionViolatedException} for JUnit 4 (if available in the classpath)
  4. + *
  5. {@code org.opentest4j.TestAbortedException} for JUnit 5
  6. + *
+ * + * @param preferredAssumptionException the preferred exception to use with {@link Assumptions}. + * @since 3.21.0 + */ + public static void setPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException) { + Assumptions.setPreferredAssumptionException(preferredAssumptionException); + } + } diff --git a/src/test/java/org/assertj/core/api/Assumptions_is_in_sync_with_WithAssumptions_Test.java b/src/test/java/org/assertj/core/api/Assumptions_is_in_sync_with_WithAssumptions_Test.java deleted file mode 100644 index efd37c8acff..00000000000 --- a/src/test/java/org/assertj/core/api/Assumptions_is_in_sync_with_WithAssumptions_Test.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright 2012-2021 the original author or authors. - */ -package org.assertj.core.api; - -import static java.lang.reflect.Modifier.isPublic; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.toSet; -import static org.assertj.core.api.BDDAssertions.then; - -import java.lang.reflect.Method; -import java.util.Set; - -import org.junit.jupiter.api.Test; - -class Assumptions_is_in_sync_with_WithAssumptions_Test extends BaseAssertionsTest { - - @Test - void standard_assumptions_and_with_assumptions_should_have_the_same_assumptions_methods() { - Method[] assumeThat_Assumptions_methods = findMethodsWithName(Assumptions.class, "assumeThat"); - Method[] assumeThat_WithAssumptions_methods = findMethodsWithName(WithAssumptions.class, "assumeThat"); - - then(assumeThat_WithAssumptions_methods).usingElementComparator(IGNORING_DECLARING_CLASS_ONLY) - .containsExactlyInAnyOrder(assumeThat_Assumptions_methods); - } - - @Test - void standard_assumptions_and_with_assumptions_should_have_the_same_non_assumptions_methods() { - - Set non_assumeThat_public_Assumptions_methods = non_assumeThat_public_methodsOf(Assumptions.class.getDeclaredMethods()); - Set non_assumeThat_public_WithAssumptions_methods = non_assumeThat_public_methodsOf(WithAssumptions.class.getDeclaredMethods()); - - then(non_assumeThat_public_WithAssumptions_methods).usingElementComparator(IGNORING_DECLARING_CLASS_ONLY) - .containsExactlyInAnyOrderElementsOf(non_assumeThat_public_Assumptions_methods); - } - - private static Set non_assumeThat_public_methodsOf(Method[] declaredMethods) { - return stream(declaredMethods).filter(method -> !method.getName().startsWith("assume")) - .filter(method -> isPublic(method.getModifiers())) - .collect(toSet()); - } - -} diff --git a/src/test/java/org/assertj/core/api/Assumptions_sync_Test.java b/src/test/java/org/assertj/core/api/Assumptions_sync_Test.java new file mode 100644 index 00000000000..7c574b0a6d8 --- /dev/null +++ b/src/test/java/org/assertj/core/api/Assumptions_sync_Test.java @@ -0,0 +1,61 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api; + +import static java.util.Arrays.stream; +import static java.util.stream.Collectors.toSet; +import static org.assertj.core.api.BDDAssertions.then; + +import java.lang.reflect.Method; +import java.util.Set; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class Assumptions_sync_Test extends BaseAssertionsTest { + + @ParameterizedTest + @CsvSource({ + "org.assertj.core.api.Assumptions, assumeThat", + "org.assertj.core.api.BDDAssumptions, given", + }) + void should_have_the_same_assumptions_public_methods(Class target, String methodName) { + // GIVEN + Method[] assumeThat_Assumptions_methods = findMethodsWithName(Assumptions.class, "assumeThat"); + // THEN + Method[] assumeThat_BDDAssumptions_methods = findMethodsWithName(target, methodName); + // THEN + then(assumeThat_BDDAssumptions_methods).usingElementComparator(IGNORING_DECLARING_CLASS_AND_METHOD_NAME) + .containsExactlyInAnyOrder(assumeThat_Assumptions_methods); + } + + @ParameterizedTest + @CsvSource({ + "org.assertj.core.api.Assumptions, assume", + "org.assertj.core.api.BDDAssumptions, given", + }) + void should_have_the_same_non_assumptions_public_methods(Class target, String excludePrefix) { + // GIVEN + Set expected_methods = findMethodsWithNameStartingWithout(Assumptions.class, "assume"); + // WHEN + Set methods = findMethodsWithNameStartingWithout(target, excludePrefix); + // THEN + then(methods).usingElementComparator(IGNORING_DECLARING_CLASS_ONLY) + .containsExactlyInAnyOrderElementsOf(expected_methods); + } + + private static Set findMethodsWithNameStartingWithout(Class clazz, String excludePrefix) { + return stream(clazz.getMethods()).filter(method -> !method.getName().startsWith(excludePrefix)).collect(toSet()); + } + +} From d57ae304386a84817cf1613d3ff2f02c69c727f5 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 16 Aug 2021 10:22:54 +0200 Subject: [PATCH 068/123] Typo --- src/main/java/org/assertj/core/api/BDDAssumptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/assertj/core/api/BDDAssumptions.java b/src/main/java/org/assertj/core/api/BDDAssumptions.java index e6c34861733..5e594e59c9e 100644 --- a/src/main/java/org/assertj/core/api/BDDAssumptions.java +++ b/src/main/java/org/assertj/core/api/BDDAssumptions.java @@ -2902,7 +2902,7 @@ public static AbstractUrlAssert given(URL actual) { *
  • {@code org.opentest4j.TestAbortedException} for JUnit 5
  • * * - * @param preferredAssumptionException the preferred exception to use with {@link Assumptions}. + * @param preferredAssumptionException the preferred exception to use with {@link BDDAssumptions}. * @since 3.21.0 */ public static void setPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException) { From 6ff56aeaeed5f3f585557010e6572d0977c3e7cf Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 18 Aug 2021 08:25:24 +0200 Subject: [PATCH 069/123] Fix javadoc warnings --- src/main/java/org/assertj/core/api/Assertions.java | 1 + .../java/org/assertj/core/api/AssertionsForClassTypes.java | 3 ++- src/main/java/org/assertj/core/api/Assumptions.java | 4 ++-- src/main/java/org/assertj/core/api/BDDAssertions.java | 1 + src/main/java/org/assertj/core/api/Java6Assertions.java | 1 + src/main/java/org/assertj/core/api/Java6BDDAssertions.java | 1 + .../org/assertj/core/api/Java6BDDSoftAssertionsProvider.java | 1 + .../assertj/core/api/Java6StandardSoftAssertionsProvider.java | 1 + src/main/java/org/assertj/core/api/WithAssertions.java | 1 + src/main/java/org/assertj/core/error/ShouldHaveSize.java | 1 + 10 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/assertj/core/api/Assertions.java b/src/main/java/org/assertj/core/api/Assertions.java index 5fd0e846d90..b719a21a58e 100644 --- a/src/main/java/org/assertj/core/api/Assertions.java +++ b/src/main/java/org/assertj/core/api/Assertions.java @@ -1141,6 +1141,7 @@ public static AtomicStampedReferenceAssert assertThat(AtomicStamp /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ diff --git a/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java b/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java index a6d7ec4f65c..8eae7f397fc 100644 --- a/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java +++ b/src/main/java/org/assertj/core/api/AssertionsForClassTypes.java @@ -691,6 +691,7 @@ public static AbstractPeriodAssert assertThat(Period period) { /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ @@ -795,7 +796,7 @@ public static ThrowableTypeAssert assertThatExceptionOf *
    assertThatNoException().isThrownBy(() -> { System.out.println("OK"); });
    * * This method is more or less the same of {@code assertThatCode(...).doesNotThrowAnyException();} but in a more natural way. - + * @return the created {@link NotThrownAssert}. * @since 3.17.0 */ diff --git a/src/main/java/org/assertj/core/api/Assumptions.java b/src/main/java/org/assertj/core/api/Assumptions.java index 6f594b3a71b..ec2cb82bd37 100644 --- a/src/main/java/org/assertj/core/api/Assumptions.java +++ b/src/main/java/org/assertj/core/api/Assumptions.java @@ -899,7 +899,7 @@ public static > AbstractComparableAssert a /** * Creates a new instance of {@link ThrowableAssert} assumption. * - * @param the type of actual. + * @param the type of the actual throwable. * @param actual the actual value. * @return the created assumption for assertion object. * @since 2.9.0 / 3.9.0 @@ -1291,7 +1291,7 @@ public static AbstractSpliteratorAssert assumeThat(Spliter public static void setPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException) { AssumptionExceptionFactory.setPreferredAssumptionException(preferredAssumptionException); } - + // private methods private static ASSERTION asAssumption(Class assertionType, diff --git a/src/main/java/org/assertj/core/api/BDDAssertions.java b/src/main/java/org/assertj/core/api/BDDAssertions.java index be6a7ec3eab..3d2080e6d33 100644 --- a/src/main/java/org/assertj/core/api/BDDAssertions.java +++ b/src/main/java/org/assertj/core/api/BDDAssertions.java @@ -1145,6 +1145,7 @@ public static AtomicStampedReferenceAssert then(AtomicStampedRefe /** * Creates a new instance of {@link org.assertj.core.api.ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created assertion Throwable. */ diff --git a/src/main/java/org/assertj/core/api/Java6Assertions.java b/src/main/java/org/assertj/core/api/Java6Assertions.java index 1c035eb01fe..9d567265254 100644 --- a/src/main/java/org/assertj/core/api/Java6Assertions.java +++ b/src/main/java/org/assertj/core/api/Java6Assertions.java @@ -1033,6 +1033,7 @@ public static AbstractDateAssert assertThat(Date actual) { /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ diff --git a/src/main/java/org/assertj/core/api/Java6BDDAssertions.java b/src/main/java/org/assertj/core/api/Java6BDDAssertions.java index c0e13b2f651..01a197f2ec4 100644 --- a/src/main/java/org/assertj/core/api/Java6BDDAssertions.java +++ b/src/main/java/org/assertj/core/api/Java6BDDAssertions.java @@ -903,6 +903,7 @@ public static AbstractDateAssert then(Date actual) { /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created assertion Throwable. */ diff --git a/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java b/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java index cc379b6b302..910b92aef0c 100644 --- a/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java +++ b/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java @@ -752,6 +752,7 @@ default AtomicStampedReferenceAssert then(AtomicStampedReference< /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created assertion Throwable. */ diff --git a/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java b/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java index 4d220806adf..f478124b6c8 100644 --- a/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java +++ b/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java @@ -750,6 +750,7 @@ default AtomicStampedReferenceAssert assertThat(AtomicStampedRefe /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created assertion Throwable. */ diff --git a/src/main/java/org/assertj/core/api/WithAssertions.java b/src/main/java/org/assertj/core/api/WithAssertions.java index 888a85145d8..c57501ec468 100644 --- a/src/main/java/org/assertj/core/api/WithAssertions.java +++ b/src/main/java/org/assertj/core/api/WithAssertions.java @@ -413,6 +413,7 @@ default AbstractDateAssert assertThat(final Date actual) { /** * Creates a new instance of {@link ThrowableAssert}. * + * @param the type of the actual throwable. * @param actual the actual value. * @return the created {@link ThrowableAssert}. */ diff --git a/src/main/java/org/assertj/core/error/ShouldHaveSize.java b/src/main/java/org/assertj/core/error/ShouldHaveSize.java index 492b0a3910e..8189a39fa62 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveSize.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveSize.java @@ -97,6 +97,7 @@ private ShouldHaveSize(File actual, long expectedSize) { * @param actual The actual path file in the failed assertion * @param expectedSize The expected size of the path file * @return the created {@code ErrorMessageFactory} + * @throws IOException if an I/O error occurs */ public static ErrorMessageFactory shouldHaveSize(Path actual, long expectedSize) throws IOException { return new ShouldHaveSize(actual, expectedSize); From ca3ba6311bc3fbb96243f15de9da2bfaa24bbfb3 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 18 Aug 2021 22:19:34 +0200 Subject: [PATCH 070/123] Fix javadoc warning --- .../java/org/assertj/core/api/WithAssumptions.java | 1 + ...hrowableAssert_extracting_with_Function_Test.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/org/assertj/core/api/WithAssumptions.java b/src/main/java/org/assertj/core/api/WithAssumptions.java index 3e7214966df..9bf1f421d6e 100644 --- a/src/main/java/org/assertj/core/api/WithAssumptions.java +++ b/src/main/java/org/assertj/core/api/WithAssumptions.java @@ -206,6 +206,7 @@ default AbstractDateAssert assumeThat(final Date actual) { /** * Creates a new instance of {@link ThrowableAssert} assumption. * + * @param the type of the actual value. * @param actual the actual value. * @return the created assumption for assertion object. * @since 2.9.0 / 3.9.0 diff --git a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java index 4e53179cb6d..fd08d1e3995 100644 --- a/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java +++ b/src/test/java/org/assertj/core/api/throwable/ThrowableAssert_extracting_with_Function_Test.java @@ -1,3 +1,15 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ package org.assertj.core.api.throwable; import static org.assertj.core.api.Assertions.assertThat; From 4a4e7c8580df2bb7ad1cfd61035c2b561c4ac7b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Aug 2021 23:35:39 +0200 Subject: [PATCH 071/123] Bump byte-buddy.version from 1.11.12 to 1.11.13 (#2317) Bumps `byte-buddy.version` from 1.11.12 to 1.11.13. Updates `byte-buddy` from 1.11.12 to 1.11.13 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.12...byte-buddy-1.11.13) Updates `byte-buddy-agent` from 1.11.12 to 1.11.13 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.12...byte-buddy-1.11.13) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 39f763c3a07..5edd3db775f 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ -html5 --allow-script-in-comments --no-module-directories - 1.11.12 + 1.11.13 2.2 1.2.0 5.3.0 From 80558e5f28d739d15ef81a66a48b2d498252b840 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Fri, 20 Aug 2021 00:00:06 +0200 Subject: [PATCH 072/123] Bump mockito.version from 3.11.2 to 3.12.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5edd3db775f..86cdb047b71 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 4.13.2 5.7.2 - 3.11.2 + 3.12.0 0.8.7 From b606cae91ccd13b43d9176c3a7f2dedbb2a60cf9 Mon Sep 17 00:00:00 2001 From: Szymon Linowski Date: Fri, 20 Aug 2021 01:10:25 +0200 Subject: [PATCH 073/123] Add `hasExtension` to `Path` assertions (#2255) --- .../assertj/core/api/AbstractPathAssert.java | 29 ++++- .../core/error/ShouldHaveExtension.java | 23 +++- .../java/org/assertj/core/internal/Paths.java | 20 +++- .../path/PathAssert_hasExtension_Test.java | 32 +++++ .../ShouldHaveExtension_create_Test.java | 81 +++++++++---- .../paths/Paths_assertHasExtension_Test.java | 112 ++++++++++++++++++ 6 files changed, 269 insertions(+), 28 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/path/PathAssert_hasExtension_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index a6ceeec132d..a7503e0f0a9 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -1895,7 +1895,7 @@ public AbstractStringAssert content(Charset charset) { return internalContent(charset); } - // this method was introduced to avoid to avoid double proxying in soft assertions for content() + // this method was introduced to avoid double proxying in soft assertions for content() private AbstractStringAssert internalContent(Charset charset) { paths.assertIsReadable(info, actual); String pathContent = readPath(charset); @@ -1909,4 +1909,31 @@ private String readPath(Charset charset) { throw new UncheckedIOException(format("Failed to read %s content with %s charset", actual, charset), e); } } + + /** + * Verifies that the actual {@code Path} has given extension. + * + *

    + * Example: + *

     Path path = Paths.get("file.java");
    +   *
    +   * // assertion will pass
    +   * assertThat(path).hasExtension("java");
    +   *
    +   * // assertion will fail
    +   * assertThat(path).hasExtension("png");
    + * + * @param expected the expected extension, without the {@code '.'}. + * @return {@code this} assertion object. + * @throws NullPointerException if the expected extension is {@code null}. + * @throws AssertionError if the actual {@code Path} is {@code null}. + * @throws AssertionError if the actual {@code Path} is not a regular file. + * @throws AssertionError if the actual {@code Path} does not have the expected extension. + * @since 3.21.0 + */ + public SELF hasExtension(String expected) { + paths.assertHasExtension(info, actual, expected); + return myself; + } + } diff --git a/src/main/java/org/assertj/core/error/ShouldHaveExtension.java b/src/main/java/org/assertj/core/error/ShouldHaveExtension.java index 58917f44f7a..f06fdf257a5 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveExtension.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveExtension.java @@ -13,25 +13,38 @@ package org.assertj.core.error; import java.io.File; +import java.nio.file.Path; +import java.util.Objects; /** - * Creates an error message indicating that a {@code File} should have extension. + * Creates an error message indicating that a {@code File} or a {@code Path} should have extension. * * @author Jean-Christophe Gay */ public class ShouldHaveExtension extends BasicErrorMessageFactory { public static ShouldHaveExtension shouldHaveExtension(File actual, String actualExtension, String expectedExtension) { - return actualExtension == null ? new ShouldHaveExtension(actual, expectedExtension) : new ShouldHaveExtension( - actual, actualExtension, expectedExtension); + return actualExtension == null + ? new ShouldHaveExtension(actual, expectedExtension) + : new ShouldHaveExtension(actual, actualExtension, expectedExtension); } - private ShouldHaveExtension(File actual, String actualExtension, String expectedExtension) { + public static ShouldHaveExtension shouldHaveExtension(Path actual, String actualExtension, String expectedExtension) { + Objects.requireNonNull(actualExtension); + return new ShouldHaveExtension(actual, actualExtension, expectedExtension); + } + + private ShouldHaveExtension(Object actual, String actualExtension, String expectedExtension) { super("%nExpecting%n %s%nto have extension:%n %s%nbut had:%n %s.", actual, expectedExtension, actualExtension); } - private ShouldHaveExtension(File actual, String expectedExtension) { + public static ShouldHaveExtension shouldHaveExtension(Path actual, String expectedExtension) { + return new ShouldHaveExtension(actual, expectedExtension); + } + + private ShouldHaveExtension(Object actual, String expectedExtension) { super("%nExpecting%n %s%nto have extension:%n %s%nbut had no extension.", actual, expectedExtension); } + } diff --git a/src/main/java/org/assertj/core/internal/Paths.java b/src/main/java/org/assertj/core/internal/Paths.java index fc92bcd2597..e2e273ce383 100644 --- a/src/main/java/org/assertj/core/internal/Paths.java +++ b/src/main/java/org/assertj/core/internal/Paths.java @@ -38,6 +38,7 @@ import static org.assertj.core.error.ShouldHaveBinaryContent.shouldHaveBinaryContent; import static org.assertj.core.error.ShouldHaveContent.shouldHaveContent; import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; +import static org.assertj.core.error.ShouldHaveExtension.shouldHaveExtension; import static org.assertj.core.error.ShouldHaveName.shouldHaveName; import static org.assertj.core.error.ShouldHaveNoParent.shouldHaveNoParent; import static org.assertj.core.error.ShouldHaveParent.shouldHaveParent; @@ -61,6 +62,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; @@ -93,8 +95,7 @@ public static Paths instance() { return INSTANCE; } - private Paths() { - } + private Paths() {} public void assertIsReadable(final AssertionInfo info, final Path actual) { assertNotNull(info, actual); @@ -470,4 +471,19 @@ private static Path toRealPath(Path path) { } } + public void assertHasExtension(AssertionInfo info, Path actual, String expected) { + requireNonNull(expected, "The expected extension should not be null."); + assertIsRegularFile(info, actual); + String extension = getExtension(actual).orElseThrow(() -> failures.failure(info, shouldHaveExtension(actual, expected))); + if (!expected.equals(extension)) throw failures.failure(info, shouldHaveExtension(actual, extension, expected)); + } + + private static Optional getExtension(Path path) { + String fileName = path.getFileName().toString(); + int dotAt = fileName.lastIndexOf('.'); + if (dotAt == -1) return Optional.empty(); + String extension = fileName.substring(dotAt + 1); + return extension.equals("") ? Optional.empty() : Optional.of(extension); + } + } diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_hasExtension_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_hasExtension_Test.java new file mode 100644 index 00000000000..9e2620b88b0 --- /dev/null +++ b/src/test/java/org/assertj/core/api/path/PathAssert_hasExtension_Test.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.path; + +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.PathAssert; +import org.assertj.core.api.PathAssertBaseTest; + +class PathAssert_hasExtension_Test extends PathAssertBaseTest { + + @Override + protected PathAssert invoke_api_method() { + return assertions.hasExtension("java"); + } + + @Override + protected void verify_internal_effects() { + verify(paths).assertHasExtension(getInfo(assertions), getActual(assertions), "java"); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldHaveExtension_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveExtension_create_Test.java index 71dcb0f8ac4..27f3e1519c2 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveExtension_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveExtension_create_Test.java @@ -14,48 +14,89 @@ import static java.lang.String.format; import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.configuration.ConfigurationProvider.CONFIGURATION_PROVIDER; import static org.assertj.core.error.ShouldHaveExtension.shouldHaveExtension; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import org.assertj.core.internal.TestDescription; -import org.assertj.core.presentation.StandardRepresentation; import org.junit.jupiter.api.Test; /** - * Tests for {@link ShouldHaveExtension#shouldHaveExtension(java.io.File, String, String)} - * * @author Jean-Christophe Gay */ class ShouldHaveExtension_create_Test { private final String expectedExtension = "java"; - private File actual = new FakeFile("actual-file.png"); + private final File actual = new FakeFile("actual-file.png"); @Test void should_create_error_message() { - then(createMessage("png")).isEqualTo(format("[TEST] %n" + - "Expecting%n" + - " " + actual + "%n" + - "to have extension:%n" + - " \"" + expectedExtension + "\"%n" + - "but had:%n" + - " \"png\".")); + // GIVEN + ErrorMessageFactory factory = shouldHaveExtension(actual, "png", expectedExtension); + // WHEN + String message = factory.create(new TestDescription("TEST"), CONFIGURATION_PROVIDER.representation()); + // THEN + then(message).isEqualTo(format("[TEST] %n" + + "Expecting%n" + + " " + actual + "%n" + + "to have extension:%n" + + " \"" + expectedExtension + "\"%n" + + "but had:%n" + + " \"png\".")); } @Test void should_create_error_message_when_actual_does_not_have_extension() { - then(createMessage(null)).isEqualTo(format("[TEST] %n" + - "Expecting%n" + - " " + actual + "%n" + - "to have extension:%n" + - " \"" + expectedExtension + "\"%n" + - "but had no extension.")); + // GIVEN + ErrorMessageFactory factory = shouldHaveExtension(actual, null, expectedExtension); + // WHEN + String message = factory.create(new TestDescription("TEST"), CONFIGURATION_PROVIDER.representation()); + // THEN + then(message).isEqualTo(format("[TEST] %n" + + "Expecting%n" + + " " + actual + "%n" + + "to have extension:%n" + + " \"" + expectedExtension + "\"%n" + + "but had no extension.")); + } + + @Test + void should_create_error_message_with_path_when_actual_does_not_have_extension() { + // GIVEN + Path actual = Paths.get("file"); + String expectedExtension = "txt"; + ErrorMessageFactory factory = shouldHaveExtension(actual, expectedExtension); + // WHEN + String message = factory.create(new TestDescription("TEST"), CONFIGURATION_PROVIDER.representation()); + // THEN + then(message).isEqualTo(format("[TEST] %n" + + "Expecting%n" + + " " + actual + "%n" + + "to have extension:%n" + + " \"" + expectedExtension + "\"%n" + + "but had no extension.")); } - private String createMessage(String actualExtension) { - return shouldHaveExtension(actual, actualExtension, expectedExtension).create(new TestDescription("TEST"), - new StandardRepresentation()); + @Test + void should_create_error_message_with_path_when_actual_has_extension() { + // GIVEN + Path actual = Paths.get("file.txt"); + String expectedExtension = "log"; + ErrorMessageFactory factory = shouldHaveExtension(actual, "txt", expectedExtension); + // WHEN + String message = factory.create(new TestDescription("TEST"), CONFIGURATION_PROVIDER.representation()); + // THEN + then(message).isEqualTo(format("[TEST] %n" + + "Expecting%n" + + " " + actual + "%n" + + "to have extension:%n" + + " \"" + expectedExtension + "\"%n" + + "but had:%n" + + " \"txt\".")); } + } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java new file mode 100644 index 00000000000..83ba575ec9d --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java @@ -0,0 +1,112 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveExtension.shouldHaveExtension; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; + +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class Paths_assertHasExtension_Test extends PathsBaseTest { + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + String expected = "txt"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasExtension(info, actual, expected)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + String expected = "txt"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasExtension(info, actual, expected)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_regular_file() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + String expected = "txt"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasExtension(info, actual, expected)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + void should_fail_if_expected_is_null() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file.txt")); + String expected = null; + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasExtension(info, actual, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The expected extension should not be null."); + } + + @ParameterizedTest + @ValueSource(strings = { "file", "file." }) + void should_fail_if_actual_has_no_extension(String filename) throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve(filename)); + String expected = "log"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasExtension(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveExtension(actual, expected).create()); + } + + @Test + void should_fail_if_actual_does_not_have_the_expected_extension() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file.txt")); + String expected = "log"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasExtension(info, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveExtension(actual, "txt", expected).create()); + } + + @Test + void should_pass_if_actual_has_expected_extension() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file.txt")); + String expected = "txt"; + // WHEN/THEN + paths.assertHasExtension(info, actual, expected); + } + +} From 9c8fc4108557e00d3636d84c83292d5cbc194f8c Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Thu, 19 Aug 2021 22:06:43 +1200 Subject: [PATCH 074/123] Introduce ThrowingConsumerFactory testing helper --- ..._satisfies_with_ThrowingConsumer_Test.java | 6 +---- .../core/util/ThrowingConsumerFactory.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/test/java/org/assertj/core/util/ThrowingConsumerFactory.java diff --git a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java index ba26ec2e39d..32184bd4c17 100644 --- a/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java +++ b/src/test/java/org/assertj/core/api/abstract_/AbstractAssert_satisfies_with_ThrowingConsumer_Test.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.BDDAssertions.thenNullPointerException; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; import java.nio.file.Path; import java.nio.file.Paths; @@ -115,9 +116,4 @@ void should_fail_if_throwing_consumer_is_null() { .withMessage("The Consumer expressing the assertions requirements must not be null"); } - private static ThrowingConsumer throwingConsumer(Throwable throwable) { - return value -> { - throw throwable; - }; - } } diff --git a/src/test/java/org/assertj/core/util/ThrowingConsumerFactory.java b/src/test/java/org/assertj/core/util/ThrowingConsumerFactory.java new file mode 100644 index 00000000000..c53eb68bf3a --- /dev/null +++ b/src/test/java/org/assertj/core/util/ThrowingConsumerFactory.java @@ -0,0 +1,25 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.util; + +import org.assertj.core.api.ThrowingConsumer; + +public class ThrowingConsumerFactory { + + public static ThrowingConsumer throwingConsumer(Throwable throwable) { + return value -> { + throw throwable; + }; + } + +} From 367e990071eb73b08b7717d2b842774426157caf Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Thu, 19 Aug 2021 22:07:11 +1200 Subject: [PATCH 075/123] Minor javadoc improvements --- .../org/assertj/core/api/AbstractAssert.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/assertj/core/api/AbstractAssert.java b/src/main/java/org/assertj/core/api/AbstractAssert.java index e3765a34d27..f1729167658 100644 --- a/src/main/java/org/assertj/core/api/AbstractAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractAssert.java @@ -824,13 +824,13 @@ public SELF satisfies(Consumer requirements) { * Verifies that the actual object satisfied the given requirements expressed as a {@link ThrowingConsumer}. *

    * This is the same assertion as {@link #satisfies(java.util.function.Consumer)} except that a {@link ThrowingConsumer} rethrows checked exceptions as {@link RuntimeException}. - * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are while any other {@link Throwable} are rethrown as {@link RuntimeException}. + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. *

    * Example: *

     // read() throws IOException
        * ThrowingConsumer<Reader> hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1);
        *
    -   * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as Consumer<Reader> the following line would not compile): 
    +   * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as a Consumer<Reader> the following line would not compile): 
        * assertThat(new FileReader("empty.txt")).satisfies(hasReachedEOF);
        *
        * // assertion fails as the file is not empty:
    @@ -840,8 +840,8 @@ public SELF satisfies(Consumer requirements) {
        * @return this assertion object.
        *
        * @throws NullPointerException if given {@link ThrowingConsumer} is null
    -   * @throws RuntimeException rethrown as is by given {@link ThrowingConsumer} or wrapping any {@link Throwable}.    
    -   * @throws AssertionError rethrown as is by given {@link ThrowingConsumer}
    +   * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}.    
    +   * @throws AssertionError rethrown as is by the given {@link ThrowingConsumer}
        * @since 3.21.0
        */
       public SELF satisfies(ThrowingConsumer throwingConsumer) {
    @@ -894,7 +894,7 @@ public final SELF satisfiesAnyOf(Consumer... assertions) {
        * This allows users to perform OR like assertions since only one the assertions group has to be met.
        * 

    * This is the same assertion as {@link #satisfiesAnyOf(Consumer...)} but the given consumers can throw checked exceptions.
    - * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are while any other {@link Throwable} are rethrown as {@link RuntimeException}. + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. *

    * {@link #overridingErrorMessage(String, Object...) Overriding error message} is not supported as it would prevent from * getting the error messages of the failing assertions, these are valuable to figure out what went wrong.
    @@ -905,7 +905,7 @@ public final SELF satisfiesAnyOf(Consumer... assertions) { * ThrowingConsumer<Reader> hasReachedEOF = reader -> assertThat(reader.read()).isEqualTo(-1); * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z'); * - * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as Consumer<Reader> the following line would not compile): + * // assertion succeeds as the file is empty (note that if hasReachedEOF was declared as a Consumer<Reader> the following line would not compile): * assertThat(new FileReader("empty.txt")).satisfiesAnyOf(hasReachedEOF, startsWithZ); * * // alphabet.txt contains: abcdefghijklmnopqrstuvwxyz @@ -916,8 +916,8 @@ public final SELF satisfiesAnyOf(Consumer... assertions) { * @return this assertion object. * * @throws IllegalArgumentException if any given assertions group is null - * @throws RuntimeException rethrown as is by given {@link ThrowingConsumer} or wrapping any {@link Throwable}. - * @throws AssertionError rethrown as is by given {@link ThrowingConsumer} + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError rethrown as is by the given {@link ThrowingConsumer} * @since 3.21.0 */ @SafeVarargs From fff8b961508d6f0a3a8888f31739460754b2a70b Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Thu, 19 Aug 2021 22:24:22 +1200 Subject: [PATCH 076/123] Add allSatisfy, anySatisfy, satisfiesExactly, noneSatisfy, satisfiesExactlyInAnyOrder and filteredOnAssertions with ThrowingConsumer --- .../core/api/AbstractIterableAssert.java | 101 ++++- .../core/api/AbstractObjectArrayAssert.java | 363 +++++++++++++++++- .../core/api/AtomicReferenceArrayAssert.java | 334 +++++++++++++++- .../core/api/ObjectEnumerableAssert.java | 221 ++++++++++- ...allSatisfy_with_ThrowingConsumer_Test.java | 68 ++++ ...anySatisfy_with_ThrowingConsumer_Test.java | 68 ++++ ...sert_hasOnlyOneElementSatisfying_Test.java | 4 +- ...oneSatisfy_with_ThrowingConsumer_Test.java | 68 ++++ ...ssert_satisfiesExactlyInAnyOrder_Test.java | 9 +- ...InAnyOrder_with_ThrowingConsumer_Test.java | 75 ++++ ...iesExactly_with_ThrowingConsumer_Test.java | 63 +++ ...allSatisfy_with_ThrowingConsumer_Test.java | 68 ++++ ...anySatisfy_with_ThrowingConsumer_Test.java | 68 ++++ ...redOnAssertions_ThrowingConsumer_Test.java | 137 +++++++ ...t_filteredOnAssertions_consumer_Test.java} | 2 +- ...oneSatisfy_with_ThrowingConsumer_Test.java | 68 ++++ ...InAnyOrder_with_ThrowingConsumer_Test.java | 63 +++ ...iesExactly_with_ThrowingConsumer_Test.java | 63 +++ ...allSatisfy_with_ThrowingConsumer_Test.java | 69 ++++ ...anySatisfy_with_ThrowingConsumer_Test.java | 69 ++++ ...redOnAssertions_ThrowingConsumer_Test.java | 88 +++++ ...oneSatisfy_with_ThrowingConsumer_Test.java | 69 ++++ ...ssert_satisfiesExactlyInAnyOrder_Test.java | 10 +- ...InAnyOrder_with_ThrowingConsumer_Test.java | 63 +++ ...iesExactly_with_ThrowingConsumer_Test.java | 63 +++ 25 files changed, 2240 insertions(+), 34 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/iterable/IterableAssert_allSatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/iterable/IterableAssert_anySatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_ThrowingConsumer_Test.java rename src/test/java/org/assertj/core/api/iterable/{IterableAssert_filteredOn_consumer_Test.java => IterableAssert_filteredOnAssertions_consumer_Test.java} (98%) create mode 100644 src/test/java/org/assertj/core/api/iterable/IterableAssert_noneSatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactly_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_filteredOnAssertions_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java create mode 100644 src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractIterableAssert.java b/src/main/java/org/assertj/core/api/AbstractIterableAssert.java index 0e92b8c8887..7e7a7faef6e 100644 --- a/src/main/java/org/assertj/core/api/AbstractIterableAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractIterableAssert.java @@ -3135,10 +3135,42 @@ public SELF filteredOn(Function function, T expectedValu * * @param elementAssertions containing AssertJ assertions to filter on * @return a new assertion object with the filtered iterable under test - * @throws IllegalArgumentException if the given predicate is {@code null}. + * @throws IllegalArgumentException if the given {@link Consumer} is {@code null}. * @since 3.11.0 */ public SELF filteredOnAssertions(Consumer elementAssertions) { + return internalFilteredOnAssertions(elementAssertions); + } + + /** + * Filters the iterable under test keeping only elements matching the given assertions specified with a {@link ThrowingConsumer}. + *

    + * This is the same assertion as {@link #filteredOnAssertions(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: check young hobbits whose age < 34: + * + *

     TolkienCharacter pippin = new TolkienCharacter("Pippin", 28, HOBBIT);
    +   * TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
    +   * TolkienCharacter merry = new TolkienCharacter("Merry", 36, HOBBIT);
    +   * TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT);
    +   *
    +   * List<TolkienCharacter> hobbits = list(frodo, sam, merry, pippin);
    +   *
    +   * // the code would compile even if getAge() threw a checked exception
    +   * assertThat(hobbits).filteredOnAssertions(hobbit -> assertThat(hobbit.getAge()).isLessThan(34))
    +   *                    .containsOnly(frodo, pippin);
    + * + * @param elementAssertions containing AssertJ assertions to filter on + * @return a new assertion object with the filtered iterable under test + * @throws IllegalArgumentException if the given {@link ThrowingConsumer} is {@code null}. + * @since 3.21.0 + */ + public SELF filteredOnAssertions(ThrowingConsumer elementAssertions) { + return internalFilteredOnAssertions(elementAssertions); + } + + private SELF internalFilteredOnAssertions(Consumer elementAssertions) { checkArgument(elementAssertions != null, "The element assertions should not be null"); List filteredIterable = stream(actual.spliterator(), false).filter(byPassingAssertions(elementAssertions)) .collect(toList()); @@ -3678,10 +3710,25 @@ public SELF allMatch(Predicate predicate, String predicateDescr */ @Override public SELF allSatisfy(Consumer requirements) { + return internalAllSatisfy(requirements); + } + + /** + * {@inheritDoc} + */ + @Override + public SELF allSatisfy(ThrowingConsumer requirements) { + return internalAllSatisfy(requirements); + } + + private SELF internalAllSatisfy(Consumer requirements) { iterables.assertAllSatisfy(info, actual, requirements); return myself; } + /** + * {@inheritDoc} + */ @Override public SELF anyMatch(Predicate predicate) { iterables.assertAnyMatch(info, actual, predicate, PredicateDescription.GIVEN); @@ -3727,25 +3774,61 @@ public SELF zipSatisfy(Iterable other, */ @Override public SELF anySatisfy(Consumer requirements) { + return internalAnySatisfy(requirements); + } + + /** + * {@inheritDoc} + */ + @Override + public SELF anySatisfy(ThrowingConsumer requirements) { + return internalAnySatisfy(requirements); + } + + private SELF internalAnySatisfy(Consumer requirements) { iterables.assertAnySatisfy(info, actual, requirements); return myself; } - + /** * {@inheritDoc} */ @Override public SELF noneSatisfy(Consumer restrictions) { + return internalNoneSatisfy(restrictions); + } + + /** + * {@inheritDoc} + */ + @Override + public SELF noneSatisfy(ThrowingConsumer restrictions) { + return internalNoneSatisfy(restrictions); + } + + private SELF internalNoneSatisfy(Consumer restrictions) { iterables.assertNoneSatisfy(info, actual, restrictions); return myself; } - + + /** + * {@inheritDoc} + */ @Override @SafeVarargs public final SELF satisfiesExactly(Consumer... requirements) { return satisfiesExactlyForProxy(requirements); } + /** + * {@inheritDoc} + */ + @Override + @SafeVarargs + public final SELF satisfiesExactly(ThrowingConsumer... requirements) { + return satisfiesExactlyForProxy(requirements); + } + // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code @@ -3754,12 +3837,24 @@ protected SELF satisfiesExactlyForProxy(Consumer[] requirements return myself; } + /** + * {@inheritDoc} + */ @Override @SafeVarargs public final SELF satisfiesExactlyInAnyOrder(Consumer... requirements) { return satisfiesExactlyInAnyOrderForProxy(requirements); } + /** + * {@inheritDoc} + */ + @Override + @SafeVarargs + public final SELF satisfiesExactlyInAnyOrder(ThrowingConsumer... requirements) { + return satisfiesExactlyInAnyOrderForProxy(requirements); + } + // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code diff --git a/src/main/java/org/assertj/core/api/AbstractObjectArrayAssert.java b/src/main/java/org/assertj/core/api/AbstractObjectArrayAssert.java index 0a754876390..6cef681509a 100644 --- a/src/main/java/org/assertj/core/api/AbstractObjectArrayAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractObjectArrayAssert.java @@ -3230,6 +3230,35 @@ public SELF filteredOn(Function function, T expectedValu * @since 3.11.0 */ public SELF filteredOnAssertions(Consumer elementAssertions) { + return internalFilteredOnAssertions(elementAssertions); + } + + /** + * Filter the array under test keeping only elements matching the given assertions specified with a {@link Consumer}. + *

    + * Example : check old employees whose age > 100: + * + *

     Employee yoda   = new Employee(1L, new Name("Yoda"), 800);
    +   * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);
    +   * Employee luke   = new Employee(3L, new Name("Luke", "Skywalker"), 26);
    +   *
    +   * Employee[] employees = new Employee[] { yoda, luke, obiwan };
    +   * 
    +   * // compiles even if getAge() throws a checked exception unlike filteredOnAssertions(Consumer)
    +   * assertThat(employees).filteredOnAssertions(employee -> assertThat(employee.getAge()).isGreaterThan(100))
    +   *                      .containsOnly(yoda, obiwan);
    + * + * @param elementAssertions containing AssertJ assertions to filter on + * @return a new assertion object with the filtered iterable under test + * @throws IllegalArgumentException if the given predicate is {@code null}. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @since 3.21.0 + */ + public SELF filteredOnAssertions(ThrowingConsumer elementAssertions) { + return internalFilteredOnAssertions(elementAssertions); + } + + private SELF internalFilteredOnAssertions(Consumer elementAssertions) { checkArgument(elementAssertions != null, "The element assertions should not be null"); List filteredIterable = stream(actual).filter(byPassingAssertions(elementAssertions)).collect(toList()); return newObjectArrayAssert(filteredIterable).withAssertionState(myself); @@ -3276,6 +3305,48 @@ public SELF allMatch(Predicate predicate, String predicateDescr */ @Override public SELF allSatisfy(Consumer requirements) { + return internalAllSatisfy(requirements); + } + + /** + * Verifies that all the elements satisfy the given requirements expressed as a {@link ThrowingConsumer}. + *

    + * This is useful to perform a group of assertions on elements. + *

    + * This is the same assertion as {@link #allSatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if isNotEmpty, startsWithA or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> isNotEmpty = reader -> assertThat(reader.read()).isEqualTo(-1);
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * FileReader[] readers = { new FileReader("ABC.txt"), new FileReader("XYZ.txt") }; 
    +   * 
    +   * // assertion succeeds as none of the files are empty
    +   * assertThat(readers).allSatisfy(isNotEmpty);
    +   *
    +   * // assertion fails as XYZ.txt does not start with 'A':
    +   * assertThat(readers).allSatisfy(startsWithA);
    + *

    + * If the actual array is empty, this assertion succeeds as there is nothing to check. + * + * @param requirements the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if one or more elements don't satisfy the given requirements. + * @since 3.21.0 + */ + @Override + public SELF allSatisfy(ThrowingConsumer requirements) { + return internalAllSatisfy(requirements); + } + + private SELF internalAllSatisfy(Consumer requirements) { iterables.assertAllSatisfy(info, newArrayList(actual), requirements); return myself; } @@ -3346,6 +3417,48 @@ public SELF zipSatisfy(OTHER_ELEMENT[] other, */ @Override public SELF anySatisfy(Consumer requirements) { + return internalAnySatisfy(requirements); + } + + /** + * Verifies that at least one element satisfies the given requirements expressed as a {@link ThrowingConsumer}. + *

    + * This is useful to check that a group of assertions is verified by (at least) one element. + *

    + * This is the same assertion as {@link #anySatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * FileReader[] readers = { new FileReader("ABC.txt"), new FileReader("XYZ.txt") };
    +   *  
    +   * // assertion succeeds as ABC.txt starts with 'A'
    +   * assertThat(readers).anySatisfy(startsWithA);
    +   *
    +   * // assertion fails none of the files starts with 'Z':
    +   * assertThat(readers).anySatisfy(startsWithZ);
    + *

    + * If the actual array is empty, this assertion succeeds as there is nothing to check. + * + * @param requirements the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError no elements satisfy the given requirements. + * @since 3.21.0 + */ + @Override + public SELF anySatisfy(ThrowingConsumer requirements) { + return internalAnySatisfy(requirements); + } + + private SELF internalAnySatisfy(Consumer requirements) { iterables.assertAnySatisfy(info, newArrayList(actual), requirements); return myself; } @@ -3355,16 +3468,150 @@ public SELF anySatisfy(Consumer requirements) { */ @Override public SELF noneSatisfy(Consumer restrictions) { + return internalNoneSatisfy(restrictions); + } + + /** + * Verifies that no elements satisfy the given restrictions expressed as a {@link Consumer}. + *

    + * This is useful to check that a group of assertions is verified by (at least) one element. + *

    + * This is the same assertion as {@link #anySatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * FileReader[] readers = { new FileReader("ABC.txt"), new FileReader("XYZ.txt") }; 
    +   * 
    +   * // assertion succeeds as none of the file starts 'Z'
    +   * assertThat(readers).noneSatisfy(startsWithZ);
    +   *
    +   * // assertion fails as ABC.txt starts with 'A':
    +   * assertThat(readers).noneSatisfy(startsWithA);
    + *

    + * Note that this assertion succeeds if the group (collection, array, ...) is empty whatever the restrictions are. + * + * @param restrictions the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if one or more elements satisfy the given requirements. + * @since 3.21.0 + */ + @Override + public SELF noneSatisfy(ThrowingConsumer restrictions) { + return internalNoneSatisfy(restrictions); + } + + private SELF internalNoneSatisfy(Consumer restrictions) { iterables.assertNoneSatisfy(info, newArrayList(actual), restrictions); return myself; } + /** + * Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the + * first requirements, the second element the second requirements etc... + *

    + * Each requirements are expressed as a {@link Consumer}, there must be as many requirements as there are iterable elements. + *

    + * Example: + *

     TolkienCharacter[] characters = {frodo, aragorn, legolas};
    +   *
    +   * // assertions succeed
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isTrue(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    +   *
    +   * // you can specify more that one assertion per requirements
    +   * assertThat(characters).satisfiesExactly(character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Hobbit");
    +   *                                            assertThat(character.getName()).isEqualTo("Frodo");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.isMortal()).isTrue();
    +   *                                            assertThat(character.getName()).isEqualTo("Aragorn");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Elf");
    +   *                                            assertThat(character.getName()).isEqualTo("Legolas");
    +   *                                         });
    +   *
    +   * // assertion fails as aragorn does not meet the second requirements
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isFalse(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    + * + * @param requirements the requirements to meet. + * @return {@code this} to chain assertions. + * @throws NullPointerException if given requirements are null. + * @throws AssertionError if any element does not satisfy the requirements at the same index + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.19.0 + */ @Override @SafeVarargs public final SELF satisfiesExactly(Consumer... requirements) { return satisfiesExactlyForProxy(requirements); } + /** + * Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the + * first requirements, the second element the second requirements etc... + *

    + * Each requirements are expressed as a {@link ThrowingConsumer}, there must be as many requirements as there are iterable elements. + *

    + * This is the same assertion as {@link #satisfiesExactly(Consumer...)} but the given consumers can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

     TolkienCharacter[] characters = {frodo, aragorn, legolas};
    +   * 
    +   * // the code would compile even if TolkienCharacter.getRace(), isMortal() or getName() threw a checked exception
    +   *
    +   * // assertions succeed
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isTrue(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    +   *
    +   * // you can specify more that one assertion per requirements
    +   * assertThat(characters).satisfiesExactly(character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Hobbit");
    +   *                                            assertThat(character.getName()).isEqualTo("Frodo");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.isMortal()).isTrue();
    +   *                                            assertThat(character.getName()).isEqualTo("Aragorn");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Elf");
    +   *                                            assertThat(character.getName()).isEqualTo("Legolas");
    +   *                                         });
    +   *
    +   * // assertion fails as aragorn does not meet the second requirements
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isFalse(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    + * + * @param requirements the requirements to meet. + * @return {@code this} to chain assertions. + * @throws NullPointerException if given requirements are null. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if any element does not satisfy the requirements at the same index + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.21.0 + */ + @Override + @SafeVarargs + public final SELF satisfiesExactly(ThrowingConsumer... requirements) { + return satisfiesExactlyForProxy(requirements); + } + // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code @@ -3373,17 +3620,125 @@ protected SELF satisfiesExactlyForProxy(Consumer[] requirements return myself; } + /** + * Verifies that at least one combination of iterable elements exists that satisfies the consumers in order (there must be as + * many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements). + *

    + * This is a variation of {@link #satisfiesExactly(Consumer...)} where order does not matter. + *

    + * Examples: + *

     String[] starWarsCharacterNames = {"Luke", "Leia", "Yoda"};
    +   *
    +   * // these assertions succeed:
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda"
    +   *                                                               name -> assertThat(name).contains("L"), // matches "Luke" and "Leia"
    +   *                                                               name -> {
    +   *                                                                 assertThat(name).hasSize(4);
    +   *                                                                 assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia"
    +   *                                                               })
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"),
    +   *                                                               name -> assertThat(name).contains("Le"))
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"),
    +   *                                                               name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"));
    +   *
    +   * // this assertion fails as 3 consumer/requirements are expected
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no element contains "Han" (first consumer/requirements can't be met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("Y"));
    +   *
    +   * // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no combination of elements can satisfy the consumers in order
    +   * // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("o"),
    +   *                                                               name -> assertThat(name).contains("L"));
    + * + * @param requirements the consumers that are expected to be satisfied by the elements of the given {@code Iterable}. + * @return this assertion object. + * @throws NullPointerException if the given consumers array or any consumer is {@code null}. + * @throws AssertionError if there is no permutation of elements that satisfies the individual consumers in order + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * + * @since 3.19.0 + */ + @Override + @SafeVarargs + public final SELF satisfiesExactlyInAnyOrder(Consumer... requirements) { + return satisfiesExactlyInAnyOrderForProxy(requirements); + } + + /** + * Verifies that at least one combination of iterable elements exists that satisfies the {@link ThrowingConsumer}s in order (there must be as + * many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements). + *

    + * This is a variation of {@link #satisfiesExactly(ThrowingConsumer...)} where order does not matter. + *

    + * Examples: + *

     String[] starWarsCharacterNames = {"Luke", "Leia", "Yoda"};
    +   *
    +   * // these assertions succeed:
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda"
    +   *                                                               name -> assertThat(name).contains("L"), // matches "Luke" and "Leia"
    +   *                                                               name -> {
    +   *                                                                 assertThat(name).hasSize(4);
    +   *                                                                 assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia"
    +   *                                                               })
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"),
    +   *                                                               name -> assertThat(name).contains("Le"))
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"),
    +   *                                                               name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"));
    +   *
    +   * // this assertion fails as 3 consumers/requirements are expected
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no element contains "Han" (first consumer/requirements can't be met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("Y"));
    +   *
    +   * // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no combination of elements can satisfy the consumers in order
    +   * // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("o"),
    +   *                                                               name -> assertThat(name).contains("L"));
    + * + * @param requirements the consumers that are expected to be satisfied by the elements of the given {@code Iterable}. + * @return this assertion object. + * @throws NullPointerException if the given consumers array or any consumer is {@code null}. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if there is no permutation of elements that satisfies the individual consumers in order + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.21.0 + */ @Override @SafeVarargs - public final SELF satisfiesExactlyInAnyOrder(Consumer... consumers) { - return satisfiesExactlyInAnyOrderForProxy(consumers); + public final SELF satisfiesExactlyInAnyOrder(ThrowingConsumer... requirements) { + return satisfiesExactlyInAnyOrderForProxy(requirements); } // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code - protected SELF satisfiesExactlyInAnyOrderForProxy(Consumer[] consumers) { - iterables.assertSatisfiesExactlyInAnyOrder(info, newArrayList(actual), consumers); + protected SELF satisfiesExactlyInAnyOrderForProxy(Consumer[] requirements) { + iterables.assertSatisfiesExactlyInAnyOrder(info, newArrayList(actual), requirements); return myself; } diff --git a/src/main/java/org/assertj/core/api/AtomicReferenceArrayAssert.java b/src/main/java/org/assertj/core/api/AtomicReferenceArrayAssert.java index 7c56960d582..6da97077eff 100644 --- a/src/main/java/org/assertj/core/api/AtomicReferenceArrayAssert.java +++ b/src/main/java/org/assertj/core/api/AtomicReferenceArrayAssert.java @@ -3393,6 +3393,48 @@ public AtomicReferenceArrayAssert allMatch(Predicate predicate, St */ @Override public AtomicReferenceArrayAssert allSatisfy(Consumer requirements) { + return internalAllSatisfy(requirements); + } + + /** + * Verifies that all the elements satisfy the given requirements expressed as a {@link ThrowingConsumer}. + *

    + * This is useful to perform a group of assertions on elements. + *

    + * This is the same assertion as {@link #allSatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if isNotEmpty, startsWithA or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> isNotEmpty = reader -> assertThat(reader.read()).isEqualTo(-1);
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * AtomicReferenceArray<FileReader> fileReaders = new AtomicReferenceArray<>(new FileReader[] {new FileReader("ABC.txt"), new FileReader("XYZ.txt")});
    +   * 
    +   * // assertion succeeds as none of the files are empty
    +   * assertThat(fileReaders).allSatisfy(isNotEmpty);
    +   *
    +   * // assertion fails as XYZ.txt does not start with 'A':
    +   * assertThat(fileReaders).allSatisfy(startsWithA);
    + *

    + * If the actual iterable is empty, this assertion succeeds as there is nothing to check. + * + * @param requirements the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if one or more elements don't satisfy the given requirements. + * @since 3.21.0 + */ + @Override + public AtomicReferenceArrayAssert allSatisfy(ThrowingConsumer requirements) { + return internalAllSatisfy(requirements); + } + + private AtomicReferenceArrayAssert internalAllSatisfy(Consumer requirements) { iterables.assertAllSatisfy(info, newArrayList(array), requirements); return myself; } @@ -3453,6 +3495,48 @@ public AtomicReferenceArrayAssert anyMatch(Predicate predicate) { */ @Override public AtomicReferenceArrayAssert anySatisfy(Consumer requirements) { + return internalAnySatisfy(requirements); + } + + /** + * Verifies that at least one element satisfies the given requirements expressed as a {@link ThrowingConsumer}. + *

    + * This is useful to check that a group of assertions is verified by (at least) one element. + *

    + * This is the same assertion as {@link #anySatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * AtomicReferenceArray<FileReader> fileReaders = new AtomicReferenceArray<>(new FileReader[] {new FileReader("ABC.txt"), new FileReader("XYZ.txt")});
    +   * 
    +   * // assertion succeeds as ABC.txt starts with 'A'
    +   * assertThat(fileReaders).anySatisfy(startsWithA);
    +   *
    +   * // assertion fails none of the files starts with 'Z':
    +   * assertThat(fileReaders).anySatisfy(startsWithZ);
    + *

    + * If the actual iterable is empty, this assertion succeeds as there is nothing to check. + * + * @param requirements the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError no elements satisfy the given requirements. + * @since 3.21.0 + */ + @Override + public AtomicReferenceArrayAssert anySatisfy(ThrowingConsumer requirements) { + return internalAnySatisfy(requirements); + } + + private AtomicReferenceArrayAssert internalAnySatisfy(Consumer requirements) { iterables.assertAnySatisfy(info, newArrayList(array), requirements); return myself; } @@ -3462,16 +3546,150 @@ public AtomicReferenceArrayAssert anySatisfy(Consumer requirements */ @Override public AtomicReferenceArrayAssert noneSatisfy(Consumer restrictions) { + return internalNoneSatisfy(restrictions); + } + + /** + * Verifies that no elements satisfy the given restrictions expressed as a {@link Consumer}. + *

    + * This is useful to check that a group of assertions is verified by (at least) one element. + *

    + * This is the same assertion as {@link #anySatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * AtomicReferenceArray<FileReader> fileReaders = new AtomicReferenceArray<>(new FileReader[] {new FileReader("ABC.txt"), new FileReader("XYZ.txt")});
    +   * 
    +   * // assertion succeeds as none of the file starts 'Z'
    +   * assertThat(fileReaders).noneSatisfy(startsWithZ);
    +   *
    +   * // assertion fails as ABC.txt starts with 'A':
    +   * assertThat(fileReaders).noneSatisfy(startsWithA);
    + *

    + * Note that this assertion succeeds if the group (collection, array, ...) is empty whatever the restrictions are. + * + * @param restrictions the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if one or more elements satisfy the given requirements. + * @since 3.21.0 + */ + @Override + public AtomicReferenceArrayAssert noneSatisfy(ThrowingConsumer restrictions) { + return internalNoneSatisfy(restrictions); + } + + private AtomicReferenceArrayAssert internalNoneSatisfy(Consumer restrictions) { iterables.assertNoneSatisfy(info, newArrayList(array), restrictions); return myself; } + /** + * Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the + * first requirements, the second element the second requirements etc... + *

    + * Each requirements are expressed as a {@link Consumer}, there must be as many requirements as there are iterable elements. + *

    + * Example: + *

     AtomicReferenceArray<TolkienCharacter> characters = new AtomicReferenceArray<>(new TolkienCharacter[] {frodo, aragorn, legolas});
    +   *
    +   * // assertions succeed
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isTrue(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    +   *
    +   * // you can specify more that one assertion per requirements
    +   * assertThat(characters).satisfiesExactly(character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Hobbit");
    +   *                                            assertThat(character.getName()).isEqualTo("Frodo");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.isMortal()).isTrue();
    +   *                                            assertThat(character.getName()).isEqualTo("Aragorn");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Elf");
    +   *                                            assertThat(character.getName()).isEqualTo("Legolas");
    +   *                                         });
    +   *
    +   * // assertion fails as aragorn does not meet the second requirements
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isFalse(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    + * + * @param requirements the requirements to meet. + * @return {@code this} to chain assertions. + * @throws NullPointerException if given requirements are null. + * @throws AssertionError if any element does not satisfy the requirements at the same index + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.19.0 + */ @Override @SafeVarargs public final AtomicReferenceArrayAssert satisfiesExactly(Consumer... requirements) { return satisfiesExactlyForProxy(requirements); } + /** + * Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the + * first requirements, the second element the second requirements etc... + *

    + * Each requirements are expressed as a {@link ThrowingConsumer}, there must be as many requirements as there are iterable elements. + *

    + * This is the same assertion as {@link #satisfiesExactly(Consumer...)} but the given consumers can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

     AtomicReferenceArray<TolkienCharacter> characters = new AtomicReferenceArray<>(new TolkienCharacter[] {frodo, aragorn, legolas});
    +   * 
    +   * // the code would compile even if TolkienCharacter.getRace(), isMortal() or getName() threw a checked exception
    +   *
    +   * // assertions succeed
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isTrue(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    +   *
    +   * // you can specify more that one assertion per requirements
    +   * assertThat(characters).satisfiesExactly(character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Hobbit");
    +   *                                            assertThat(character.getName()).isEqualTo("Frodo");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.isMortal()).isTrue();
    +   *                                            assertThat(character.getName()).isEqualTo("Aragorn");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Elf");
    +   *                                            assertThat(character.getName()).isEqualTo("Legolas");
    +   *                                         });
    +   *
    +   * // assertion fails as aragorn does not meet the second requirements
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isFalse(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    + * + * @param requirements the requirements to meet. + * @return {@code this} to chain assertions. + * @throws NullPointerException if given requirements are null. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if any element does not satisfy the requirements at the same index + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.21.0 + */ + @Override + @SafeVarargs + public final AtomicReferenceArrayAssert satisfiesExactly(ThrowingConsumer... requirements) { + return satisfiesExactlyForProxy(requirements); + } + // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code @@ -3480,17 +3698,125 @@ protected AtomicReferenceArrayAssert satisfiesExactlyForProxy(Consumer + * This is a variation of {@link #satisfiesExactly(Consumer...)} where order does not matter. + *

    + * Examples: + *

     AtomicReferenceArray<String> starWarsCharacterNames = new AtomicReferenceArray<>(new String[] {"Luke", "Leia", "Yoda"});
    +   *
    +   * // these assertions succeed:
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda"
    +   *                                                               name -> assertThat(name).contains("L"), // matches "Luke" and "Leia"
    +   *                                                               name -> {
    +   *                                                                 assertThat(name).hasSize(4);
    +   *                                                                 assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia"
    +   *                                                               })
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"),
    +   *                                                               name -> assertThat(name).contains("Le"))
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"),
    +   *                                                               name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"));
    +   *
    +   * // this assertion fails as 3 consumer/requirements are expected
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no element contains "Han" (first consumer/requirements can't be met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("Y"));
    +   *
    +   * // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no combination of elements can satisfy the consumers in order
    +   * // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("o"),
    +   *                                                               name -> assertThat(name).contains("L"));
    + * + * @param requirements the consumers that are expected to be satisfied by the elements of the given {@code Iterable}. + * @return this assertion object. + * @throws NullPointerException if the given consumers array or any consumer is {@code null}. + * @throws AssertionError if there is no permutation of elements that satisfies the individual consumers in order + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * + * @since 3.19.0 + */ + @Override + @SafeVarargs + public final AtomicReferenceArrayAssert satisfiesExactlyInAnyOrder(Consumer... requirements) { + return satisfiesExactlyInAnyOrderForProxy(requirements); + } + + /** + * Verifies that at least one combination of iterable elements exists that satisfies the {@link ThrowingConsumer}s in order (there must be as + * many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements). + *

    + * This is a variation of {@link #satisfiesExactly(ThrowingConsumer...)} where order does not matter. + *

    + * Examples: + *

     AtomicReferenceArray<String> starWarsCharacterNames = new AtomicReferenceArray<>(new String[] {"Luke", "Leia", "Yoda"});
    +   *
    +   * // these assertions succeed:
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda"
    +   *                                                               name -> assertThat(name).contains("L"), // matches "Luke" and "Leia"
    +   *                                                               name -> {
    +   *                                                                 assertThat(name).hasSize(4);
    +   *                                                                 assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia"
    +   *                                                               })
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"),
    +   *                                                               name -> assertThat(name).contains("Le"))
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"),
    +   *                                                               name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"));
    +   *
    +   * // this assertion fails as 3 consumers/requirements are expected
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no element contains "Han" (first consumer/requirements can't be met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("Y"));
    +   *
    +   * // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no combination of elements can satisfy the consumers in order
    +   * // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("o"),
    +   *                                                               name -> assertThat(name).contains("L"));
    + * + * @param requirements the consumers that are expected to be satisfied by the elements of the given {@code Iterable}. + * @return this assertion object. + * @throws NullPointerException if the given consumers array or any consumer is {@code null}. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if there is no permutation of elements that satisfies the individual consumers in order + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.21.0 + */ @Override @SafeVarargs - public final AtomicReferenceArrayAssert satisfiesExactlyInAnyOrder(Consumer... consumers) { - return satisfiesExactlyInAnyOrderForProxy(consumers); + public final AtomicReferenceArrayAssert satisfiesExactlyInAnyOrder(ThrowingConsumer... requirements) { + return satisfiesExactlyInAnyOrderForProxy(requirements); } // This method is protected in order to be proxied for SoftAssertions / Assumptions. // The public method for it (the one not ending with "ForProxy") is marked as final and annotated with @SafeVarargs // in order to avoid compiler warning in user code - protected AtomicReferenceArrayAssert satisfiesExactlyInAnyOrderForProxy(Consumer[] consumers) { - iterables.assertSatisfiesExactlyInAnyOrder(info, newArrayList(array), consumers); + protected AtomicReferenceArrayAssert satisfiesExactlyInAnyOrderForProxy(Consumer[] requirements) { + iterables.assertSatisfiesExactlyInAnyOrder(info, newArrayList(array), requirements); return myself; } diff --git a/src/main/java/org/assertj/core/api/ObjectEnumerableAssert.java b/src/main/java/org/assertj/core/api/ObjectEnumerableAssert.java index d146fbc0597..ecdda2552d8 100644 --- a/src/main/java/org/assertj/core/api/ObjectEnumerableAssert.java +++ b/src/main/java/org/assertj/core/api/ObjectEnumerableAssert.java @@ -926,7 +926,7 @@ public interface ObjectEnumerableAssert
    * @@ -937,7 +937,7 @@ public interface ObjectEnumerableAssert elementAssertions); - + /** * Verifies that all elements of the actual group are instances of the given types. *

    @@ -1280,7 +1280,7 @@ public interface ObjectEnumerableAssert predicate, String predicateDescription); /** - * Verifies that all the elements satisfy given requirements expressed as a {@link Consumer}. + * Verifies that all the elements satisfy the given requirements expressed as a {@link Consumer}. *

    * This is useful to perform a group of assertions on elements. *

    @@ -1291,16 +1291,51 @@ public interface ObjectEnumerableAssert * *

    - * If the actual iterable/array is empty, this assertion succeeds as there is no elements to check. + * If the actual iterable is empty, this assertion succeeds as there is no elements to check. * * @param requirements the given {@link Consumer}. * @return {@code this} object. * @throws NullPointerException if the given {@link Consumer} is {@code null}. - * @throws AssertionError if one or more elements don't satisfy given requirements. + * @throws AssertionError if one or more elements don't satisfy the given requirements. * @since 3.6.0 */ SELF allSatisfy(Consumer requirements); + /** + * Verifies that all the elements satisfy the given requirements expressed as a {@link ThrowingConsumer}. + *

    + * This is useful to perform a group of assertions on elements. + *

    + * This is the same assertion as {@link #allSatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if isNotEmpty, startsWithA or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> isNotEmpty = reader -> assertThat(reader.read()).isEqualTo(-1);
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * Iterable<FileReader> fileReaders = Arrays.asList(new FileReader("ABC.txt"), new FileReader("XYZ.txt"));
    +   * 
    +   * // assertion succeeds as none of the files are empty
    +   * assertThat(fileReaders).allSatisfy(isNotEmpty);
    +   *
    +   * // assertion fails as XYZ.txt does not start with 'A':
    +   * assertThat(fileReaders).allSatisfy(startsWithA);
    + *

    + * If the actual iterable is empty, this assertion succeeds as there is nothing to check. + * + * @param requirements the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if one or more elements don't satisfy the given requirements. + * @since 3.21.0 + */ + SELF allSatisfy(ThrowingConsumer requirements); + /** * Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the * first requirements, the second element the second requirements etc... @@ -1308,7 +1343,7 @@ public interface ObjectEnumerableAssert * Example: - *

     Iterable<TolkienCharater> characters = list(frodo, aragorn, legolas);
    +   * 
     Iterable<TolkienCharacter> characters = list(frodo, aragorn, legolas);
        *
        * // assertions succeed
        * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    @@ -1342,6 +1377,54 @@ public interface ObjectEnumerableAssert... allRequirements);
    +  
    +  /**
    +   * Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the
    +   * first requirements, the second element the second requirements etc...
    +   * 

    + * Each requirements are expressed as a {@link ThrowingConsumer}, there must be as many requirements as there are iterable elements. + *

    + * This is the same assertion as {@link #satisfiesExactly(Consumer...)} but the given consumers can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

     Iterable<TolkienCharacter> characters = list(frodo, aragorn, legolas);
    +   * 
    +   * // the code would compile even if TolkienCharacter.getRace(), isMortal() or getName() threw a checked exception
    +   *
    +   * // assertions succeed
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isTrue(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    +   *
    +   * // you can specify more that one assertion per requirements
    +   * assertThat(characters).satisfiesExactly(character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Hobbit");
    +   *                                            assertThat(character.getName()).isEqualTo("Frodo");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.isMortal()).isTrue();
    +   *                                            assertThat(character.getName()).isEqualTo("Aragorn");
    +   *                                         },
    +   *                                         character -> {
    +   *                                            assertThat(character.getRace()).isEqualTo("Elf");
    +   *                                            assertThat(character.getName()).isEqualTo("Legolas");
    +   *                                         });
    +   *
    +   * // assertion fails as aragorn does not meet the second requirements
    +   * assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"),
    +   *                                         character -> assertThat(character.isMortal()).isFalse(),
    +   *                                         character -> assertThat(character.getName()).isEqualTo("Legolas"));
    + * + * @param allRequirements the requirements to meet. + * @return {@code this} to chain assertions. + * @throws NullPointerException if given requirements are null. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if any element does not satisfy the requirements at the same index + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.21.0 + */ + SELF satisfiesExactly(ThrowingConsumer... allRequirements); /** * Verifies that at least one combination of iterable elements exists that satisfies the consumers in order (there must be as @@ -1386,7 +1469,6 @@ public interface ObjectEnumerableAssert
    * - * * @param allRequirements the consumers that are expected to be satisfied by the elements of the given {@code Iterable}. * @return this assertion object. * @throws NullPointerException if the given consumers array or any consumer is {@code null}. @@ -1396,6 +1478,59 @@ public interface ObjectEnumerableAssert... allRequirements); + + /** + * Verifies that at least one combination of iterable elements exists that satisfies the {@link ThrowingConsumer}s in order (there must be as + * many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements). + *

    + * This is a variation of {@link #satisfiesExactly(ThrowingConsumer...)} where order does not matter. + *

    + * Examples: + *

     List<String> starWarsCharacterNames = list("Luke", "Leia", "Yoda");
    +   *
    +   * // these assertions succeed:
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda"
    +   *                                                               name -> assertThat(name).contains("L"), // matches "Luke" and "Leia"
    +   *                                                               name -> {
    +   *                                                                 assertThat(name).hasSize(4);
    +   *                                                                 assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia"
    +   *                                                               })
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"),
    +   *                                                               name -> assertThat(name).contains("Le"))
    +   *                                   .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"),
    +   *                                                               name -> assertThat(name).contains("Yo"),
    +   *                                                               name -> assertThat(name).contains("Lu"));
    +   *
    +   * // this assertion fails as 3 consumers/requirements are expected
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no element contains "Han" (first consumer/requirements can't be met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("Y"));
    +   *
    +   * // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"),
    +   *                                                               name -> assertThat(name).contains("L"));
    +   *
    +   * // this assertion fails as no combination of elements can satisfy the consumers in order
    +   * // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa)
    +   * assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"),
    +   *                                                               name -> assertThat(name).contains("o"),
    +   *                                                               name -> assertThat(name).contains("L"));
    + * + * @param allRequirements the consumers that are expected to be satisfied by the elements of the given {@code Iterable}. + * @return this assertion object. + * @throws NullPointerException if the given consumers array or any consumer is {@code null}. + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if there is no permutation of elements that satisfies the individual consumers in order + * @throws AssertionError if there are not as many requirements as there are iterable elements. + * @since 3.21.0 + */ + SELF satisfiesExactlyInAnyOrder(ThrowingConsumer... allRequirements); /** * Verifies whether any elements match the provided {@link Predicate}. @@ -1440,11 +1575,46 @@ public interface ObjectEnumerableAssert requirements); + /** + * Verifies that at least one element satisfies the given requirements expressed as a {@link ThrowingConsumer}. + *

    + * This is useful to check that a group of assertions is verified by (at least) one element. + *

    + * This is the same assertion as {@link #anySatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * Iterable<FileReader> fileReaders = Arrays.asList(new FileReader("ABC.txt"), new FileReader("XYZ.txt"));
    +   * 
    +   * // assertion succeeds as ABC.txt starts with 'A'
    +   * assertThat(fileReaders).anySatisfy(startsWithA);
    +   *
    +   * // assertion fails none of the files starts with 'Z':
    +   * assertThat(fileReaders).anySatisfy(startsWithZ);
    + *

    + * If the actual iterable is empty, this assertion succeeds as there is nothing to check. + * + * @param requirements the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError no elements satisfy the given requirements. + * @since 3.21.0 + */ + SELF anySatisfy(ThrowingConsumer requirements); + /** * Verifies that no elements satisfy the given restrictions expressed as a {@link Consumer}. *

    @@ -1464,6 +1634,41 @@ public interface ObjectEnumerableAssert restrictions); + /** + * Verifies that no elements satisfy the given restrictions expressed as a {@link Consumer}. + *

    + * This is useful to check that a group of assertions is verified by (at least) one element. + *

    + * This is the same assertion as {@link #anySatisfy(Consumer)} but the given consumer can throw checked exceptions.
    + * More precisely, {@link RuntimeException} and {@link AssertionError} are rethrown as they are and {@link Throwable} wrapped in a {@link RuntimeException}. + *

    + * Example: + *

      // read() throws IOException
    +   * // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> 
    +   * ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A');
    +   * ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z');
    +   *
    +   * // ABC.txt contains: ABC  
    +   * // XYZ.txt contains: XYZ  
    +   * Iterable<FileReader> fileReaders = Arrays.asList(new FileReader("ABC.txt"), new FileReader("XYZ.txt"));
    +   * 
    +   * // assertion succeeds as none of the file starts 'Z'
    +   * assertThat(fileReaders).noneSatisfy(startsWithZ);
    +   *
    +   * // assertion fails as ABC.txt starts with 'A':
    +   * assertThat(fileReaders).noneSatisfy(startsWithA);
    + *

    + * Note that this assertion succeeds if the group (collection, array, ...) is empty whatever the restrictions are. + * + * @param restrictions the given {@link ThrowingConsumer}. + * @return {@code this} object. + * @throws NullPointerException if given {@link ThrowingConsumer} is null + * @throws RuntimeException rethrown as is by the given {@link ThrowingConsumer} or wrapping any {@link Throwable}. + * @throws AssertionError if one or more elements satisfy the given requirements. + * @since 3.21.0 + */ + SELF noneSatisfy(ThrowingConsumer restrictions); + /** * Verifies that the actual {@link Iterable} contains at least one of the given values. *

    diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..c4b87bfac4e --- /dev/null +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.atomic.referencearray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Lists.newArrayList; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.AtomicReferenceArrayAssert; +import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class AtomicReferenceArrayAssert_allSatisfy_with_ThrowingConsumer_Test extends AtomicReferenceArrayAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected AtomicReferenceArrayAssert invoke_api_method() { + return assertions.allSatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertAllSatisfy(info(), newArrayList(internalArray()), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).allSatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).allSatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..1860e949313 --- /dev/null +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.atomic.referencearray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.AtomicReferenceArrayAssert; +import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class AtomicReferenceArrayAssert_anySatisfy_with_ThrowingConsumer_Test extends AtomicReferenceArrayAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected AtomicReferenceArrayAssert invoke_api_method() { + return assertions.anySatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertAnySatisfy(info(), list(internalArray()), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).anySatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).anySatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_hasOnlyOneElementSatisfying_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_hasOnlyOneElementSatisfying_Test.java index fedc4497c11..82646630998 100644 --- a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_hasOnlyOneElementSatisfying_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_hasOnlyOneElementSatisfying_Test.java @@ -12,8 +12,8 @@ */ package org.assertj.core.api.atomic.referencearray; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.util.Lists.list; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import java.util.function.Consumer; @@ -28,7 +28,7 @@ */ class AtomicReferenceArrayAssert_hasOnlyOneElementSatisfying_Test extends AtomicReferenceArrayAssertBaseTest { - private Consumer consumer = mock(Consumer.class); + private Consumer consumer = element -> assertThat(element).isNotNull(); @Override protected AtomicReferenceArrayAssert create_assertions() { diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..38314081715 --- /dev/null +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.atomic.referencearray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.AtomicReferenceArrayAssert; +import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class AtomicReferenceArrayAssert_noneSatisfy_with_ThrowingConsumer_Test extends AtomicReferenceArrayAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected AtomicReferenceArrayAssert invoke_api_method() { + return assertions.noneSatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertNoneSatisfy(info(), list(internalArray()), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).noneSatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).noneSatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_Test.java index 52ff1ff067a..d1f8079c8e4 100644 --- a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_Test.java @@ -12,15 +12,16 @@ */ package org.assertj.core.api.atomic.referencearray; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.Lists.list; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import java.util.function.Consumer; import org.assertj.core.api.AtomicReferenceArrayAssert; import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; /** * Tests for {@link AtomicReferenceArrayAssert#satisfiesExactlyInAnyOrder(Consumer...)}. @@ -29,7 +30,7 @@ */ class AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_Test extends AtomicReferenceArrayAssertBaseTest { - private Consumer consumer = mock(Consumer.class); + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); @Override protected AtomicReferenceArrayAssert create_assertions() { @@ -38,11 +39,11 @@ protected AtomicReferenceArrayAssert create_assertions() { @Override protected AtomicReferenceArrayAssert invoke_api_method() { - return assertions.satisfiesExactlyInAnyOrder(consumer); + return assertions.satisfiesExactlyInAnyOrder(requirements); } @Override protected void verify_internal_effects() { - verify(iterables).assertSatisfiesExactlyInAnyOrder(info(), list(internalArray()), array(consumer)); + verify(iterables).assertSatisfiesExactlyInAnyOrder(info(), list(internalArray()), array(requirements)); } } diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..66644ea5524 --- /dev/null +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java @@ -0,0 +1,75 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.atomic.referencearray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import java.util.function.Consumer; + +import org.assertj.core.api.AtomicReferenceArrayAssert; +import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.Test; + +/** + * Tests for {@link AtomicReferenceArrayAssert#satisfiesExactlyInAnyOrder(Consumer...)}. + * + * @author Michael Grafl + */ +class AtomicReferenceArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test extends AtomicReferenceArrayAssertBaseTest { + + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); + + @Override + protected AtomicReferenceArrayAssert create_assertions() { + return new AtomicReferenceArrayAssert<>(atomicArrayOf(new Object())); + } + + @Override + protected AtomicReferenceArrayAssert invoke_api_method() { + return assertions.satisfiesExactlyInAnyOrder(requirements); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertSatisfiesExactlyInAnyOrder(info(), list(internalArray()), array(requirements)); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).satisfiesExactlyInAnyOrder(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).satisfiesExactlyInAnyOrder(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..a08e3e15ee3 --- /dev/null +++ b/src/test/java/org/assertj/core/api/atomic/referencearray/AtomicReferenceArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.atomic.referencearray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.AtomicReferenceArrayAssert; +import org.assertj.core.api.AtomicReferenceArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.Test; + +class AtomicReferenceArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test extends AtomicReferenceArrayAssertBaseTest { + + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); + + @Override + protected AtomicReferenceArrayAssert invoke_api_method() { + return assertions.satisfiesExactly(requirements); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertSatisfiesExactly(getInfo(assertions), list(internalArray()), requirements); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).satisfiesExactly(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(atomicArrayOf("foo")).satisfiesExactly(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_allSatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_allSatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..8b314faf213 --- /dev/null +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_allSatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.iterable; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; +import static org.assertj.core.util.Lists.list; + +import org.assertj.core.api.ConcreteIterableAssert; +import org.assertj.core.api.IterableAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class IterableAssert_allSatisfy_with_ThrowingConsumer_Test extends IterableAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected ConcreteIterableAssert invoke_api_method() { + return assertions.allSatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertAllSatisfy(getInfo(assertions), getActual(assertions), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).allSatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).allSatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_anySatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_anySatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..c33e81349a7 --- /dev/null +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_anySatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.iterable; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; +import static org.assertj.core.util.Lists.list; + +import org.assertj.core.api.ConcreteIterableAssert; +import org.assertj.core.api.IterableAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class IterableAssert_anySatisfy_with_ThrowingConsumer_Test extends IterableAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected ConcreteIterableAssert invoke_api_method() { + return assertions.anySatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertAnySatisfy(getInfo(assertions), getActual(assertions), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).anySatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).anySatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..27e1b689d07 --- /dev/null +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_ThrowingConsumer_Test.java @@ -0,0 +1,137 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.iterable; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.api.BDDAssertions.thenIllegalArgumentException; +import static org.assertj.core.presentation.UnicodeRepresentation.UNICODE_REPRESENTATION; +import static org.assertj.core.util.Sets.newHashSet; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; + +import org.assertj.core.api.IterableAssert; +import org.assertj.core.api.ThrowingConsumer; +import org.assertj.core.data.TolkienCharacter; +import org.assertj.core.data.TolkienCharacterAssert; +import org.assertj.core.data.TolkienCharacterAssertFactory; +import org.assertj.core.test.Employee; +import org.assertj.core.util.CaseInsensitiveStringComparator; +import org.junit.jupiter.api.Test; + +class IterableAssert_filteredOnAssertions_ThrowingConsumer_Test extends IterableAssert_filtered_baseTest { + + private static final ThrowingConsumer nameStartingWithFro = hobbit -> assertThat(hobbit.getName()).startsWith("Fro"); + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(employees).filteredOnAssertions(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(employees).filteredOnAssertions(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + + @Test + void should_filter_iterable_under_test_verifying_given_assertions() { + // GIVEN + ThrowingConsumer old = employee -> assertThat(employee.getAge()).isGreaterThan(100); + // WHEN/THEN + then(employees).filteredOnAssertions(old) + .containsOnly(yoda, obiwan); + then(newHashSet(employees)).filteredOnAssertions(old) + .containsOnly(yoda, obiwan); + } + + @Test + void should_fail_if_given_consumer_is_null() { + // GIVEN + ThrowingConsumer consumer = null; + // WHEN/THEN + thenIllegalArgumentException().isThrownBy(() -> assertThat(employees).filteredOnAssertions(consumer)) + .withMessage("The element assertions should not be null"); + } + + @Test + void should_honor_AssertFactory_strongly_typed_navigation_assertions() { + // GIVEN + Iterable hobbits = hobbits(); + TolkienCharacterAssertFactory tolkienCharacterAssertFactory = new TolkienCharacterAssertFactory(); + // THEN + assertThat(hobbits, tolkienCharacterAssertFactory).filteredOnAssertions(nameStartingWithFro) + .first() + .hasAge(33); + assertThat(hobbits, tolkienCharacterAssertFactory).filteredOnAssertions(nameStartingWithFro) + .last() + .hasAge(33); + assertThat(hobbits, tolkienCharacterAssertFactory).filteredOnAssertions(nameStartingWithFro) + .element(0) + .hasAge(33); + assertThat(hobbits, tolkienCharacterAssertFactory).filteredOnAssertions(nameStartingWithFro) + .elements(0) + .first() + .hasAge(33); + } + + @Test + void should_honor_ClassBased_strongly_typed_navigation_assertions() { + // GIVEN + Iterable hobbits = hobbits(); + // THEN + assertThat(hobbits, TolkienCharacterAssert.class).filteredOnAssertions(nameStartingWithFro) + .first() + .hasAge(33); + assertThat(hobbits, TolkienCharacterAssert.class).filteredOnAssertions(nameStartingWithFro) + .last() + .hasAge(33); + assertThat(hobbits, TolkienCharacterAssert.class).filteredOnAssertions(nameStartingWithFro) + .elements(0) + .first() + .hasAge(33); + assertThat(hobbits, TolkienCharacterAssert.class).filteredOnAssertions(nameStartingWithFro) + .element(0) + .hasAge(33); + } + + @Test + void should_keep_assertion_state() { + // GIVEN + Iterable names = asList("John", "Doe", "Jane", "Doe"); + ThrowingConsumer fourCharsWord = string -> assertThat(string.length()).isEqualTo(4); + // WHEN + IterableAssert assertion = assertThat(names).as("test description") + .withFailMessage("error message") + .withRepresentation(UNICODE_REPRESENTATION) + .usingElementComparator(CaseInsensitiveStringComparator.instance) + .filteredOnAssertions(fourCharsWord) + .containsExactly("JOHN", "JANE"); + // THEN + assertThat(assertion.descriptionText()).isEqualTo("test description"); + assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION); + assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message"); + } + +} diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOn_consumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_consumer_Test.java similarity index 98% rename from src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOn_consumer_Test.java rename to src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_consumer_Test.java index a9fe857104e..224d2077f48 100644 --- a/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOn_consumer_Test.java +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_filteredOnAssertions_consumer_Test.java @@ -28,7 +28,7 @@ import org.assertj.core.util.CaseInsensitiveStringComparator; import org.junit.jupiter.api.Test; -class IterableAssert_filteredOn_consumer_Test extends IterableAssert_filtered_baseTest { +class IterableAssert_filteredOnAssertions_consumer_Test extends IterableAssert_filtered_baseTest { private static Consumer nameStartingWithFro = hobbit -> assertThat(hobbit.getName()).startsWith("Fro"); diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_noneSatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_noneSatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..5a3d5062520 --- /dev/null +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_noneSatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.iterable; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; +import static org.assertj.core.util.Lists.list; + +import org.assertj.core.api.ConcreteIterableAssert; +import org.assertj.core.api.IterableAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class IterableAssert_noneSatisfy_with_ThrowingConsumer_Test extends IterableAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected ConcreteIterableAssert invoke_api_method() { + return assertions.noneSatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertNoneSatisfy(getInfo(assertions), getActual(assertions), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).noneSatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).noneSatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..42ea9b99bd1 --- /dev/null +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.iterable; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ConcreteIterableAssert; +import org.assertj.core.api.IterableAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.Test; + +class IterableAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test extends IterableAssertBaseTest { + + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); + + @Override + protected ConcreteIterableAssert invoke_api_method() { + return assertions.satisfiesExactlyInAnyOrder(requirements); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertSatisfiesExactlyInAnyOrder(getInfo(assertions), getActual(assertions), requirements); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Exception exception = new Exception("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).satisfiesExactlyInAnyOrder(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).satisfiesExactlyInAnyOrder(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactly_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactly_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..c4ecd0b03b9 --- /dev/null +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_satisfiesExactly_with_ThrowingConsumer_Test.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.iterable; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ConcreteIterableAssert; +import org.assertj.core.api.IterableAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.Test; + +class IterableAssert_satisfiesExactly_with_ThrowingConsumer_Test extends IterableAssertBaseTest { + + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); + + @Override + protected ConcreteIterableAssert invoke_api_method() { + return assertions.satisfiesExactly(requirements); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertSatisfiesExactly(getInfo(assertions), getActual(assertions), requirements); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Exception exception = new Exception("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).satisfiesExactly(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(list("foo")).satisfiesExactly(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..54b798e150c --- /dev/null +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_allSatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,69 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.objectarray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ObjectArrayAssert; +import org.assertj.core.api.ObjectArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ObjectArrayAssert_allSatisfy_with_ThrowingConsumer_Test extends ObjectArrayAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected ObjectArrayAssert invoke_api_method() { + return assertions.allSatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertAllSatisfy(getInfo(assertions), list(getActual(assertions)), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).allSatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).allSatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..6ad8f1cbfa0 --- /dev/null +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_anySatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,69 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.objectarray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ObjectArrayAssert; +import org.assertj.core.api.ObjectArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ObjectArrayAssert_anySatisfy_with_ThrowingConsumer_Test extends ObjectArrayAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected ObjectArrayAssert invoke_api_method() { + return assertions.anySatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertAnySatisfy(getInfo(assertions), list(getActual(assertions)), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).anySatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).anySatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_filteredOnAssertions_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_filteredOnAssertions_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..2deef87eeea --- /dev/null +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_filteredOnAssertions_ThrowingConsumer_Test.java @@ -0,0 +1,88 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.objectarray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.api.BDDAssertions.thenIllegalArgumentException; +import static org.assertj.core.presentation.UnicodeRepresentation.UNICODE_REPRESENTATION; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; + +import org.assertj.core.api.ObjectArrayAssert; +import org.assertj.core.api.ThrowingConsumer; +import org.assertj.core.test.Employee; +import org.assertj.core.util.CaseInsensitiveStringComparator; +import org.junit.jupiter.api.Test; + +class ObjectArrayAssert_filteredOnAssertions_ThrowingConsumer_Test extends ObjectArrayAssert_filtered_baseTest { + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(employees).filteredOnAssertions(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(employees).filteredOnAssertions(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + + @Test + void should_filter_iterable_under_test_verifying_given_assertions() { + // GIVEN + ThrowingConsumer old = employee -> assertThat(employee.getAge()).isGreaterThan(100); + // WHEN/THEN + then(employees).filteredOnAssertions(old) + .containsOnly(yoda, obiwan); + } + + @Test + void should_fail_if_given_consumer_is_null() { + // GIVEN + ThrowingConsumer consumer = null; + // WHEN/THEN + thenIllegalArgumentException().isThrownBy(() -> assertThat(employees).filteredOnAssertions(consumer)) + .withMessage("The element assertions should not be null"); + } + + @Test + void should_keep_assertion_state() { + // GIVEN + String[] names = array("John", "Doe", "Jane", "Doe"); + ThrowingConsumer fourCharsWord = string -> assertThat(string.length()).isEqualTo(4); + // WHEN + ObjectArrayAssert assertion = assertThat(names).as("test description") + .withFailMessage("error message") + .withRepresentation(UNICODE_REPRESENTATION) + .usingElementComparator(CaseInsensitiveStringComparator.instance) + .filteredOnAssertions(fourCharsWord) + .containsExactly("JOHN", "JANE"); + // THEN + assertThat(assertion.descriptionText()).isEqualTo("test description"); + assertThat(assertion.info.representation()).isEqualTo(UNICODE_REPRESENTATION); + assertThat(assertion.info.overridingErrorMessage()).isEqualTo("error message"); + } + +} diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..5738339acd7 --- /dev/null +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_noneSatisfy_with_ThrowingConsumer_Test.java @@ -0,0 +1,69 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.objectarray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ObjectArrayAssert; +import org.assertj.core.api.ObjectArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ObjectArrayAssert_noneSatisfy_with_ThrowingConsumer_Test extends ObjectArrayAssertBaseTest { + + private ThrowingConsumer restrictions; + + @BeforeEach + void beforeOnce() { + restrictions = o -> assertThat(o).isNotNull(); + } + + @Override + protected ObjectArrayAssert invoke_api_method() { + return assertions.noneSatisfy(restrictions); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertNoneSatisfy(getInfo(assertions), list(getActual(assertions)), restrictions); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).noneSatisfy(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).noneSatisfy(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_Test.java index 6c8cb27989a..27c5d3bf9a6 100644 --- a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_Test.java @@ -12,10 +12,9 @@ */ package org.assertj.core.api.objectarray; -import static org.assertj.core.test.ObjectArrays.arrayOf; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.Lists.list; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import java.util.function.Consumer; @@ -30,12 +29,7 @@ */ class ObjectArrayAssert_satisfiesExactlyInAnyOrder_Test extends ObjectArrayAssertBaseTest { - private Consumer consumer = mock(Consumer.class); - - @Override - protected ObjectArrayAssert create_assertions() { - return new ObjectArrayAssert<>(arrayOf(new Object())); - } + private Consumer consumer = element -> assertThat(element).isNotNull(); @Override protected ObjectArrayAssert invoke_api_method() { diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..6fc9798e85a --- /dev/null +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.objectarray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ObjectArrayAssert; +import org.assertj.core.api.ObjectArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.Test; + +class ObjectArrayAssert_satisfiesExactlyInAnyOrder_with_ThrowingConsumer_Test extends ObjectArrayAssertBaseTest { + + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); + + @Override + protected ObjectArrayAssert invoke_api_method() { + return assertions.satisfiesExactlyInAnyOrder(requirements); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertSatisfiesExactlyInAnyOrder(getInfo(assertions), list(getActual(assertions)), requirements); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).satisfiesExactlyInAnyOrder(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).satisfiesExactlyInAnyOrder(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} diff --git a/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java new file mode 100644 index 00000000000..919b24f08be --- /dev/null +++ b/src/test/java/org/assertj/core/api/objectarray/ObjectArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test.java @@ -0,0 +1,63 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.objectarray; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.ThrowingConsumerFactory.throwingConsumer; +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.ObjectArrayAssert; +import org.assertj.core.api.ObjectArrayAssertBaseTest; +import org.assertj.core.api.ThrowingConsumer; +import org.junit.jupiter.api.Test; + +class ObjectArrayAssert_satisfiesExactly_with_ThrowingConsumer_Test extends ObjectArrayAssertBaseTest { + + private ThrowingConsumer[] requirements = array(element -> assertThat(element).isNotNull()); + + @Override + protected ObjectArrayAssert invoke_api_method() { + return assertions.satisfiesExactly(requirements); + } + + @Override + protected void verify_internal_effects() { + verify(iterables).assertSatisfiesExactly(getInfo(assertions), list(getActual(assertions)), requirements); + } + + @Test + void should_rethrow_throwables_as_runtime_exceptions() { + // GIVEN + Throwable exception = new Throwable("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).satisfiesExactly(throwingConsumer(exception))); + // THEN + then(throwable).isInstanceOf(RuntimeException.class) + .hasCauseReference(exception); + } + + @Test + void should_propagate_RuntimeException_as_is() { + // GIVEN + RuntimeException runtimeException = new RuntimeException("boom!"); + // WHEN + Throwable throwable = catchThrowable(() -> assertThat(array("foo")).satisfiesExactly(throwingConsumer(runtimeException))); + // THEN + then(throwable).isSameAs(runtimeException); + } + +} From 0d1643e35c0f0685dbf06817fe7c73eed92bf454 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 23 Aug 2021 08:25:34 +0200 Subject: [PATCH 077/123] Bump mockito.version from 3.12.0 to 3.12.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 86cdb047b71..01d6fc45b9a 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 4.13.2 5.7.2 - 3.12.0 + 3.12.1 0.8.7 From 867631539d891c7590f03da4d053b523b5046c32 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 23 Aug 2021 22:29:14 +0200 Subject: [PATCH 078/123] Bump JUnit versions --- verify.bndrun | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/verify.bndrun b/verify.bndrun index d3d09c918fb..0925fe18a3f 100644 --- a/verify.bndrun +++ b/verify.bndrun @@ -32,9 +32,9 @@ -runbundles: \ assertj-core;version='[3.21.0,3.21.1)',\ assertj-core-tests;version='[3.21.0,3.21.1)',\ - junit-jupiter-api;version='[5.7.2,5.7.3)',\ - junit-jupiter-engine;version='[5.7.2,5.7.3)',\ - junit-platform-commons;version='[1.7.2,1.7.3)',\ - junit-platform-engine;version='[1.7.2,1.7.3)',\ - junit-platform-launcher;version='[1.7.2,1.7.3)',\ + junit-jupiter-api;version='[5.8.0,5.8.1)',\ + junit-jupiter-engine;version='[5.8.0,5.8.1)',\ + junit-platform-commons;version='[1.8.0,1.8.1)',\ + junit-platform-engine;version='[1.8.0,1.8.1)',\ + junit-platform-launcher;version='[1.8.0,1.8.1)',\ org.opentest4j;version='[1.2.0,1.2.1)' From 71b9e77976dd089340fd0d996e99cb12dd55a79e Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 23 Aug 2021 22:41:43 +0200 Subject: [PATCH 079/123] Use setup-java cache support --- .github/workflows/binary-compatibility.yml | 8 +------- .github/workflows/cross-version.yml | 8 +------- .github/workflows/main.yml | 16 ++-------------- .github/workflows/pitest-receive-pr.yml | 8 +------- 4 files changed, 5 insertions(+), 35 deletions(-) diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml index f5ab184f82d..6acf36e8aed 100644 --- a/.github/workflows/binary-compatibility.yml +++ b/.github/workflows/binary-compatibility.yml @@ -25,13 +25,7 @@ jobs: with: distribution: 'zulu' java-version: 11 - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + cache: 'maven' - name: (`main` only) Compare with the latest release if: github.base_ref == null diff --git a/.github/workflows/cross-version.yml b/.github/workflows/cross-version.yml index 20cb2794243..0892dab4d5d 100644 --- a/.github/workflows/cross-version.yml +++ b/.github/workflows/cross-version.yml @@ -18,12 +18,6 @@ jobs: with: distribution: 'zulu' java-version: ${{ matrix.java }} - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + cache: 'maven' - name: Test run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa08ad2362f..8ffb86317bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,13 +18,7 @@ jobs: with: distribution: 'zulu' java-version: 11 - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + cache: 'maven' - name: Test run: ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc @@ -41,13 +35,7 @@ jobs: with: distribution: 'zulu' java-version: 11 - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- + cache: 'maven' - name: Test with Sonar run: > ./mvnw -V --no-transfer-progress -e verify javadoc:javadoc sonar:sonar diff --git a/.github/workflows/pitest-receive-pr.yml b/.github/workflows/pitest-receive-pr.yml index db235747b9c..16464b6e816 100644 --- a/.github/workflows/pitest-receive-pr.yml +++ b/.github/workflows/pitest-receive-pr.yml @@ -28,18 +28,12 @@ jobs: # important to set a fetch depth of 2. By default the checkout action make no history available fetch-depth: 2 - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - name: Setup Java uses: actions/setup-java@v2 with: distribution: 'zulu' java-version: 11 + cache: 'maven' - name: run pitest # pitest has been bound to a profile called pitest for normal running # we add config to analyse only changes made within a PR and treat surviving mutants as check errors From 391b688863002fe50bdf9f7f70e542096fb0ece1 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 23 Aug 2021 22:50:00 +0200 Subject: [PATCH 080/123] Add default method lookup to `hasMethods` (#2324) --- .../org/assertj/core/internal/Classes.java | 11 ++-- .../Classes_assertHasMethods_Test.java | 57 +++++++++++++++---- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/assertj/core/internal/Classes.java b/src/main/java/org/assertj/core/internal/Classes.java index d8f6c20d469..056197b4959 100644 --- a/src/main/java/org/assertj/core/internal/Classes.java +++ b/src/main/java/org/assertj/core/internal/Classes.java @@ -431,7 +431,7 @@ private static Set fieldsToName(Set fields) { * @param actual the "actual" {@code Class}. * @param methods the methods who must be present in the class. * @throws AssertionError if {@code actual} is {@code null}. - * @throws AssertionError if the actual {@code Class} doesn't contains all of the methods. + * @throws AssertionError if the actual {@code Class} doesn't contains all the methods. */ public void assertHasMethods(AssertionInfo info, Class actual, String... methods) { assertNotNull(info, actual); @@ -445,7 +445,7 @@ public void assertHasMethods(AssertionInfo info, Class actual, String... meth * @param actual the "actual" {@code Class}. * @param methods the methods who must be declared in the class. * @throws AssertionError if {@code actual} is {@code null}. - * @throws AssertionError if the actual {@code Class} doesn't contains all of the methods. + * @throws AssertionError if the actual {@code Class} doesn't contains all the methods. */ public void assertHasDeclaredMethods(AssertionInfo info, Class actual, String... methods) { assertNotNull(info, actual); @@ -476,7 +476,7 @@ private void doAssertHasMethods(AssertionInfo info, Class actual, Set * @param actual the "actual" {@code Class}. * @param methods the public methods who must be present in the class. * @throws AssertionError if {@code actual} is {@code null}. - * @throws AssertionError if the actual {@code Class} doesn't contains all of the public methods. + * @throws AssertionError if the actual {@code Class} doesn't contains all the public methods. */ public void assertHasPublicMethods(AssertionInfo info, Class actual, String... methods) { assertNotNull(info, actual); @@ -555,7 +555,10 @@ private static Method[] getAllMethods(Class actual) { if (superclass != null) { allMethods.addAll(newLinkedHashSet(getAllMethods(superclass))); } - return allMethods.toArray(new Method[allMethods.size()]); + for (Class anInterface : actual.getInterfaces()) { + allMethods.addAll(newLinkedHashSet(getAllMethods(anInterface))); + } + return allMethods.toArray(new Method[0]); } private static Set filterSyntheticMembers(M[] members) { diff --git a/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java b/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java index ccf291909ec..2777efae9f4 100644 --- a/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java +++ b/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java @@ -51,17 +51,17 @@ void should_pass_if_actual_has_expected_accessible_public_methods() { @Test void should_fail_if_no_methods_are_expected_and_methods_are_available() { SortedSet expectedMethods = newTreeSet("publicMethod", - "protectedMethod", - "privateMethod", - "finalize", - "wait", - "equals", - "toString", - "hashCode", - "getClass", - "clone", - "notify", - "notifyAll"); + "protectedMethod", + "privateMethod", + "finalize", + "wait", + "equals", + "toString", + "hashCode", + "getClass", + "clone", + "notify", + "notifyAll"); if (isJavaVersionBefore14()) { expectedMethods.add("registerNatives"); } @@ -98,4 +98,39 @@ private static boolean isJavaVersionBefore14() { BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version")); return javaVersion.compareTo(new BigDecimal("14")) < 0; } + + @Test + void should_pass_with_direct_default_method() { + // GIVEN + Class actual = ClassWithDirectDefaultMethod.class; + String[] expected = { "method" }; + // WHEN/THEN + classes.assertHasMethods(someInfo(), actual, expected); + } + + private static class ClassWithDirectDefaultMethod implements InterfaceWithDefaultMethod { + } + + private interface InterfaceWithDefaultMethod { + + @SuppressWarnings("unused") + default void method() {} + + } + + @Test + void should_pass_with_indirect_default_method() { + // GIVEN + Class actual = ClassWithIndirectDefaultMethod.class; + String[] expected = { "method" }; + // WHEN/THEN + classes.assertHasMethods(someInfo(), actual, expected); + } + + private static class ClassWithIndirectDefaultMethod implements InterfaceInheritingDefaultMethod { + } + + private interface InterfaceInheritingDefaultMethod extends InterfaceWithDefaultMethod { + } + } From 933a350828f8dee0614f7fe18d1c7275e3dcd050 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 24 Aug 2021 11:39:50 +0200 Subject: [PATCH 081/123] Cosmetic --- src/main/java/org/assertj/core/internal/Classes.java | 4 ++-- .../classes/Classes_assertHasMethods_Test.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/assertj/core/internal/Classes.java b/src/main/java/org/assertj/core/internal/Classes.java index 056197b4959..2f1caf7d43d 100644 --- a/src/main/java/org/assertj/core/internal/Classes.java +++ b/src/main/java/org/assertj/core/internal/Classes.java @@ -555,8 +555,8 @@ private static Method[] getAllMethods(Class actual) { if (superclass != null) { allMethods.addAll(newLinkedHashSet(getAllMethods(superclass))); } - for (Class anInterface : actual.getInterfaces()) { - allMethods.addAll(newLinkedHashSet(getAllMethods(anInterface))); + for (Class superinterface : actual.getInterfaces()) { + allMethods.addAll(newLinkedHashSet(getAllMethods(superinterface))); } return allMethods.toArray(new Method[0]); } diff --git a/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java b/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java index 2777efae9f4..96ec565157b 100644 --- a/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java +++ b/src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java @@ -100,15 +100,15 @@ private static boolean isJavaVersionBefore14() { } @Test - void should_pass_with_direct_default_method() { + void should_pass_with_directly_inherited_default_method() { // GIVEN - Class actual = ClassWithDirectDefaultMethod.class; + Class actual = ClassWithDirectlyInheritedDefaultMethod.class; String[] expected = { "method" }; // WHEN/THEN classes.assertHasMethods(someInfo(), actual, expected); } - private static class ClassWithDirectDefaultMethod implements InterfaceWithDefaultMethod { + private static class ClassWithDirectlyInheritedDefaultMethod implements InterfaceWithDefaultMethod { } private interface InterfaceWithDefaultMethod { @@ -119,15 +119,15 @@ default void method() {} } @Test - void should_pass_with_indirect_default_method() { + void should_pass_with_indirectly_inherited_default_method() { // GIVEN - Class actual = ClassWithIndirectDefaultMethod.class; + Class actual = ClassWithIndirectlyInheritedDefaultMethod.class; String[] expected = { "method" }; // WHEN/THEN classes.assertHasMethods(someInfo(), actual, expected); } - private static class ClassWithIndirectDefaultMethod implements InterfaceInheritingDefaultMethod { + private static class ClassWithIndirectlyInheritedDefaultMethod implements InterfaceInheritingDefaultMethod { } private interface InterfaceInheritingDefaultMethod extends InterfaceWithDefaultMethod { From f5eb1e6bd17b57d5a709d18348bc1d2c0d403882 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Aug 2021 22:18:52 +0200 Subject: [PATCH 082/123] Bump cdg.pitest.version from 0.0.12 to 0.0.13 (#2325) * Bump cdg.pitest.version from 0.0.12 to 0.0.13 Bumps `cdg.pitest.version` from 0.0.12 to 0.0.13. Updates `pitest-git-plugin` from 0.0.12 to 0.0.13 Updates `pitest-git-maven-plugin` from 0.0.12 to 0.0.13 --- updated-dependencies: - dependency-name: com.groupcdg:pitest-git-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.groupcdg:pitest-git-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump pitest-github-maven-plugin from 0.0.12 to 0.0.13 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefano Cordio --- .github/workflows/pitest-updated-pr.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pitest-updated-pr.yml b/.github/workflows/pitest-updated-pr.yml index 2335a563740..a19c0899928 100644 --- a/.github/workflows/pitest-updated-pr.yml +++ b/.github/workflows/pitest-updated-pr.yml @@ -42,4 +42,4 @@ jobs: # The updatePR maven goal is used here with an explicit version. This allows us to upload without checking out # the code, but does mean the version here must be maintained. An alternative would be to checkout the code and use # the github goal. This will work as long as the artifact is extracted to the maven target directory - run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.12:updatePR + run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.13:updatePR diff --git a/pom.xml b/pom.xml index 01d6fc45b9a..340311d9745 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 2.2 1.2.0 5.3.0 - 0.0.12 + 0.0.13 4.13.2 5.7.2 From 91b8eb3554bbbd6ec837508eecfb5a79c4c278cc Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 25 Aug 2021 09:02:53 +0200 Subject: [PATCH 083/123] Bump mockito.version from 3.12.1 to 3.12.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 340311d9745..a9e4bb46ccf 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 4.13.2 5.7.2 - 3.12.1 + 3.12.3 0.8.7 From 37b3460f33ab224603a36f9ab8309d8e8b9773cd Mon Sep 17 00:00:00 2001 From: epeee Date: Thu, 26 Aug 2021 08:03:20 +0200 Subject: [PATCH 084/123] Bump mockito.version from 3.12.3 to 3.12.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a9e4bb46ccf..58064c73474 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 4.13.2 5.7.2 - 3.12.3 + 3.12.4 0.8.7 From c3909f5f6dd1744cfccb556caf2c58bbb5a6b84e Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Fri, 27 Aug 2021 07:47:39 +0200 Subject: [PATCH 085/123] Reorder POM based on Maven code conventions See https://maven.apache.org/developers/conventions/code.html#pom-code-convention --- pom.xml | 298 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 153 insertions(+), 145 deletions(-) diff --git a/pom.xml b/pom.xml index 58064c73474..cb8a9a2f37b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,21 @@ 4.0.0 - assertj-core - 3.21.0-SNAPSHOT - jar - AssertJ fluent assertions - Rich and fluent assertions for testing for Java + org.assertj assertj-parent-pom 2.2.13 + + assertj-core + 3.21.0-SNAPSHOT + jar + + AssertJ fluent assertions + Rich and fluent assertions for testing for Java + scm:git:git@github.com:assertj/assertj-core.git scm:git:git@github.com:assertj/assertj-core.git @@ -62,8 +66,13 @@ - + + + net.bytebuddy + byte-buddy + + junit junit @@ -78,57 +87,28 @@ - org.junit.jupiter - junit-jupiter-api + org.hamcrest + hamcrest provided true org.junit.jupiter - junit-jupiter - test - - - - org.junit.vintage - junit-vintage-engine - test - - - org.junit.platform - junit-platform-testkit - test - - - org.assertj - assertj-core - - - - - org.opentest4j - opentest4j + junit-jupiter-api provided true - org.hamcrest - hamcrest + org.opentest4j + opentest4j provided true + - net.bytebuddy - byte-buddy - - - org.mockito - mockito-core - test - - - org.mockito - mockito-junit-jupiter + commons-io + commons-io + 2.11.0 test @@ -138,9 +118,9 @@ test + a decent JSR 203 implementation which lets us test our assertions. Right now, this is memoryfilesystem (https://github.com/marschall/memoryfilesystem). + Another choice would be jimfs from Google (https://github.com/google/jimfs), but its support for reading/writing file attributes + is not as complete as that of memoryfilesystem's. --> com.github.marschall memoryfilesystem @@ -154,9 +134,9 @@ test - org.apache.commons - commons-lang3 - 3.12.0 + nl.jqno.equalsverifier + equalsverifier + 3.7.1 test @@ -166,15 +146,9 @@ test - commons-io - commons-io - 2.11.0 - test - - - nl.jqno.equalsverifier - equalsverifier - 3.7.1 + org.apache.commons + commons-lang3 + 3.12.0 test @@ -183,6 +157,38 @@ 3.16.300 test + + org.junit.platform + junit-platform-testkit + test + + + org.assertj + assertj-core + + + + + org.junit.jupiter + junit-jupiter + test + + + + org.junit.vintage + junit-vintage-engine + test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-junit-jupiter + test + org.springframework spring-core @@ -190,7 +196,94 @@ test + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.9.0.2155 + + + net.alchim31.maven + yuicompressor-maven-plugin + 1.5.1 + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + com.mycila + license-maven-plugin + [2.6,) + + format + + + + + + + + + + + + com.github.siom79.japicmp + japicmp-maven-plugin + 0.15.3 + + + + junit + junit + ${junit.version} + + + org.hamcrest + hamcrest + ${hamcrest.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + + + org.opentest4j + opentest4j + ${opentest4j.version} + + + + + org.assertj.core.internal + + true + true + + + + METHOD_NEW_DEFAULT + true + true + + + true + + true + + + + org.apache.maven.plugins @@ -633,93 +726,8 @@ - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.9.0.2155 - - - net.alchim31.maven - yuicompressor-maven-plugin - 1.5.1 - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - com.mycila - license-maven-plugin - [2.6,) - - format - - - - - - - - - - - - com.github.siom79.japicmp - japicmp-maven-plugin - 0.15.3 - - - - junit - junit - ${junit.version} - - - org.hamcrest - hamcrest - ${hamcrest.version} - - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter.version} - - - org.opentest4j - opentest4j - ${opentest4j.version} - - - - - org.assertj.core.internal - - true - true - - - - METHOD_NEW_DEFAULT - true - true - - - true - - true - - - - + java13+ From e654260374a5c45da1e3cb934b6e7bf591a1a540 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 28 Aug 2021 16:37:57 +1200 Subject: [PATCH 086/123] Bump jackson-databind from 2.12.4 to 2.12.5 (#2326) Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.12.4 to 2.12.5. - [Release notes](https://github.com/FasterXML/jackson/releases) - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cb8a9a2f37b..6053229989b 100644 --- a/pom.xml +++ b/pom.xml @@ -114,7 +114,7 @@ com.fasterxml.jackson.core jackson-databind - 2.12.4 + 2.12.5 test + org.apache.maven.plugins maven-surefire-plugin - -Dfile.encoding=${project.build.sourceEncoding} ${argLine} + @{argLine} false org/assertj/core/osgi/** @@ -536,50 +537,6 @@ - - - org.jacoco - jacoco-maven-plugin - - - - **/*hamcrest*/** - - - - - - jacoco-report - prepare-package - - report - - - - default-check - prepare-package - - check - - - - - BUNDLE - - - CLASS - COVEREDRATIO - 0.98 - - - - - - - - net.alchim31.maven yuicompressor-maven-plugin @@ -744,9 +701,14 @@ [16,) - -Dnet.bytebuddy.experimental=true --add-opens=java.base/java.lang=ALL-UNNAMED - --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.math=ALL-UNNAMED - --add-opens=java.base/sun.nio.fs=ALL-UNNAMED + + -Dfile.encoding=${project.build.sourceEncoding} + -Dnet.bytebuddy.experimental=true + --add-opens=java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.math=ALL-UNNAMED + --add-opens=java.base/java.util=ALL-UNNAMED + --add-opens=java.base/sun.nio.fs=ALL-UNNAMED + @@ -797,6 +759,56 @@ + + coverage + + + + org.jacoco + jacoco-maven-plugin + + + + **/*hamcrest*/** + + + + + + jacoco-report + prepare-package + + report + + + + default-check + prepare-package + + check + + + + + BUNDLE + + + CLASS + COVEREDRATIO + 0.98 + + + + + + + + + + + From b0c2127dd7b5997b5ba0365ff910d32fb60d31d7 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 29 Aug 2021 23:57:28 +0200 Subject: [PATCH 091/123] Remove memoryfilesystem --- pom.xml | 10 --- .../assertj/core/internal/PathsBaseTest.java | 60 +------------ .../paths/Paths_assertHasFileName_Test.java | 90 ++++++++----------- 3 files changed, 38 insertions(+), 122 deletions(-) diff --git a/pom.xml b/pom.xml index b056ef06695..2eed5a3d3a8 100644 --- a/pom.xml +++ b/pom.xml @@ -118,16 +118,6 @@ 2.12.5 test - - - com.github.marschall - memoryfilesystem - 2.2.0 - test - com.google.guava guava diff --git a/src/test/java/org/assertj/core/internal/PathsBaseTest.java b/src/test/java/org/assertj/core/internal/PathsBaseTest.java index c75315231e2..e74c9da0a99 100644 --- a/src/test/java/org/assertj/core/internal/PathsBaseTest.java +++ b/src/test/java/org/assertj/core/internal/PathsBaseTest.java @@ -13,45 +13,16 @@ package org.assertj.core.internal; import static org.assertj.core.test.TestData.someInfo; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import java.io.File; -import java.io.IOException; -import java.nio.file.FileSystem; import java.nio.file.Path; import org.assertj.core.api.AssertionInfo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; -import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; - /** - * Base test class for {@link Path} instances - * - *

    - * Assertion on {@link Path} objects are of two categories: - *

    - * - *
      - *
    • assertions on the {@link Path} object themselves: those do not require a {@link FileSystem};
    • - *
    • assertions inducing filesystem I/O: those do require a {@link FileSystem}.
    • - *
    - * - *

    - * An advantage when compared with {@link File} is that we do not need to pollute the developer's machine with temporary - * files/directories/etc for I/O bound tests; all that is required is a filesystem implementation. - *

    - * - *

    - * memoryfilesystem is chosen for its great support of - * getting/setting file attributes etc, and for its emulation of both Unix and Windows filesystems. - *

    - * - * @see Path - * @see FileSystem - * @see Files + * Base class for {@link Paths} tests. */ public abstract class PathsBaseTest { @@ -67,7 +38,7 @@ public abstract class PathsBaseTest { protected BinaryDiff binaryDiff; @BeforeEach - public void setUp() { + void setUp() { paths = Paths.instance(); nioFilesWrapper = spy(paths.nioFilesWrapper); paths.nioFilesWrapper = nioFilesWrapper; @@ -80,31 +51,4 @@ public void setUp() { info = someInfo(); } - /** - * A {@link FileSystem} for test classes which need them - */ - public static class FileSystemResource { - - private final FileSystem fs; - - public FileSystemResource() { - try { - fs = MemoryFileSystemBuilder.newLinux().build("PathsTest"); - } catch (IOException e) { - throw new RuntimeException("failed to initialize filesystem", e); - } - } - - public FileSystem getFileSystem() { - return fs; - } - - public void close() { - try { - fs.close(); - } catch (IOException e) { - throw new RuntimeException("failed to close filesystem", e); - } - } - } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java index b668ee3f6ca..12fd63e67a9 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java @@ -15,86 +15,68 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; import static java.nio.file.Files.createSymbolicLink; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import java.io.IOException; -import java.nio.file.FileSystem; import java.nio.file.Path; import org.assertj.core.internal.PathsBaseTest; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; class Paths_assertHasFileName_Test extends PathsBaseTest { - public static FileSystemResource resource; - - private static Path existingFile; - private static Path symlinkToExistingFile; - private static Path nonExistingPath; - private static Path symlinkToNonExistingPath; - private static Path existingDirectory; - private static Path symlinkToExistingDirectory; - - @BeforeAll - static void initPaths() throws IOException { - resource = new FileSystemResource(); - final FileSystem fs = resource.getFileSystem(); - - existingDirectory = fs.getPath("/dir1/dir2"); - symlinkToExistingDirectory = fs.getPath("/symlinkToExistingDirectory"); - createDirectory(fs.getPath("/dir1")); - createDirectory(existingDirectory); - createSymbolicLink(symlinkToExistingDirectory, existingDirectory); - - existingFile = fs.getPath("/dir1/dir2/gc.log"); - symlinkToExistingFile = fs.getPath("/dir1/good-symlink"); - createFile(existingFile); - createSymbolicLink(symlinkToExistingFile, existingFile); - - nonExistingPath = fs.getPath("/dir1/fake.log"); - symlinkToNonExistingPath = fs.getPath("/dir1/bad-symlink"); - createSymbolicLink(symlinkToNonExistingPath, nonExistingPath); - } - - @AfterAll - static void tearDown() { - resource.close(); - } - @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> paths.assertHasFileName(info, null, "file.txt")) - .withMessage(actualIsNull()); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasFileName(info, null, "actual")); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_given_file_name_is_null() { - assertThatNullPointerException().isThrownBy(() -> paths.assertHasFileName(info, existingFile, null)) - .withMessage("expected fileName should not be null"); + void should_fail_if_fileName_is_null() { + // GIVEN + Path actual = tempDir.resolve("actual"); + // WHEN + Throwable thrown = catchThrowable(() -> paths.assertHasFileName(info, actual, null)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("expected fileName should not be null"); } @Test - void should_pass_if_actual_file_has_the_given_file_name() { - paths.assertHasFileName(info, existingFile, "gc.log"); + void should_pass_if_non_existing_actual_has_given_fileName() { + // GIVEN + Path actual = tempDir.resolve("actual"); + // WHEN/THEN + paths.assertHasFileName(info, actual, "actual"); } @Test - void should_pass_if_actual_non_existent_path_has_the_given_file_name() { - paths.assertHasFileName(info, nonExistingPath, "fake.log"); + void should_pass_if_existing_actual_file_has_given_fileName() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("actual")); + // WHEN/THEN + paths.assertHasFileName(info, actual, "actual"); } @Test - void should_pass_if_actual_symbolic_link_has_the_given_file_name() { - paths.assertHasFileName(info, symlinkToNonExistingPath, "bad-symlink"); - paths.assertHasFileName(info, symlinkToExistingFile, "good-symlink"); + void should_pass_if_existing_actual_directory_has_given_fileName() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + // WHEN/THEN + paths.assertHasFileName(info, actual, "actual"); } @Test - void should_pass_if_actual_directory_has_the_given_file_name() { - paths.assertHasFileName(info, existingDirectory, "dir2"); + void should_pass_if_existing_actual_symbolic_link_has_given_fileName() throws IOException { + // GIVEN + Path actual = createSymbolicLink(tempDir.resolve("actual"), tempDir); + // WHEN/THEN + paths.assertHasFileName(info, actual, "actual"); } + } From 441999e1fd90b96a803e91e1fcfa2843aa1ee4f9 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 30 Aug 2021 08:41:10 +0200 Subject: [PATCH 092/123] Add missing test, cosmetic --- .../paths/Paths_assertHasFileName_Test.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java index 12fd63e67a9..8522a41fe64 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java @@ -30,53 +30,72 @@ class Paths_assertHasFileName_Test extends PathsBaseTest { @Test void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + String filename = "actual"; // WHEN - AssertionError error = expectAssertionError(() -> paths.assertHasFileName(info, null, "actual")); + AssertionError error = expectAssertionError(() -> paths.assertHasFileName(info, actual, filename)); // THEN then(error).hasMessage(actualIsNull()); } @Test - void should_fail_if_fileName_is_null() { + void should_fail_if_filename_is_null() { // GIVEN Path actual = tempDir.resolve("actual"); + String filename = null; // WHEN - Throwable thrown = catchThrowable(() -> paths.assertHasFileName(info, actual, null)); + Throwable thrown = catchThrowable(() -> paths.assertHasFileName(info, actual, filename)); // THEN then(thrown).isInstanceOf(NullPointerException.class) .hasMessage("expected fileName should not be null"); } @Test - void should_pass_if_non_existing_actual_has_given_fileName() { + void should_fail_if_actual_does_not_have_given_filename() { + // GIVEN + Path actual = tempDir.resolve("actual"); + String filename = "filename"; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasFileName(info, null, filename)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_pass_with_non_existing_path() { // GIVEN Path actual = tempDir.resolve("actual"); + String filename = "actual"; // WHEN/THEN - paths.assertHasFileName(info, actual, "actual"); + paths.assertHasFileName(info, actual, filename); } @Test - void should_pass_if_existing_actual_file_has_given_fileName() throws IOException { + void should_pass_with_existing_regular_file() throws IOException { // GIVEN Path actual = createFile(tempDir.resolve("actual")); + String filename = "actual"; // WHEN/THEN - paths.assertHasFileName(info, actual, "actual"); + paths.assertHasFileName(info, actual, filename); } @Test - void should_pass_if_existing_actual_directory_has_given_fileName() throws IOException { + void should_pass_with_existing_directory() throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); + String filename = "actual"; // WHEN/THEN - paths.assertHasFileName(info, actual, "actual"); + paths.assertHasFileName(info, actual, filename); } @Test - void should_pass_if_existing_actual_symbolic_link_has_given_fileName() throws IOException { + void should_pass_with_existing_symbolic_link() throws IOException { // GIVEN Path actual = createSymbolicLink(tempDir.resolve("actual"), tempDir); + String filename = "actual"; // WHEN/THEN - paths.assertHasFileName(info, actual, "actual"); + paths.assertHasFileName(info, actual, filename); } } From 9b802a514e1fcdf450e78622757a0a86cfd0c84d Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 30 Aug 2021 09:24:09 +0200 Subject: [PATCH 093/123] Reorder binary compatibility steps --- .github/workflows/binary-compatibility.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/binary-compatibility.yml b/.github/workflows/binary-compatibility.yml index 6acf36e8aed..a9f66a32989 100644 --- a/.github/workflows/binary-compatibility.yml +++ b/.github/workflows/binary-compatibility.yml @@ -12,16 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - - name: (PR only) Checkout `${{ github.base_ref }}` into subfolder - if: github.base_ref != null - uses: actions/checkout@v2 - with: - ref: ${{ github.base_ref }} - path: assertj-core.${{ github.base_ref }} - - - name: Setup Java - uses: actions/setup-java@v2 + - uses: actions/setup-java@v2 with: distribution: 'zulu' java-version: 11 @@ -34,6 +25,12 @@ jobs: -DskipTests -Djapicmp.breakBuildOnBinaryIncompatibleModifications=true + - name: (PR only) Checkout `${{ github.base_ref }}` into subfolder + if: github.base_ref != null + uses: actions/checkout@v2 + with: + ref: ${{ github.base_ref }} + path: assertj-core.${{ github.base_ref }} - name: (PR only) Build `${{ github.base_ref }}` if: github.base_ref != null run: ./mvnw -V --no-transfer-progress -e -f assertj-core.${{ github.base_ref }}/pom.xml package -DskipTests From 0299603d9a81e0f97ee9e503be3ab6008fc1f24a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Aug 2021 23:12:04 +0200 Subject: [PATCH 094/123] Bump byte-buddy.version from 1.11.13 to 1.11.14 (#2327) Bumps `byte-buddy.version` from 1.11.13 to 1.11.14. Updates `byte-buddy` from 1.11.13 to 1.11.14 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.13...byte-buddy-1.11.14) Updates `byte-buddy-agent` from 1.11.13 to 1.11.14 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.13...byte-buddy-1.11.14) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2eed5a3d3a8..885d69190ee 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ -Dfile.encoding=${project.build.sourceEncoding} -html5 --allow-script-in-comments --no-module-directories - 1.11.13 + 1.11.14 2.2 1.2.0 5.3.0 From 3db7c4ea4e0e2861795dfc8ea599fd6624b66d4f Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 31 Aug 2021 23:30:00 +0200 Subject: [PATCH 095/123] Add `CollectionAssert` hierarchy (#2315) --- .../core/api/AbstractCollectionAssert.java | 40 +++++++++++ .../core/api/AbstractIterableAssert.java | 11 ++- .../assertj/core/api/AbstractListAssert.java | 2 +- .../java/org/assertj/core/api/Assertions.java | 25 ++++--- .../core/api/AssertionsForInterfaceTypes.java | 13 ++++ .../org/assertj/core/api/Assumptions.java | 21 +++++- .../org/assertj/core/api/BDDAssertions.java | 13 ++++ .../org/assertj/core/api/BDDAssumptions.java | 14 ++++ .../api/ClassBasedNavigableListAssert.java | 3 +- .../assertj/core/api/CollectionAssert.java | 46 +++++++++++++ .../core/api/InstanceOfAssertFactories.java | 25 +++++++ .../org/assertj/core/api/Java6Assertions.java | 13 ++++ .../assertj/core/api/Java6BDDAssertions.java | 13 ++++ .../api/Java6BDDSoftAssertionsProvider.java | 14 ++++ .../Java6StandardSoftAssertionsProvider.java | 18 +++-- .../org/assertj/core/api/WithAssertions.java | 13 ++++ ...ertions_assertThat_with_Iterable_Test.java | 7 +- ...ertions_assertThat_with_Iterator_Test.java | 12 ++-- .../api/InstanceOfAssertFactoriesTest.java | 37 ++++++++-- ...hould_honor_SortedSet_comparator_Test.java | 67 +++++++++---------- 20 files changed, 333 insertions(+), 74 deletions(-) create mode 100644 src/main/java/org/assertj/core/api/AbstractCollectionAssert.java create mode 100644 src/main/java/org/assertj/core/api/CollectionAssert.java diff --git a/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java b/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java new file mode 100644 index 00000000000..e96bdbb679f --- /dev/null +++ b/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java @@ -0,0 +1,40 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api; + +import java.util.Collection; + +/** + * Base class for all implementations of assertions for {@link Collection}s. + * @param the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" + * for more details. + * @param the type of the "actual" value. + * @param the type of elements of the "actual" value. + * @param used for navigational assertions to return the right assert type. + * + * @since 3.21.0 + */ +//@format:off +public abstract class AbstractCollectionAssert, + ACTUAL extends Collection, + ELEMENT, + ELEMENT_ASSERT extends AbstractAssert> + extends AbstractIterableAssert { +//@format:on + + protected AbstractCollectionAssert(ACTUAL actual, Class selfType) { + super(actual, selfType); + } + +} diff --git a/src/main/java/org/assertj/core/api/AbstractIterableAssert.java b/src/main/java/org/assertj/core/api/AbstractIterableAssert.java index 7e7a7faef6e..3e624368730 100644 --- a/src/main/java/org/assertj/core/api/AbstractIterableAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractIterableAssert.java @@ -119,6 +119,13 @@ public abstract class AbstractIterableAssert selfType) { super(actual, selfType); + + if (actual instanceof SortedSet) { + @SuppressWarnings("unchecked") + SortedSet sortedSet = (SortedSet) actual; + Comparator comparator = sortedSet.comparator(); + if (comparator != null) usingElementComparator(sortedSet.comparator()); + } } /** @@ -1517,7 +1524,7 @@ private AbstractListAssert, V, ObjectAssert> newList if (actual instanceof SortedSet) { // Reset the natural element comparator set when building an iterable assert instance for a SortedSet as it is likely not // compatible with extracted values type, example with a SortedSet using a comparator on the Person's age, after - // extracting names we get a a List which is mot suitable for the age comparator + // extracting names we get a List which is mot suitable for the age comparator usingDefaultElementComparator(); } return newListAssertInstance(values).withAssertionState(myself); @@ -2392,7 +2399,7 @@ public SELF usingFieldByFieldElementComparator() { * @return {@code this} assertion object. * @since 2.5.0 / 3.5.0 - breaking change in 3.20.0 * @see RecursiveComparisonConfiguration - * @see usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration) + * @see #usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration) */ @CheckReturnValue public SELF usingRecursiveFieldByFieldElementComparator() { diff --git a/src/main/java/org/assertj/core/api/AbstractListAssert.java b/src/main/java/org/assertj/core/api/AbstractListAssert.java index 05af56c697c..04c5fafd166 100644 --- a/src/main/java/org/assertj/core/api/AbstractListAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractListAssert.java @@ -44,7 +44,7 @@ public abstract class AbstractListAssert, ELEMENT, ELEMENT_ASSERT extends AbstractAssert> - extends AbstractIterableAssert + extends AbstractCollectionAssert implements IndexedObjectEnumerableAssert { // @format:on diff --git a/src/main/java/org/assertj/core/api/Assertions.java b/src/main/java/org/assertj/core/api/Assertions.java index b719a21a58e..0f92ed141a0 100644 --- a/src/main/java/org/assertj/core/api/Assertions.java +++ b/src/main/java/org/assertj/core/api/Assertions.java @@ -36,7 +36,7 @@ import java.time.Period; import java.time.ZonedDateTime; import java.time.temporal.TemporalUnit; -import java.util.Comparator; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -45,7 +45,6 @@ import java.util.OptionalDouble; import java.util.OptionalInt; import java.util.OptionalLong; -import java.util.SortedSet; import java.util.Spliterator; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; @@ -2871,15 +2870,7 @@ public static AbstractStringAssert assertThat(String actual) { * @return the created assertion object. */ public static IterableAssert assertThat(Iterable actual) { - if (actual instanceof SortedSet) { - @SuppressWarnings("unchecked") - SortedSet sortedSet = (SortedSet) actual; - Comparator comparator = sortedSet.comparator(); - return comparator == null - ? new IterableAssert<>(actual) - : new IterableAssert(actual).usingElementComparator(comparator); - } - return new IterableAssert<>(actual); + return AssertionsForInterfaceTypes.assertThat(actual); } /** @@ -2905,6 +2896,18 @@ public static IteratorAssert assertThat(Iterator{@link CollectionAssert}. + * + * @param the type of elements. + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + public static AbstractCollectionAssert, E, ObjectAssert> assertThat(Collection actual) { + return AssertionsForInterfaceTypes.assertThat(actual); + } + /** * Creates a new instance of {@link ListAssert}. * diff --git a/src/main/java/org/assertj/core/api/AssertionsForInterfaceTypes.java b/src/main/java/org/assertj/core/api/AssertionsForInterfaceTypes.java index 2bde801dae0..fcc3c251434 100644 --- a/src/main/java/org/assertj/core/api/AssertionsForInterfaceTypes.java +++ b/src/main/java/org/assertj/core/api/AssertionsForInterfaceTypes.java @@ -13,6 +13,7 @@ package org.assertj.core.api; import java.nio.file.Path; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -118,6 +119,18 @@ public static IteratorAssert assertThat(Iterator(actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the type of elements. + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + public static AbstractCollectionAssert, E, ObjectAssert> assertThat(Collection actual) { + return new CollectionAssert<>(actual); + } + /** * Creates a new instance of {@link ListAssert}. * diff --git a/src/main/java/org/assertj/core/api/Assumptions.java b/src/main/java/org/assertj/core/api/Assumptions.java index ec2cb82bd37..9518eef414f 100644 --- a/src/main/java/org/assertj/core/api/Assumptions.java +++ b/src/main/java/org/assertj/core/api/Assumptions.java @@ -36,6 +36,7 @@ import java.time.OffsetTime; import java.time.Period; import java.time.ZonedDateTime; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -830,6 +831,19 @@ public static IteratorAssert assumeThat(Iterator{@link CollectionAssert} assumption. + * + * @param the type of elements. + * @param actual the actual value. + * @return the created assumption for assertion object. + * @since 3.21.0 + */ + @SuppressWarnings("unchecked") + public static AbstractCollectionAssert, E, ObjectAssert> assumeThat(Collection actual) { + return asAssumption(CollectionAssert.class, Collection.class, actual); + } + /** * Creates a new instance of {@link ListAssert} assumption. * @@ -1335,15 +1349,16 @@ protected static Class generateAssumptionClass( private static AbstractAssert asAssumption(AbstractAssert assertion) { // @format:off Object actual = assertion.actual; - if (assertion instanceof StringAssert) return asAssumption(StringAssert.class, String.class, actual); + if (assertion instanceof AbstractObjectArrayAssert) return asAssumption(ObjectArrayAssert.class, Object[].class, actual); + if (assertion instanceof CollectionAssert) return asAssumption(CollectionAssert.class, Collection.class, actual); if (assertion instanceof FactoryBasedNavigableListAssert) return asAssumption(ListAssert.class, List.class, actual); if (assertion instanceof IterableAssert) return asAssumption(IterableAssert.class, Iterable.class, actual); - if (assertion instanceof MapAssert) return asAssumption(MapAssert.class, Map.class, actual); - if (assertion instanceof AbstractObjectArrayAssert) return asAssumption(ObjectArrayAssert.class, Object[].class, actual); if (assertion instanceof IterableSizeAssert) return asIterableSizeAssumption(assertion); + if (assertion instanceof MapAssert) return asAssumption(MapAssert.class, Map.class, actual); if (assertion instanceof MapSizeAssert) return asMapSizeAssumption(assertion); if (assertion instanceof ObjectAssert) return asAssumption(ObjectAssert.class, Object.class, actual); if (assertion instanceof RecursiveComparisonAssert) return asRecursiveComparisonAssumption(assertion); + if (assertion instanceof StringAssert) return asAssumption(StringAssert.class, String.class, actual); // @format:on // should not arrive here throw new IllegalArgumentException("Unsupported assumption creation for " + assertion.getClass()); diff --git a/src/main/java/org/assertj/core/api/BDDAssertions.java b/src/main/java/org/assertj/core/api/BDDAssertions.java index 3d2080e6d33..8da35449c4a 100644 --- a/src/main/java/org/assertj/core/api/BDDAssertions.java +++ b/src/main/java/org/assertj/core/api/BDDAssertions.java @@ -33,6 +33,7 @@ import java.time.Period; import java.time.ZonedDateTime; import java.time.temporal.TemporalUnit; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -800,6 +801,18 @@ public static AbstractIntegerAssert then(Integer actual) { return assertThat(actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the type of elements. + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + public static AbstractCollectionAssert, E, ObjectAssert> then(Collection actual) { + return assertThat(actual); + } + /** * Creates a new instance of {@link org.assertj.core.api.ListAssert}. * diff --git a/src/main/java/org/assertj/core/api/BDDAssumptions.java b/src/main/java/org/assertj/core/api/BDDAssumptions.java index 5e594e59c9e..c51f4bda7bf 100644 --- a/src/main/java/org/assertj/core/api/BDDAssumptions.java +++ b/src/main/java/org/assertj/core/api/BDDAssumptions.java @@ -31,6 +31,7 @@ import java.time.OffsetTime; import java.time.Period; import java.time.ZonedDateTime; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -1527,6 +1528,19 @@ public static IteratorAssert given(Iterator the type of elements. + * @param actual the actual value. + * @return the created assumption for assertion object. + * @see Assumptions#assumeThat(Collection) + * @since 3.21.0 + */ + public static AbstractCollectionAssert, E, ObjectAssert> given(Collection actual) { + return assumeThat(actual); + } + /** * Creates a new assumption's instance for a {@link List} value. *

    diff --git a/src/main/java/org/assertj/core/api/ClassBasedNavigableListAssert.java b/src/main/java/org/assertj/core/api/ClassBasedNavigableListAssert.java index 64f8969e4de..a23d72dda14 100644 --- a/src/main/java/org/assertj/core/api/ClassBasedNavigableListAssert.java +++ b/src/main/java/org/assertj/core/api/ClassBasedNavigableListAssert.java @@ -46,8 +46,7 @@ private ELEMENT_ASSERT buildAssert(V value, String description, Class cla try { Constructor[] declaredConstructors = assertClass.getDeclaredConstructors(); // find a matching Assert constructor for E or one of its subclass. - for (int i = 0; i < declaredConstructors.length; i++) { - Constructor constructor = declaredConstructors[i]; + for (Constructor constructor : declaredConstructors) { if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0].isAssignableFrom(clazz)) { @SuppressWarnings("unchecked") ELEMENT_ASSERT newAssert = (ELEMENT_ASSERT) constructor.newInstance(value); diff --git a/src/main/java/org/assertj/core/api/CollectionAssert.java b/src/main/java/org/assertj/core/api/CollectionAssert.java new file mode 100644 index 00000000000..64e50ec04d1 --- /dev/null +++ b/src/main/java/org/assertj/core/api/CollectionAssert.java @@ -0,0 +1,46 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api; + +import static org.assertj.core.util.Lists.newArrayList; + +import java.util.Collection; + +/** + * Assertion methods for {@link Collection}s. + *

    + * To create an instance of this class, invoke {@link Assertions#assertThat(Collection)}. + *

    + * + * @param the type of elements of the "actual" value. + * + * @since 3.21.0 + */ +public class CollectionAssert extends + AbstractCollectionAssert, Collection, ELEMENT, ObjectAssert> { + + public CollectionAssert(Collection actual) { + super(actual, CollectionAssert.class); + } + + @Override + protected ObjectAssert toAssert(ELEMENT value, String description) { + return new ObjectAssertFactory().createAssert(value).as(description); + } + + @Override + protected CollectionAssert newAbstractIterableAssert(Iterable iterable) { + return new CollectionAssert<>(newArrayList(iterable)); + } + +} diff --git a/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java b/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java index d83c1d4f930..2bafa450659 100644 --- a/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java +++ b/src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java @@ -28,6 +28,7 @@ import java.time.OffsetTime; import java.time.Period; import java.time.ZonedDateTime; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -813,6 +814,30 @@ static InstanceOfAssertFactory> iter return new InstanceOfAssertFactory<>(Iterator.class, Assertions:: assertThat); } + /** + * {@link InstanceOfAssertFactory} for a {@link Collection}, assuming {@code Object} as element type. + * + * @see #collection(Class) + * @since 3.21.0 + */ + @SuppressWarnings("rawtypes") // rawtypes: using Class instance + InstanceOfAssertFactory, Object, ObjectAssert>> COLLECTION = collection(Object.class); + + /** + * {@link InstanceOfAssertFactory} for a {@link Collection}. + * + * @param the {@code Collection} element type. + * @param elementType the element type instance. + * @return the factory instance. + * + * @see #COLLECTION + * @since 3.21.0 + */ + @SuppressWarnings({ "rawtypes", "unused" }) // rawtypes: using Class instance, unused: parameter needed for type inference + static InstanceOfAssertFactory, E, ObjectAssert>> collection(Class elementType) { + return new InstanceOfAssertFactory<>(Collection.class, Assertions:: assertThat); + } + /** * {@link InstanceOfAssertFactory} for a {@link List}, assuming {@code Object} as element type. * diff --git a/src/main/java/org/assertj/core/api/Java6Assertions.java b/src/main/java/org/assertj/core/api/Java6Assertions.java index 9d567265254..faec4b07bf2 100644 --- a/src/main/java/org/assertj/core/api/Java6Assertions.java +++ b/src/main/java/org/assertj/core/api/Java6Assertions.java @@ -23,6 +23,7 @@ import java.net.URL; import java.nio.charset.Charset; import java.text.DateFormat; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -604,6 +605,18 @@ public static AbstractIntegerAssert assertThat(Integer actual) { return new IntegerAssert(actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the actual elements type + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + public static AbstractCollectionAssert, T, ObjectAssert> assertThat(Collection actual) { + return new CollectionAssert<>(actual); + } + /** * Creates a new instance of {@link ListAssert}. * diff --git a/src/main/java/org/assertj/core/api/Java6BDDAssertions.java b/src/main/java/org/assertj/core/api/Java6BDDAssertions.java index 01a197f2ec4..581822995ab 100644 --- a/src/main/java/org/assertj/core/api/Java6BDDAssertions.java +++ b/src/main/java/org/assertj/core/api/Java6BDDAssertions.java @@ -21,6 +21,7 @@ import java.math.BigInteger; import java.net.URI; import java.net.URL; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -350,6 +351,18 @@ public static AbstractClassAssert then(Class actual) { return assertThat(actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the actual elements type + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + public static AbstractCollectionAssert, T, ObjectAssert> then(Collection actual) { + return assertThat(actual); + } + /** * Creates a new instance of {@link org.assertj.core.api.GenericComparableAssert} with * standard comparison semantics. diff --git a/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java b/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java index 910b92aef0c..da6a386fbdd 100644 --- a/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java +++ b/src/main/java/org/assertj/core/api/Java6BDDSoftAssertionsProvider.java @@ -20,6 +20,7 @@ import java.math.BigInteger; import java.net.URI; import java.net.URL; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -209,6 +210,19 @@ default ClassAssert then(Class actual) { return proxy(ClassAssert.class, Class.class, actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the type of elements. + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + @SuppressWarnings("unchecked") + default CollectionAssert then(Collection actual) { + return proxy(CollectionAssert.class, Collection.class, actual); + } + /** * Creates a new instance of {@link org.assertj.core.api.GenericComparableAssert} with * standard comparison semantics. diff --git a/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java b/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java index f478124b6c8..fa3ccc7447e 100644 --- a/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java +++ b/src/main/java/org/assertj/core/api/Java6StandardSoftAssertionsProvider.java @@ -20,6 +20,7 @@ import java.math.BigInteger; import java.net.URI; import java.net.URL; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -207,6 +208,19 @@ default ClassAssert assertThat(Class actual) { return proxy(ClassAssert.class, Class.class, actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the actual element's type. + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + @SuppressWarnings("unchecked") + default CollectionAssert assertThat(Collection actual) { + return proxy(CollectionAssert.class, Collection.class, actual); + } + /** * Creates a new instance of {@link GenericComparableAssert} with * standard comparison semantics. @@ -222,8 +236,6 @@ default > AbstractComparableAssert assertT /** * Creates a new instance of {@link IterableAssert}. - *

    - * We don't return {@link IterableAssert} as it has overridden methods to annotated with {@link SafeVarargs}. * * @param the actual element's type. * @param actual the actual value. @@ -405,8 +417,6 @@ default IntegerAssert assertThat(Integer actual) { /** * Creates a new instance of {@link ListAssert}. - *

    - * We don't return {@link IterableAssert} as it has overridden methods to annotated with {@link SafeVarargs}. * * @param the actual element's type. * @param actual the actual value. diff --git a/src/main/java/org/assertj/core/api/WithAssertions.java b/src/main/java/org/assertj/core/api/WithAssertions.java index c57501ec468..4ded8cedb6c 100644 --- a/src/main/java/org/assertj/core/api/WithAssertions.java +++ b/src/main/java/org/assertj/core/api/WithAssertions.java @@ -33,6 +33,7 @@ import java.time.Period; import java.time.ZonedDateTime; import java.time.temporal.TemporalUnit; +import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -1056,6 +1057,18 @@ default AbstractDoubleAssert assertThat(final Double actual) { return Assertions.assertThat(actual); } + /** + * Creates a new instance of {@link CollectionAssert}. + * + * @param the type of elements. + * @param actual the actual value. + * @return the created assertion object. + * @since 3.21.0 + */ + default AbstractCollectionAssert, E, ObjectAssert> assertThat(final Collection actual) { + return Assertions.assertThat(actual); + } + /** * Creates a new instance of {@link ListAssert}. * diff --git a/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterable_Test.java b/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterable_Test.java index bc69ffb5781..59855bc2d1b 100644 --- a/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterable_Test.java +++ b/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterable_Test.java @@ -18,8 +18,6 @@ import org.junit.jupiter.api.Test; /** - * Tests for {@link Assertions#assertThat(Iterable)}. - * * @author Alex Ruiz * @author Joel Costigliola */ @@ -27,13 +25,14 @@ class Assertions_assertThat_with_Iterable_Test { @Test void should_create_Assert() { - AbstractIterableAssert, Object, ObjectAssert> assertThat = Assertions.assertThat(newLinkedHashSet()); + Iterable actual = newLinkedHashSet(); + AbstractIterableAssert, Object, ObjectAssert> assertThat = assertThat(actual); assertThat(assertThat).isNotNull(); } @Test void should_pass_actual() { Iterable names = newLinkedHashSet("Luke"); - assertThat(Assertions.assertThat(names).actual).isSameAs(names); + assertThat(assertThat(names).actual).isSameAs(names); } } diff --git a/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterator_Test.java b/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterator_Test.java index d3c40ef4497..a99891257d7 100644 --- a/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterator_Test.java +++ b/src/test/java/org/assertj/core/api/Assertions_assertThat_with_Iterator_Test.java @@ -15,6 +15,7 @@ import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.util.Sets.newLinkedHashSet; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoInteractions; @@ -24,17 +25,15 @@ import org.junit.jupiter.api.Test; /** - * Tests for {@link Assertions#assertThat(Iterator)}. - * * @author Julien Meddah * @author Joel Costigliola * @author Mikhail Mazursky */ class Assertions_assertThat_with_Iterator_Test { - private StringIterator stringIterator = new StringIterator(); + private final StringIterator stringIterator = new StringIterator(); - private final class StringIterator implements Iterator { + private static final class StringIterator implements Iterator { @Override public boolean hasNext() { return true; @@ -51,7 +50,8 @@ public void remove() {} @Test void should_create_Assert() { - AbstractIterableAssert, Object, ObjectAssert> iteratorAssert = assertThat(newLinkedHashSet()); + Iterable actual = newLinkedHashSet(); + AbstractIterableAssert, Object, ObjectAssert> iteratorAssert = assertThat(actual); assertThat(iteratorAssert).isNotNull(); } @@ -145,7 +145,7 @@ void isNotSameAs_should_check_the_original_iterator_without_consuming_it() { verifyNoInteractions(iterator); return; } - Assertions.fail("Expected assertionError, because assert notSame on same iterator."); + fail("Expected assertionError, because assert notSame on same iterator."); } diff --git a/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java b/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java index 7a2bdc8da23..7083bf674db 100644 --- a/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java +++ b/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java @@ -12,7 +12,6 @@ */ package org.assertj.core.api; -import static java.util.Arrays.asList; import static java.util.concurrent.CompletableFuture.completedFuture; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -43,6 +42,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.CHAR_ARRAY; import static org.assertj.core.api.InstanceOfAssertFactories.CHAR_SEQUENCE; import static org.assertj.core.api.InstanceOfAssertFactories.CLASS; +import static org.assertj.core.api.InstanceOfAssertFactories.COLLECTION; import static org.assertj.core.api.InstanceOfAssertFactories.COMPLETABLE_FUTURE; import static org.assertj.core.api.InstanceOfAssertFactories.COMPLETION_STAGE; import static org.assertj.core.api.InstanceOfAssertFactories.DATE; @@ -106,6 +106,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.atomicReferenceArray; import static org.assertj.core.api.InstanceOfAssertFactories.atomicReferenceFieldUpdater; import static org.assertj.core.api.InstanceOfAssertFactories.atomicStampedReference; +import static org.assertj.core.api.InstanceOfAssertFactories.collection; import static org.assertj.core.api.InstanceOfAssertFactories.comparable; import static org.assertj.core.api.InstanceOfAssertFactories.completableFuture; import static org.assertj.core.api.InstanceOfAssertFactories.completionStage; @@ -120,6 +121,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.throwable; import static org.assertj.core.api.InstanceOfAssertFactories.type; import static org.assertj.core.test.Maps.mapOf; +import static org.assertj.core.util.Lists.list; import static org.mockito.Mockito.mock; import java.io.ByteArrayInputStream; @@ -139,6 +141,7 @@ import java.time.OffsetTime; import java.time.Period; import java.time.ZonedDateTime; +import java.util.Collection; import java.util.Date; import java.util.Objects; import java.util.Optional; @@ -1052,7 +1055,7 @@ void string_factory_should_allow_string_assertions() { @Test void iterable_factory_should_allow_iterable_assertions() { // GIVEN - Object value = asList("Homer", "Marge", "Bart", "Lisa", "Maggie"); + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie"); // WHEN IterableAssert result = assertThat(value).asInstanceOf(ITERABLE); // THEN @@ -1062,7 +1065,7 @@ void iterable_factory_should_allow_iterable_assertions() { @Test void typed_iterable_factory_should_allow_typed_iterable_assertions() { // GIVEN - Object value = asList("Homer", "Marge", "Bart", "Lisa", "Maggie"); + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie"); // WHEN IterableAssert result = assertThat(value).asInstanceOf(iterable(String.class)); // THEN @@ -1072,7 +1075,7 @@ void typed_iterable_factory_should_allow_typed_iterable_assertions() { @Test void iterator_factory_should_allow_iterator_assertions() { // GIVEN - Object value = asList("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator(); + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator(); // WHEN IteratorAssert result = assertThat(value).asInstanceOf(ITERATOR); // THEN @@ -1082,17 +1085,37 @@ void iterator_factory_should_allow_iterator_assertions() { @Test void typed_iterator_factory_should_allow_typed_iterator_assertions() { // GIVEN - Object value = asList("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator(); + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie").iterator(); // WHEN IteratorAssert result = assertThat(value).asInstanceOf(iterator(String.class)); // THEN result.hasNext(); } + @Test + void collection_factory_should_allow_collection_assertions() { + // GIVEN + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie"); + // WHEN + AbstractCollectionAssert, Object, ObjectAssert> result = assertThat(value).asInstanceOf(COLLECTION); + // THEN + result.contains("Bart", "Lisa"); + } + + @Test + void typed_collection_factory_should_allow_typed_collection_assertions() { + // GIVEN + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie"); + // WHEN + AbstractCollectionAssert, String, ObjectAssert> result = assertThat(value).asInstanceOf(collection(String.class)); + // THEN + result.contains("Bart", "Lisa"); + } + @Test void list_factory_should_allow_list_assertions() { // GIVEN - Object value = asList("Homer", "Marge", "Bart", "Lisa", "Maggie"); + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie"); // WHEN ListAssert result = assertThat(value).asInstanceOf(LIST); // THEN @@ -1102,7 +1125,7 @@ void list_factory_should_allow_list_assertions() { @Test void typed_list_factory_should_allow_typed_list_assertions() { // GIVEN - Object value = asList("Homer", "Marge", "Bart", "Lisa", "Maggie"); + Object value = list("Homer", "Marge", "Bart", "Lisa", "Maggie"); // WHEN ListAssert result = assertThat(value).asInstanceOf(list(String.class)); // THEN diff --git a/src/test/java/org/assertj/core/api/iterable/IterableAssert_should_honor_SortedSet_comparator_Test.java b/src/test/java/org/assertj/core/api/iterable/IterableAssert_should_honor_SortedSet_comparator_Test.java index 8583e6aa7bd..254feb86936 100644 --- a/src/test/java/org/assertj/core/api/iterable/IterableAssert_should_honor_SortedSet_comparator_Test.java +++ b/src/test/java/org/assertj/core/api/iterable/IterableAssert_should_honor_SortedSet_comparator_Test.java @@ -13,7 +13,7 @@ package org.assertj.core.api.iterable; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.util.Lists.newArrayList; +import static org.assertj.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy; import static org.assertj.core.util.Sets.newLinkedHashSet; import static org.assertj.core.util.Sets.newTreeSet; @@ -21,51 +21,50 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.stream.Stream; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; class IterableAssert_should_honor_SortedSet_comparator_Test { - private Iterable> sets; + @ParameterizedTest + @MethodSource("sets") + void should_honor_sorted_set_comparator(Iterable actual) { + // WHEN/THEN + assertThat(actual).contains("foo"); + assertThat(actual).containsAll(newLinkedHashSet("foo")); + assertThat(actual).containsAnyElementsOf(newLinkedHashSet("foo", "bar")); + assertThat(actual).containsAnyOf("foo", "bar"); + assertThat(actual).containsExactly("foo"); + assertThat(actual).containsExactlyElementsOf(newLinkedHashSet("foo")); + assertThat(actual).containsExactlyInAnyOrder("foo"); + assertThat(actual).containsExactlyInAnyOrderElementsOf(newLinkedHashSet("foo")); + assertThat(actual).containsOnly("foo"); + assertThat(actual).isSubsetOf(newLinkedHashSet("foo")); + assertThat(actual).containsOnlyOnce("foo"); + assertThat(actual).containsOnlyOnceElementsOf(newLinkedHashSet("foo")); + assertThat(actual).containsSequence("foo"); + assertThat(actual).containsSequence(newLinkedHashSet("foo")); + assertThat(actual).containsSubsequence("foo"); + assertThat(actual).containsSubsequence(newLinkedHashSet("foo")); + assertThatAssertionErrorIsThrownBy(() -> assertThat(actual).doesNotContain("foo", "FOO")); + assertThatAssertionErrorIsThrownBy(() -> assertThat(actual).doesNotContainAnyElementsOf(newLinkedHashSet("foo", "FOO"))); + assertThatAssertionErrorIsThrownBy(() -> assertThat(actual).doesNotContainSequence("foo")); + assertThatAssertionErrorIsThrownBy(() -> assertThat(actual).doesNotContainSequence(newLinkedHashSet("foo"))); + assertThatAssertionErrorIsThrownBy(() -> assertThat(actual).doesNotContainSubsequence("foo")); + assertThatAssertionErrorIsThrownBy(() -> assertThat(actual).doesNotContainSubsequence(newLinkedHashSet("foo"))); + } - @BeforeEach - void setup() { + private static Stream> sets() { Set treeSetWithComparator = new TreeSet<>(Comparator.comparing(String::toUpperCase)); treeSetWithComparator.add("FOO"); SortedSet sortedSetWithComparator = new TreeSet<>(Comparator.comparing(String::toUpperCase)); sortedSetWithComparator.add("FOO"); Set treeSet = newTreeSet("foo"); SortedSet sortedSet = newTreeSet("foo"); - sets = newArrayList(sortedSetWithComparator, treeSetWithComparator, sortedSet, treeSet); - } - @Test - void should_honor_sorted_set_comparator() { - assertThat(sets).allSatisfy(set -> { - assertThat(set).contains("foo"); - assertThat(set).containsAll(newLinkedHashSet("foo")); - assertThat(set).containsAnyElementsOf(newLinkedHashSet("foo", "bar")); - assertThat(set).containsAnyOf("foo", "bar"); - assertThat(set).containsExactly("foo"); - assertThat(set).containsExactlyElementsOf(newLinkedHashSet("foo")); - assertThat(set).containsExactlyInAnyOrder("foo"); - assertThat(set).containsExactlyInAnyOrderElementsOf(newLinkedHashSet("foo")); - assertThat(set).containsOnly("foo"); - assertThat(set).isSubsetOf(newLinkedHashSet("foo")); - assertThat(set).containsOnlyOnce("foo"); - assertThat(set).containsOnlyOnceElementsOf(newLinkedHashSet("foo")); - assertThat(set).containsSequence("foo"); - assertThat(set).containsSequence(newLinkedHashSet("foo")); - assertThat(set).containsSubsequence("foo"); - assertThat(set).containsSubsequence(newLinkedHashSet("foo")); - }); - assertThat(sets).noneSatisfy(set -> assertThat(set).doesNotContain("foo", "FOO")); - assertThat(sets).noneSatisfy(set -> assertThat(set).doesNotContainAnyElementsOf(newLinkedHashSet("foo", "FOO"))); - assertThat(sets).noneSatisfy(set -> assertThat(set).doesNotContainSequence("foo")); - assertThat(sets).noneSatisfy(set -> assertThat(set).doesNotContainSequence(newLinkedHashSet("foo"))); - assertThat(sets).noneSatisfy(set -> assertThat(set).doesNotContainSubsequence("foo")); - assertThat(sets).noneSatisfy(set -> assertThat(set).doesNotContainSubsequence(newLinkedHashSet("foo"))); + return Stream.of(sortedSetWithComparator, treeSetWithComparator, sortedSet, treeSet); } } From cec4ecd2844bfa7e86236e51155b6dbbe92f52a2 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Sun, 29 Aug 2021 17:39:41 +1200 Subject: [PATCH 096/123] Replace deprecated org.assertj.core.util.Objects.areEqual by java.util.Objects.deepEquals --- .../comparison/RecursiveComparisonDifferenceCalculator.java | 4 ++-- src/main/java/org/assertj/core/error/ShouldBeEqual.java | 6 +++--- src/main/java/org/assertj/core/internal/Maps.java | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java b/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java index 82563680522..e8bc8d1a1a4 100644 --- a/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java +++ b/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java @@ -13,6 +13,7 @@ package org.assertj.core.api.recursive.comparison; import static java.lang.String.format; +import static java.util.Objects.deepEquals; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toMap; import static org.assertj.core.api.recursive.comparison.ComparisonDifference.rootComparisonDifference; @@ -43,7 +44,6 @@ import java.util.stream.Stream; import org.assertj.core.internal.DeepDifference; -import org.assertj.core.util.Objects; /** * Based on {@link DeepDifference} but takes a {@link RecursiveComparisonConfiguration}, {@link DeepDifference} @@ -689,7 +689,7 @@ private static boolean propertyOrFieldValuesAreEqual(DualValue dualValue, Comparator typeComparator = recursiveComparisonConfiguration.getComparatorForType(fieldType); if (typeComparator != null) return typeComparator.compare(actualFieldValue, expectedFieldValue) == 0; // default comparison using equals - return Objects.areEqual(actualFieldValue, expectedFieldValue); + return deepEquals(actualFieldValue, expectedFieldValue); } private static ComparisonDifference expectedAndActualTypeDifference(Object actual, Object expected) { diff --git a/src/main/java/org/assertj/core/error/ShouldBeEqual.java b/src/main/java/org/assertj/core/error/ShouldBeEqual.java index fd0723563d9..5f6ebbf70d9 100644 --- a/src/main/java/org/assertj/core/error/ShouldBeEqual.java +++ b/src/main/java/org/assertj/core/error/ShouldBeEqual.java @@ -12,9 +12,9 @@ */ package org.assertj.core.error; +import static java.util.Objects.deepEquals; import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.Objects.HASH_CODE_PRIME; -import static org.assertj.core.util.Objects.areEqual; import static org.assertj.core.util.Objects.hashCodeFor; import java.util.Objects; @@ -232,8 +232,8 @@ public boolean equals(Object o) { if (o == null) return false; if (getClass() != o.getClass()) return false; ShouldBeEqual other = (ShouldBeEqual) o; - if (!areEqual(actual, other.actual)) return false; - return areEqual(expected, other.expected); + if (!deepEquals(actual, other.actual)) return false; + return deepEquals(expected, other.expected); } @Override diff --git a/src/main/java/org/assertj/core/internal/Maps.java b/src/main/java/org/assertj/core/internal/Maps.java index c0ac860ac8f..23aca7b87e5 100644 --- a/src/main/java/org/assertj/core/internal/Maps.java +++ b/src/main/java/org/assertj/core/internal/Maps.java @@ -51,7 +51,6 @@ import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.Arrays.asList; import static org.assertj.core.util.IterableUtil.toArray; -import static org.assertj.core.util.Objects.areEqual; import static org.assertj.core.util.Preconditions.checkArgument; import java.lang.reflect.InvocationTargetException; @@ -519,7 +518,7 @@ public void assertContainsExactly(AssertionInfo info, Map actual, E // check entries order int index = 0; for (K keyFromActual : actual.keySet()) { - if (!areEqual(keyFromActual, entries[index].getKey())) { + if (!deepEquals(keyFromActual, entries[index].getKey())) { Entry actualEntry = entry(keyFromActual, actual.get(keyFromActual)); throw failures.failure(info, elementsDifferAtIndex(actualEntry, entries[index], index)); } From 1012521b7a99abc5b6ac9d1360bda38b59894791 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Sun, 29 Aug 2021 18:05:07 +1200 Subject: [PATCH 097/123] Fix typo --- src/main/java/org/assertj/core/internal/Maps.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/assertj/core/internal/Maps.java b/src/main/java/org/assertj/core/internal/Maps.java index 23aca7b87e5..b2a25f705dc 100644 --- a/src/main/java/org/assertj/core/internal/Maps.java +++ b/src/main/java/org/assertj/core/internal/Maps.java @@ -224,7 +224,7 @@ public void assertContains(AssertionInfo info, Map actual, Entry void assertContainsAnyOf(AssertionInfo info, Map actual, Ent assertNotNull(info, actual); // if both actual and values are empty, then assertion passes. if (actual.isEmpty() && entries.length == 0) return; - failIfEntriesIsEmptyEmptySinceActualIsNotEmpty(info, actual, entries); + failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries); for (Entry entry : entries) { if (containsEntry(actual, entry)) return; } @@ -452,7 +452,7 @@ public void assertDoesNotContainValue(AssertionInfo info, Map actua public void assertContainsOnly(AssertionInfo info, Map actual, Entry[] entries) { doCommonContainsCheck(info, actual, entries); if (actual.isEmpty() && entries.length == 0) return; - failIfEntriesIsEmptyEmptySinceActualIsNotEmpty(info, actual, entries); + failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries); Set> notFound = getNotFoundEntries(actual, entries); Set> notExpected = getNotExpectedEntries(actual, entries); @@ -506,7 +506,7 @@ private static void removeEntries(Map map, Entry void assertContainsExactly(AssertionInfo info, Map actual, Entry[] entries) { doCommonContainsCheck(info, actual, entries); if (actual.isEmpty() && entries.length == 0) return; - failIfEntriesIsEmptyEmptySinceActualIsNotEmpty(info, actual, entries); + failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries); assertHasSameSizeAs(info, actual, entries); Set> notFound = new LinkedHashSet<>(); @@ -604,8 +604,8 @@ private void assertNotNull(AssertionInfo info, Map actual) { } // this should be only called when actual is not empty - private void failIfEntriesIsEmptyEmptySinceActualIsNotEmpty(AssertionInfo info, Map actual, - Entry[] entries) { + private void failIfEntriesIsEmptySinceActualIsNotEmpty(AssertionInfo info, Map actual, + Entry[] entries) { if (entries.length == 0) throw failures.failure(info, shouldBeEmpty(actual)); } From b4aa5d5d3195573cc33f681c21790e7aa64aecf0 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Mon, 30 Aug 2021 22:53:06 +1200 Subject: [PATCH 098/123] Change MapEntry representation to be key=value --- .../core/presentation/StandardRepresentation.java | 2 +- .../assertj/core/api/BDDSoftAssertionsTest.java | 10 +++++----- .../org/assertj/core/api/SoftAssertionsTest.java | 10 +++++----- .../java/org/assertj/core/data/MapEntry_Test.java | 4 ++-- .../core/error/ShouldContainOnly_create_Test.java | 14 +++++++------- .../core/error/ShouldContain_create_Test.java | 4 ++-- .../StandardRepresentation_toStringOf_Test.java | 2 +- ...dRepresentation_unambiguousToStringOf_Test.java | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/assertj/core/presentation/StandardRepresentation.java b/src/main/java/org/assertj/core/presentation/StandardRepresentation.java index 4e5b4193c75..60136630871 100644 --- a/src/main/java/org/assertj/core/presentation/StandardRepresentation.java +++ b/src/main/java/org/assertj/core/presentation/StandardRepresentation.java @@ -456,7 +456,7 @@ protected String toStringOf(Tuple tuple) { } protected String toStringOf(MapEntry mapEntry) { - return String.format("MapEntry[key=%s, value=%s]", toStringOf(mapEntry.key), toStringOf(mapEntry.value)); + return String.format("%s=%s", toStringOf(mapEntry.key), toStringOf(mapEntry.value)); } protected String toStringOf(Map map) { diff --git a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java index d44327511ad..1140c6f0a09 100644 --- a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java @@ -178,9 +178,9 @@ void should_be_able_to_catch_exceptions_thrown_by_map_assertions() { assertThat(errors.get(0)).hasMessageContaining(format("Expecting map:%n" + " {\"54\"=\"55\"}%n" + "to contain:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n" + + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n")); + + " [\"1\"=\"2\"]%n")); assertThat(errors.get(1)).hasMessageContaining(format("Expecting empty but was: {\"54\"=\"55\"}")); } @@ -337,9 +337,9 @@ public String toString() { assertThat(errors.get(39)).contains(format("%nExpecting map:%n" + " {\"54\"=\"55\"}%n" + "to contain:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n" + + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n")); + + " [\"1\"=\"2\"]%n")); assertThat(errors.get(40)).contains(shouldBeEqualMessage("12:00", "13:00")); assertThat(errors.get(41)).contains(shouldBeEqualMessage("12:00Z", "13:00Z")); assertThat(errors.get(42)).contains(shouldBeEqualMessage("Optional[not empty]", "\"empty\"")); @@ -1677,7 +1677,7 @@ void map_soft_assertions_should_report_errors_on_final_methods_and_methods_that_ // THEN List errors = softly.errorsCollected(); assertThat(errors).hasSize(16); - assertThat(errors.get(0)).hasMessageContaining("MapEntry[key=\"abc\", value=\"ABC\"]"); + assertThat(errors.get(0)).hasMessageContaining("\"abc\"=\"ABC\""); assertThat(errors.get(1)).hasMessageContaining("empty"); assertThat(errors.get(2)).hasMessageContaining("gh") .hasMessageContaining("IJ"); diff --git a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java index abc316278db..6d3966626b3 100644 --- a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java @@ -179,9 +179,9 @@ void should_be_able_to_catch_exceptions_thrown_by_map_assertions() { assertThat(errors.get(0)).hasMessageStartingWith(format("%nExpecting map:%n" + " {\"54\"=\"55\"}%n" + "to contain:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n" + + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n")); + + " [\"1\"=\"2\"]%n")); assertThat(errors.get(1)).hasMessageStartingWith(format("%nExpecting empty but was: {\"54\"=\"55\"}")); } @@ -370,9 +370,9 @@ public String toString() { assertThat(errors.get(39)).contains(format("%nExpecting map:%n" + " {\"54\"=\"55\"}%n" + "to contain:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n" + + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [MapEntry[key=\"1\", value=\"2\"]]%n")); + + " [\"1\"=\"2\"]%n")); assertThat(errors.get(40)).contains(shouldBeEqualMessage("12:00", "13:00")); assertThat(errors.get(41)).contains(shouldBeEqualMessage("12:00Z", "13:00Z")); @@ -2031,7 +2031,7 @@ void map_soft_assertions_should_report_errors_on_final_methods_and_methods_that_ // THEN List errors = softly.errorsCollected(); assertThat(errors).hasSize(17); - assertThat(errors.get(0)).hasMessageContaining("MapEntry[key=\"abc\", value=\"ABC\"]"); + assertThat(errors.get(0)).hasMessageContaining("\"abc\"=\"ABC\""); assertThat(errors.get(1)).hasMessageContaining("empty"); assertThat(errors.get(2)).hasMessageContaining("gh") .hasMessageContaining("IJ"); diff --git a/src/test/java/org/assertj/core/data/MapEntry_Test.java b/src/test/java/org/assertj/core/data/MapEntry_Test.java index 9bb634bc832..fe564f7d02b 100644 --- a/src/test/java/org/assertj/core/data/MapEntry_Test.java +++ b/src/test/java/org/assertj/core/data/MapEntry_Test.java @@ -51,7 +51,7 @@ void should_implement_toString() { // WHEN String result = underTest.toString(); // THEN - then(result).isEqualTo("MapEntry[key=\"name\", value=\"Yoda\"]"); + then(result).isEqualTo("\"name\"=\"Yoda\""); } @Test @@ -61,7 +61,7 @@ void should_implement_toString_using_standard_representation() { // WHEN String result = underTest.toString(); // THEN - then(result).isEqualTo("MapEntry[key=\"name\", value=[\"Yoda\"]]"); + then(result).isEqualTo("\"name\"=[\"Yoda\"]"); } } diff --git a/src/test/java/org/assertj/core/error/ShouldContainOnly_create_Test.java b/src/test/java/org/assertj/core/error/ShouldContainOnly_create_Test.java index 9915a6a84b7..5f30fc4131b 100644 --- a/src/test/java/org/assertj/core/error/ShouldContainOnly_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldContainOnly_create_Test.java @@ -185,9 +185,9 @@ void should_create_error_message_unexpected_for_map() { + "Expecting map:%n" + " {\"color\"=\"green\", \"name\"=\"Yoda\"}%n" + "to contain only:%n" - + " [MapEntry[key=\"name\", value=\"Yoda\"]]%n" + + " [\"name\"=\"Yoda\"]%n" + "but the following map entries were unexpected:%n" - + " [MapEntry[key=\"color\", value=\"green\"]]%n")); + + " [\"color\"=\"green\"]%n")); } @Test @@ -206,9 +206,9 @@ void should_create_error_message_not_found_for_map() { + "Expecting map:%n" + " {\"name\"=\"Yoda\"}%n" + "to contain only:%n" - + " [MapEntry[key=\"name\", value=\"Yoda\"], MapEntry[key=\"color\", value=\"green\"]]%n" + + " [\"name\"=\"Yoda\", \"color\"=\"green\"]%n" + "but could not find the following map entries:%n" - + " [MapEntry[key=\"color\", value=\"green\"]]%n")); + + " [\"color\"=\"green\"]%n")); } @Test @@ -227,11 +227,11 @@ void should_create_error_message_not_found_and_unexpected_for_map() { + "Expecting map:%n" + " {\"name\"=\"Yoda\"}%n" + "to contain only:%n" - + " [MapEntry[key=\"color\", value=\"green\"]]%n" + + " [\"color\"=\"green\"]%n" + "map entries not found:%n" - + " [MapEntry[key=\"color\", value=\"green\"]]%n" + + " [\"color\"=\"green\"]%n" + "and map entries not expected:%n" - + " [MapEntry[key=\"name\", value=\"Yoda\"]]%n")); + + " [\"name\"=\"Yoda\"]%n")); } @Test diff --git a/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java b/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java index b6c2fcb43ed..8df88fccab2 100644 --- a/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java @@ -123,9 +123,9 @@ void should_create_error_message_for_map() { + "Expecting map:%n" + " {\"1\"=2.0}%n" + "to contain:%n" - + " MapEntry[key=\"3\", value=4.0]%n" + + " \"3\"=4.0%n" + "but could not find the following map entries:%n" - + " MapEntry[key=\"3\", value=4.0]%n")); + + " \"3\"=4.0%n")); } @Test diff --git a/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java b/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java index a10330bad1a..c9a232e0dec 100644 --- a/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java +++ b/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java @@ -368,7 +368,7 @@ void should_format_simple_date_format() { @Test void should_format_assertj_map_entry() { MapEntry entry = entry("A", 1); - assertThat(toStringOf(entry)).isEqualTo("MapEntry[key=\"A\", value=1]"); + assertThat(toStringOf(entry)).isEqualTo("\"A\"=1"); } @Test diff --git a/src/test/java/org/assertj/core/presentation/StandardRepresentation_unambiguousToStringOf_Test.java b/src/test/java/org/assertj/core/presentation/StandardRepresentation_unambiguousToStringOf_Test.java index f5c3154db29..daed7add747 100644 --- a/src/test/java/org/assertj/core/presentation/StandardRepresentation_unambiguousToStringOf_Test.java +++ b/src/test/java/org/assertj/core/presentation/StandardRepresentation_unambiguousToStringOf_Test.java @@ -376,7 +376,7 @@ void should_format_simple_date_format() { @Test void should_format_assertj_map_entry() { MapEntry entry = entry("A", 1); - assertThat(unambiguousToStringOf(entry)).isEqualTo(format("MapEntry[key=\"A\", value=1] (MapEntry@%s)", + assertThat(unambiguousToStringOf(entry)).isEqualTo(format("\"A\"=1 (MapEntry@%s)", toHexString(System.identityHashCode(entry)))); } From 37292a63f8fdc460ef33fa40529d4dfdf91430ad Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Mon, 30 Aug 2021 23:03:40 +1200 Subject: [PATCH 099/123] Format java Map.Entry and assertj MapEntry the same (AssertJ) way --- .../core/presentation/StandardRepresentation.java | 6 +++++- .../StandardRepresentation_toStringOf_Test.java | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/assertj/core/presentation/StandardRepresentation.java b/src/main/java/org/assertj/core/presentation/StandardRepresentation.java index 60136630871..af93a10bc9e 100644 --- a/src/main/java/org/assertj/core/presentation/StandardRepresentation.java +++ b/src/main/java/org/assertj/core/presentation/StandardRepresentation.java @@ -235,7 +235,7 @@ public String toStringOf(Object object) { if (object instanceof Collection) return smartFormat((Collection) object); if (object instanceof Map) return toStringOf((Map) object); if (object instanceof Tuple) return toStringOf((Tuple) object); - if (object instanceof MapEntry) return toStringOf((MapEntry) object); + if (object instanceof Map.Entry) return toStringOf((Map.Entry) object); if (object instanceof Method) return ((Method) object).toGenericString(); if (object instanceof InsertDelta) return toStringOf((InsertDelta) object); if (object instanceof ChangeDelta) return toStringOf((ChangeDelta) object); @@ -459,6 +459,10 @@ protected String toStringOf(MapEntry mapEntry) { return String.format("%s=%s", toStringOf(mapEntry.key), toStringOf(mapEntry.value)); } + protected String toStringOf(Entry javaMapEntry) { + return String.format("%s=%s", toStringOf(javaMapEntry.getKey()), toStringOf(javaMapEntry.getValue())); + } + protected String toStringOf(Map map) { if (map == null) return null; Map sortedMap = toSortedMapIfPossible(map); diff --git a/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java b/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java index c9a232e0dec..7713e5ef1b2 100644 --- a/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java +++ b/src/test/java/org/assertj/core/presentation/StandardRepresentation_toStringOf_Test.java @@ -16,11 +16,12 @@ import static java.time.temporal.ChronoUnit.MILLIS; import static java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; import static org.assertj.core.api.Assertions.tuple; +import static org.assertj.core.api.BDDAssertions.entry; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.Maps.newHashMap; import java.io.File; import java.lang.reflect.Method; @@ -45,6 +46,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicLongFieldUpdater; @@ -371,6 +373,12 @@ void should_format_assertj_map_entry() { assertThat(toStringOf(entry)).isEqualTo("\"A\"=1"); } + @Test + void should_format_java_map_entry() { + Entry entry = newHashMap("key", 123).entrySet().iterator().next(); + assertThat(toStringOf(entry)).isEqualTo("\"key\"=123"); + } + @Test void should_return_toStringOf_method() { Method method = Arrays.stream(GenericClass.class.getMethods()).filter(m -> m.getName().equals("someGenericMethod")) From 35050851746713736911894939a7324795224ea1 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Thu, 2 Sep 2021 22:48:34 +1200 Subject: [PATCH 100/123] Improve containsEntry/containsAllEntriesOf error message when key match but not values. Fixes #2197 --- .../core/error/ShouldContainEntries.java | 101 +++++++++++++++ .../java/org/assertj/core/internal/Maps.java | 13 +- .../core/api/BDDSoftAssertionsTest.java | 8 +- .../assertj/core/api/SoftAssertionsTest.java | 8 +- .../ShouldContainEntries_create_Test.java | 119 ++++++++++++++++++ .../assertj/core/internal/MapsBaseTest.java | 4 +- .../Maps_assertContainsAllEntriesOf_Test.java | 59 ++++++--- .../maps/Maps_assertContains_Test.java | 76 +++++++---- 8 files changed, 336 insertions(+), 52 deletions(-) create mode 100644 src/main/java/org/assertj/core/error/ShouldContainEntries.java create mode 100644 src/test/java/org/assertj/core/error/ShouldContainEntries_create_Test.java diff --git a/src/main/java/org/assertj/core/error/ShouldContainEntries.java b/src/main/java/org/assertj/core/error/ShouldContainEntries.java new file mode 100644 index 00000000000..7f3cbff9e66 --- /dev/null +++ b/src/main/java/org/assertj/core/error/ShouldContainEntries.java @@ -0,0 +1,101 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +import static java.lang.String.format; +import static java.util.stream.Collectors.toList; +import static org.assertj.core.data.MapEntry.entry; +import static org.assertj.core.util.Strings.escapePercent; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.assertj.core.data.MapEntry; +import org.assertj.core.presentation.Representation; + +public class ShouldContainEntries extends BasicErrorMessageFactory { + + public static ErrorMessageFactory shouldContainEntries(Map actual, + Entry[] expectedEntries, + Set> entriesWithWrongValue, + Set> entriesWithKeyNotFound, + Representation representation) { + if (entriesWithWrongValue.isEmpty()) return new ShouldContainEntries(actual, expectedEntries, entriesWithKeyNotFound); + if (entriesWithKeyNotFound.isEmpty()) + return new ShouldContainEntries(actual, expectedEntries, + buildValueDifferences(actual, entriesWithWrongValue, representation)); + // mix of missing keys and keys with different values + return new ShouldContainEntries(actual, expectedEntries, entriesWithKeyNotFound, + buildValueDifferences(actual, entriesWithWrongValue, representation)); + } + + private static List buildValueDifferences(Map actual, + Set> entriesWithWrongValues, + Representation representation) { + return entriesWithWrongValues.stream() + .map(entryWithWrongValue -> valueDifference(actual, entryWithWrongValue, representation)) + .collect(toList()); + } + + private static String valueDifference(Map actual, + Entry entryWithWrongValue, + Representation representation) { + K key = entryWithWrongValue.getKey(); + MapEntry actualEntry = entry(key, actual.get(key)); + V expectedValue = entryWithWrongValue.getValue(); + return escapePercent(format("%s (expected: %s)", representation.toStringOf(actualEntry), + representation.toStringOf(expectedValue))); + } + + private ShouldContainEntries(Map actual, + Entry[] expectedEntries, + Set> notFound) { + super("%nExpecting map:%n" + + " %s%n" + + "to contain entries:%n" + + " %s%n" + + "but could not find the following map entries:%n" + + " %s", + actual, expectedEntries, notFound); + } + + private ShouldContainEntries(Map actual, + Entry[] expectedEntries, + List valueDifferences) { + super("%nExpecting map:%n" + + " %s%n" + + "to contain entries:%n" + + " %s%n" + + "but the following map entries had different values:%n" + + " " + valueDifferences, + actual, expectedEntries, valueDifferences); + } + + private ShouldContainEntries(Map actual, + Entry[] expectedEntries, + Set> keysNotFound, + List valueDifferences) { + super("%nExpecting map:%n" + + " %s%n" + + "to contain entries:%n" + + " %s%n" + + "but could not find the following map entries:%n" + + " %s%n" + + "and the following map entries had different values:%n" + + " " + valueDifferences, + actual, expectedEntries, keysNotFound); + } + +} diff --git a/src/main/java/org/assertj/core/internal/Maps.java b/src/main/java/org/assertj/core/internal/Maps.java index b2a25f705dc..76728f4b36f 100644 --- a/src/main/java/org/assertj/core/internal/Maps.java +++ b/src/main/java/org/assertj/core/internal/Maps.java @@ -22,8 +22,8 @@ import static org.assertj.core.error.NoElementsShouldSatisfy.noElementsShouldSatisfy; import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; -import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; +import static org.assertj.core.error.ShouldContainEntries.shouldContainEntries; import static org.assertj.core.error.ShouldContainEntry.shouldContainEntry; import static org.assertj.core.error.ShouldContainExactly.elementsDifferAtIndex; import static org.assertj.core.error.ShouldContainExactly.shouldContainExactly; @@ -558,11 +558,16 @@ private void doCommonContainsCheck(AssertionInfo info, Map actual, private void failIfAnyEntryNotFoundInActualMap(AssertionInfo info, Map actual, Entry[] entries) { - Set> notFound = new LinkedHashSet<>(); + Set> entriesWithKeyNotFound = new LinkedHashSet<>(); + Set> entriesWithWrongValue = new LinkedHashSet<>(); for (Entry entry : entries) { - if (!containsEntry(actual, entry)) notFound.add(entry); + requireNonNull(entry, ErrorMessages.entryToLookForIsNull()); + if (!actual.containsKey(entry.getKey())) entriesWithKeyNotFound.add(entry); + else if (!containsEntry(actual, entry)) entriesWithWrongValue.add(entry); // can only be wrong value since key was found } - if (!notFound.isEmpty()) throw failures.failure(info, shouldContain(actual, entries, notFound)); + if (!entriesWithWrongValue.isEmpty() || !entriesWithKeyNotFound.isEmpty()) + throw failures.failure(info, shouldContainEntries(actual, entries, entriesWithWrongValue, entriesWithKeyNotFound, + info.representation())); } private static Map entriesToMap(Entry[] entries) { diff --git a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java index 1140c6f0a09..5fb1a4c5f57 100644 --- a/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java @@ -177,10 +177,10 @@ void should_be_able_to_catch_exceptions_thrown_by_map_assertions() { assertThat(errors).hasSize(2); assertThat(errors.get(0)).hasMessageContaining(format("Expecting map:%n" + " {\"54\"=\"55\"}%n" - + "to contain:%n" + + "to contain entries:%n" + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [\"1\"=\"2\"]%n")); + + " [\"1\"=\"2\"]")); assertThat(errors.get(1)).hasMessageContaining(format("Expecting empty but was: {\"54\"=\"55\"}")); } @@ -336,10 +336,10 @@ public String toString() { + " \"something was wrong\"")); assertThat(errors.get(39)).contains(format("%nExpecting map:%n" + " {\"54\"=\"55\"}%n" - + "to contain:%n" + + "to contain entries:%n" + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [\"1\"=\"2\"]%n")); + + " [\"1\"=\"2\"]")); assertThat(errors.get(40)).contains(shouldBeEqualMessage("12:00", "13:00")); assertThat(errors.get(41)).contains(shouldBeEqualMessage("12:00Z", "13:00Z")); assertThat(errors.get(42)).contains(shouldBeEqualMessage("Optional[not empty]", "\"empty\"")); diff --git a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java index 6d3966626b3..1b4e7802c81 100644 --- a/src/test/java/org/assertj/core/api/SoftAssertionsTest.java +++ b/src/test/java/org/assertj/core/api/SoftAssertionsTest.java @@ -178,10 +178,10 @@ void should_be_able_to_catch_exceptions_thrown_by_map_assertions() { assertThat(errors).hasSize(2); assertThat(errors.get(0)).hasMessageStartingWith(format("%nExpecting map:%n" + " {\"54\"=\"55\"}%n" - + "to contain:%n" + + "to contain entries:%n" + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [\"1\"=\"2\"]%n")); + + " [\"1\"=\"2\"]")); assertThat(errors.get(1)).hasMessageStartingWith(format("%nExpecting empty but was: {\"54\"=\"55\"}")); } @@ -369,10 +369,10 @@ public String toString() { + " \"something was wrong\"")); assertThat(errors.get(39)).contains(format("%nExpecting map:%n" + " {\"54\"=\"55\"}%n" - + "to contain:%n" + + "to contain entries:%n" + " [\"1\"=\"2\"]%n" + "but could not find the following map entries:%n" - + " [\"1\"=\"2\"]%n")); + + " [\"1\"=\"2\"]")); assertThat(errors.get(40)).contains(shouldBeEqualMessage("12:00", "13:00")); assertThat(errors.get(41)).contains(shouldBeEqualMessage("12:00Z", "13:00Z")); diff --git a/src/test/java/org/assertj/core/error/ShouldContainEntries_create_Test.java b/src/test/java/org/assertj/core/error/ShouldContainEntries_create_Test.java new file mode 100644 index 00000000000..68936bf944b --- /dev/null +++ b/src/test/java/org/assertj/core/error/ShouldContainEntries_create_Test.java @@ -0,0 +1,119 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +import static java.lang.String.format; +import static java.util.Collections.emptySet; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.data.MapEntry.entry; +import static org.assertj.core.error.ShouldContainEntries.shouldContainEntries; +import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; +import static org.assertj.core.test.Maps.mapOf; +import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.Sets.set; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.assertj.core.description.TextDescription; +import org.junit.jupiter.api.Test; + +class ShouldContainEntries_create_Test { + + @Test + void should_create_error_message_when_all_keys_are_found_but_values_differ() { + // GIVEN + Map map = mapOf(entry("name", "yoda"), entry("color", "green")); + Entry[] expectedEntries = array(entry("name", "vador"), entry("color", "red")); + Set> keysWithWrongValues = set(entry("name", "vador"), entry("color", "red")); + Set> keysNotFound = emptySet(); + ErrorMessageFactory factory = shouldContainEntries(map, expectedEntries, keysWithWrongValues, keysNotFound, + STANDARD_REPRESENTATION); + // WHEN + String message = factory.create(new TextDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting map:%n" + + " {\"color\"=\"green\", \"name\"=\"yoda\"}%n" + + "to contain entries:%n" + + " [\"name\"=\"vador\", \"color\"=\"red\"]%n" + + "but the following map entries had different values:%n" + + " [\"name\"=\"yoda\" (expected: \"vador\"), \"color\"=\"green\" (expected: \"red\")]")); + } + + @Test + void should_create_error_message_when_keys_and_values_differ() { + // GIVEN + Map map = mapOf(entry("name", "yoda"), entry("color", "green")); + Entry[] expectedEntries = array(entry("NAME", "vador"), entry("COLOR", "red")); + Set> keysWithWrongValues = emptySet(); + Set> keysNotFound = set(entry("NAME", "vador"), entry("COLOR", "red")); + ErrorMessageFactory factory = shouldContainEntries(map, expectedEntries, keysWithWrongValues, keysNotFound, + STANDARD_REPRESENTATION); + // WHEN + String message = factory.create(new TextDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting map:%n" + + " {\"color\"=\"green\", \"name\"=\"yoda\"}%n" + + "to contain entries:%n" + + " [\"NAME\"=\"vador\", \"COLOR\"=\"red\"]%n" + + "but could not find the following map entries:%n" + + " [\"NAME\"=\"vador\", \"COLOR\"=\"red\"]")); + } + + @Test + void should_create_error_message_when_no_keys_are_found() { + // GIVEN + Map map = mapOf(entry("name", "yoda"), entry("color", "green")); + Entry[] expectedEntries = array(entry("NAME", "yoda"), entry("COLOR", "green")); + Set> keysWithWrongValues = emptySet(); + Set> keysNotFound = set(entry("NAME", "yoda"), entry("COLOR", "green")); + ErrorMessageFactory factory = shouldContainEntries(map, expectedEntries, keysWithWrongValues, keysNotFound, + STANDARD_REPRESENTATION); + // WHEN + String message = factory.create(new TextDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting map:%n" + + " {\"color\"=\"green\", \"name\"=\"yoda\"}%n" + + "to contain entries:%n" + + " [\"NAME\"=\"yoda\", \"COLOR\"=\"green\"]%n" + + "but could not find the following map entries:%n" + + " [\"NAME\"=\"yoda\", \"COLOR\"=\"green\"]")); + } + + @Test + void should_create_error_message_when_some_keys_are_found_but_values_differ() { + // GIVEN + Map map = mapOf(entry("name", "yoda"), entry("color", "%d"), entry("power", "99%")); + Entry[] expectedEntries = array(entry("NAME", "yoda"), entry("color", "red"), entry("power", "%s")); + Set> keysWithWrongValues = set(entry("color", "red"), entry("power", "%s")); + Set> keysNotFound = set(entry("NAME", "yoda")); + ErrorMessageFactory factory = shouldContainEntries(map, expectedEntries, keysWithWrongValues, keysNotFound, + STANDARD_REPRESENTATION); + // WHEN + String message = factory.create(new TextDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting map:%n" + + " {\"color\"=\"%%d\", \"name\"=\"yoda\", \"power\"=\"99%%\"}%n" + + "to contain entries:%n" + + " [\"NAME\"=\"yoda\", \"color\"=\"red\", \"power\"=\"%%s\"]%n" + + "but could not find the following map entries:%n" + + " [\"NAME\"=\"yoda\"]%n" + + "and the following map entries had different values:%n" + + " [\"color\"=\"%%d\" (expected: \"red\"), \"power\"=\"99%%\" (expected: \"%%s\")]")); + } +} diff --git a/src/test/java/org/assertj/core/internal/MapsBaseTest.java b/src/test/java/org/assertj/core/internal/MapsBaseTest.java index 38f8e14bc60..5c95b5e4da7 100644 --- a/src/test/java/org/assertj/core/internal/MapsBaseTest.java +++ b/src/test/java/org/assertj/core/internal/MapsBaseTest.java @@ -49,8 +49,8 @@ protected void setUp() { info = someInfo(); } - @SuppressWarnings("rawtypes") - protected static MapEntry[] emptyEntries() { + @SuppressWarnings("unchecked") + protected static MapEntry[] emptyEntries() { return new MapEntry[0]; } diff --git a/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsAllEntriesOf_Test.java b/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsAllEntriesOf_Test.java index b5be90115e8..ee333b4d858 100644 --- a/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsAllEntriesOf_Test.java +++ b/src/test/java/org/assertj/core/internal/maps/Maps_assertContainsAllEntriesOf_Test.java @@ -13,18 +13,19 @@ package org.assertj.core.internal.maps; import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; import static org.assertj.core.api.Assertions.catchThrowableOfType; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.data.MapEntry.entry; -import static org.assertj.core.error.ShouldContain.shouldContain; +import static org.assertj.core.error.ShouldContainEntries.shouldContainEntries; import static org.assertj.core.internal.ErrorMessages.mapOfEntriesToLookForIsNull; import static org.assertj.core.test.Maps.mapOf; -import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Sets.set; -import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; import org.assertj.core.internal.MapsBaseTest; import org.junit.jupiter.api.Test; @@ -33,28 +34,28 @@ class Maps_assertContainsAllEntriesOf_Test extends MapsBaseTest { @Test void should_pass_if_actual_contains_given_map_entries() { - maps.assertContainsAllEntriesOf(someInfo(), actual, mapOf(entry("name", "Yoda"))); + maps.assertContainsAllEntriesOf(info, actual, mapOf(entry("name", "Yoda"))); } @Test void should_pass_if_actual_contains_given_map_entries_in_different_order() { - maps.assertContainsAllEntriesOf(someInfo(), actual, mapOf(entry("color", "green"), entry("name", "Yoda"))); + maps.assertContainsAllEntriesOf(info, actual, mapOf(entry("color", "green"), entry("name", "Yoda"))); } @Test void should_pass_if_actual_contains_all_given_map_entries() { - maps.assertContainsAllEntriesOf(someInfo(), actual, mapOf(entry("name", "Yoda"), entry("color", "green"))); + maps.assertContainsAllEntriesOf(info, actual, mapOf(entry("name", "Yoda"), entry("color", "green"))); } @Test void should_pass_if_actual_and_given_map_are_empty() { actual = emptyMap(); - maps.assertContainsAllEntriesOf(someInfo(), actual, mapOf()); + maps.assertContainsAllEntriesOf(info, actual, mapOf()); } @Test void should_pass_if_actual_is_not_empty_and_given_map_is_empty() { - maps.assertContainsAllEntriesOf(someInfo(), actual, emptyMap()); + maps.assertContainsAllEntriesOf(info, actual, emptyMap()); } @Test @@ -62,11 +63,10 @@ void should_throw_error_if_map_of_entries_to_look_for_is_null() { // GIVEN Map other = null; // WHEN - NullPointerException npe = catchThrowableOfType(() -> maps.assertContainsAllEntriesOf(someInfo(), actual, other), + NullPointerException npe = catchThrowableOfType(() -> maps.assertContainsAllEntriesOf(info, actual, other), NullPointerException.class); // THEN - then(npe).isNotNull() - .hasMessage(mapOfEntriesToLookForIsNull()); + then(npe).hasMessage(mapOfEntriesToLookForIsNull()); } @Test @@ -74,7 +74,7 @@ void should_fail_if_actual_is_null() { // GIVEN Map actual = null; // WHEN - AssertionError assertionError = expectAssertionError(() -> maps.assertContainsAllEntriesOf(someInfo(), actual, + AssertionError assertionError = expectAssertionError(() -> maps.assertContainsAllEntriesOf(info, actual, mapOf(entry("name", "Yoda")))); // THEN then(assertionError).hasMessage(actualIsNull()); @@ -83,10 +83,39 @@ void should_fail_if_actual_is_null() { @Test void should_fail_if_actual_does_not_contain_map_entries() { // GIVEN - LinkedHashMap other = mapOf(entry("name", "Yoda"), entry("job", "Jedi")); + Map expected = mapOf(entry("name", "Yoda"), entry("job", "Jedi")); // WHEN - AssertionError assertionError = expectAssertionError(() -> maps.assertContainsAllEntriesOf(info, actual, other)); + AssertionError assertionError = expectAssertionError(() -> maps.assertContainsAllEntriesOf(info, actual, expected)); // THEN - then(assertionError).hasMessage(shouldContain(actual, other.entrySet(), mapOf(entry("job", "Jedi")).entrySet()).create()); + then(assertionError).hasMessage(shouldContainEntries(actual, asEntriesArray(expected), emptySet(), set(entry("job", "Jedi")), + info.representation()).create()); } + + @Test + void should_fail_if_actual_does_not_contain_entries_because_values_differ_for_the_same_key() { + // GIVEN + Map expected = mapOf(entry("name", "Yoda"), entry("color", "red")); + // WHEN + AssertionError assertionError = expectAssertionError(() -> maps.assertContainsAllEntriesOf(info, actual, expected)); + // THEN + then(assertionError).hasMessage(shouldContainEntries(actual, asEntriesArray(expected), set(entry("color", "red")), emptySet(), + info.representation()).create()); + } + + @Test + void should_fail_if_actual_does_not_contain_entries_because_of_some_missing_keys_and_some_values_difference() { + // GIVEN + Map expected = mapOf(entry("name", "Yoda"), entry("color", "red"), entry("job", "Jedi")); + // WHEN + AssertionError assertionError = expectAssertionError(() -> maps.assertContainsAllEntriesOf(info, actual, expected)); + // THEN + then(assertionError).hasMessage(shouldContainEntries(actual, asEntriesArray(expected), set(entry("color", "red")), + set(entry("job", "Jedi")), info.representation()).create()); + } + + @SuppressWarnings("unchecked") + private static Entry[] asEntriesArray(Map expected) { + return expected.entrySet().toArray(new Entry[0]); + } + } diff --git a/src/test/java/org/assertj/core/internal/maps/Maps_assertContains_Test.java b/src/test/java/org/assertj/core/internal/maps/Maps_assertContains_Test.java index 74be1bba4ee..c685cf8d656 100644 --- a/src/test/java/org/assertj/core/internal/maps/Maps_assertContains_Test.java +++ b/src/test/java/org/assertj/core/internal/maps/Maps_assertContains_Test.java @@ -12,25 +12,25 @@ */ package org.assertj.core.internal.maps; +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.data.MapEntry.entry; import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; -import static org.assertj.core.error.ShouldContain.shouldContain; +import static org.assertj.core.error.ShouldContainEntries.shouldContainEntries; import static org.assertj.core.internal.ErrorMessages.entriesToLookForIsNull; import static org.assertj.core.internal.ErrorMessages.entryToLookForIsNull; -import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Sets.newLinkedHashSet; +import static org.assertj.core.util.Sets.set; import static org.mockito.Mockito.verify; -import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.assertj.core.api.AssertionInfo; -import org.assertj.core.data.MapEntry; import org.assertj.core.internal.Maps; import org.assertj.core.internal.MapsBaseTest; import org.junit.jupiter.api.Test; @@ -45,31 +45,28 @@ class Maps_assertContains_Test extends MapsBaseTest { @Test void should_pass_if_actual_contains_given_entries() { - maps.assertContains(someInfo(), actual, array(entry("name", "Yoda"))); + maps.assertContains(info, actual, array(entry("name", "Yoda"))); } @Test void should_pass_if_actual_contains_given_entries_in_different_order() { - maps.assertContains(someInfo(), actual, array(entry("color", "green"), entry("name", "Yoda"))); + maps.assertContains(info, actual, array(entry("color", "green"), entry("name", "Yoda"))); } @Test void should_pass_if_actual_contains_all_given_entries() { - maps.assertContains(someInfo(), actual, array(entry("name", "Yoda"), entry("color", "green"))); + maps.assertContains(info, actual, array(entry("name", "Yoda"), entry("color", "green"))); } - @SuppressWarnings("unchecked") @Test void should_pass_if_actual_and_given_entries_are_empty() { - actual = new HashMap<>(); - maps.assertContains(someInfo(), actual, emptyEntries()); + maps.assertContains(info, emptyMap(), emptyEntries()); } @Test void should_fail_if_array_of_entries_to_look_for_is_empty_and_the_map_under_test_is_not() { // GIVEN - AssertionInfo info = someInfo(); - MapEntry[] expected = emptyEntries(); + Entry[] expected = emptyEntries(); // WHEN expectAssertionError(() -> maps.assertContains(info, actual, expected)); // THEN @@ -79,19 +76,19 @@ void should_fail_if_array_of_entries_to_look_for_is_empty_and_the_map_under_test @Test void should_throw_error_if_array_of_entries_to_look_for_is_null() { // GIVEN - MapEntry[] entries = null; + Entry[] entries = null; // WHEN/THEN - assertThatNullPointerException().isThrownBy(() -> maps.assertContains(someInfo(), actual, entries)) + assertThatNullPointerException().isThrownBy(() -> maps.assertContains(info, actual, entries)) .withMessage(entriesToLookForIsNull()); } @Test void should_throw_error_if_entry_is_null() { // GIVEN - MapEntry nullEntry = null; - MapEntry[] entries = array(nullEntry); + Entry nullEntry = null; + Entry[] entries = array(nullEntry); // WHEN/THEN - assertThatNullPointerException().isThrownBy(() -> maps.assertContains(someInfo(), actual, entries)) + assertThatNullPointerException().isThrownBy(() -> maps.assertContains(info, actual, entries)) .withMessage(entryToLookForIsNull()); } @@ -99,21 +96,54 @@ void should_throw_error_if_entry_is_null() { void should_fail_if_actual_is_null() { // GIVEN actual = null; - MapEntry[] expected = array(entry("name", "Yoda")); + Entry[] expected = array(entry("name", "Yoda")); // WHEN - AssertionError assertionError = expectAssertionError(() -> maps.assertContains(someInfo(), actual, expected)); + AssertionError assertionError = expectAssertionError(() -> maps.assertContains(info, actual, expected)); // THEN then(assertionError).hasMessage(actualIsNull()); } + @Test + void should_fail_if_actual_is_empty_and_expected_entries_is_not() { + // GIVEN + Entry[] expected = array(entry("a", "1")); + // WHEN + expectAssertionError(() -> maps.assertContains(info, emptyMap(), expected)); + // THEN + verify(failures).failure(info, + shouldContainEntries(emptyMap(), expected, emptySet(), set(entry("a", "1")), info.representation())); + } + @Test void should_fail_if_actual_does_not_contain_entries() { // GIVEN - AssertionInfo info = someInfo(); - MapEntry[] expected = array(entry("name", "Yoda"), entry("job", "Jedi")); + Entry[] expected = array(entry("name", "Yoda"), entry("job", "Jedi")); + // WHEN + expectAssertionError(() -> maps.assertContains(info, actual, expected)); + // THEN + verify(failures).failure(info, shouldContainEntries(actual, expected, emptySet(), set(entry("job", "Jedi")), + info.representation())); + } + + @Test + void should_fail_if_actual_does_not_contain_entries_because_values_differ_for_the_same_key() { + // GIVEN + Entry[] expected = array(entry("name", "Yoda"), entry("color", "red")); + // WHEN + expectAssertionError(() -> maps.assertContains(info, actual, expected)); + // THEN + verify(failures).failure(info, shouldContainEntries(actual, expected, set(entry("color", "red")), emptySet(), + info.representation())); + } + + @Test + void should_fail_if_actual_does_not_contain_entries_because_of_some_missing_keys_and_some_values_difference() { + // GIVEN + Entry[] expected = array(entry("name", "Yoda"), entry("color", "red"), entry("job", "Jedi")); // WHEN expectAssertionError(() -> maps.assertContains(info, actual, expected)); // THEN - verify(failures).failure(info, shouldContain(actual, expected, newLinkedHashSet(entry("job", "Jedi")))); + verify(failures).failure(info, shouldContainEntries(actual, expected, set(entry("color", "red")), set(entry("job", "Jedi")), + info.representation())); } } From 49941cbf852c3cbf1fc5e4c75ec4d6cd613ea295 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Sep 2021 22:33:27 +0200 Subject: [PATCH 101/123] Bump cdg.pitest.version from 0.0.13 to 0.1.0 (#2330) * Bump cdg.pitest.version from 0.0.13 to 0.1.0 Bumps `cdg.pitest.version` from 0.0.13 to 0.1.0. Updates `pitest-git-plugin` from 0.0.13 to 0.1.0 Updates `pitest-git-maven-plugin` from 0.0.13 to 0.1.0 --- updated-dependencies: - dependency-name: com.groupcdg:pitest-git-plugin dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.groupcdg:pitest-git-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump pitest-github-maven-plugin from 0.0.13 to 0.1.0 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefano Cordio --- .github/workflows/pitest-updated-pr.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pitest-updated-pr.yml b/.github/workflows/pitest-updated-pr.yml index a19c0899928..68576f90074 100644 --- a/.github/workflows/pitest-updated-pr.yml +++ b/.github/workflows/pitest-updated-pr.yml @@ -42,4 +42,4 @@ jobs: # The updatePR maven goal is used here with an explicit version. This allows us to upload without checking out # the code, but does mean the version here must be maintained. An alternative would be to checkout the code and use # the github goal. This will work as long as the artifact is extracted to the maven target directory - run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.0.13:updatePR + run: mvn -DrepoToken=${{ secrets.GITHUB_TOKEN }} com.groupcdg:pitest-github-maven-plugin:0.1.0:updatePR diff --git a/pom.xml b/pom.xml index 885d69190ee..f0b1341876b 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 2.2 1.2.0 5.3.0 - 0.0.13 + 0.1.0 4.13.2 5.7.2 From 6a375b3a76e1d2effb69a78125ec869950547070 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Sep 2021 22:33:41 +0200 Subject: [PATCH 102/123] Bump pitest-maven from 1.6.9 to 1.7.0 (#2331) Bumps [pitest-maven](https://github.com/hcoles/pitest) from 1.6.9 to 1.7.0. - [Release notes](https://github.com/hcoles/pitest/releases) - [Commits](https://github.com/hcoles/pitest/compare/1.6.9...1.7.0) --- updated-dependencies: - dependency-name: org.pitest:pitest-maven dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f0b1341876b..46be96c5a36 100644 --- a/pom.xml +++ b/pom.xml @@ -653,7 +653,7 @@ org.pitest pitest-maven - 1.6.9 + 1.7.0 org.pitest From f136350fa6b0863e43a4e36e48e139bf64ec4958 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Sep 2021 23:17:55 +0200 Subject: [PATCH 103/123] Bump byte-buddy.version from 1.11.14 to 1.11.15 (#2332) Bumps `byte-buddy.version` from 1.11.14 to 1.11.15. Updates `byte-buddy` from 1.11.14 to 1.11.15 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.14...byte-buddy-1.11.15) Updates `byte-buddy-agent` from 1.11.14 to 1.11.15 - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.11.14...byte-buddy-1.11.15) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: net.bytebuddy:byte-buddy-agent dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 46be96c5a36..c2fe4a28a3c 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ -Dfile.encoding=${project.build.sourceEncoding} -html5 --allow-script-in-comments --no-module-directories - 1.11.14 + 1.11.15 2.2 1.2.0 5.3.0 From f9a8922d6a848aec72dd7910c38914ec473b7ea0 Mon Sep 17 00:00:00 2001 From: talentedasian Date: Tue, 31 Aug 2021 21:25:34 +0800 Subject: [PATCH 104/123] Add assertHasScale method for BigDecimals Fixes #2321 --- .../core/api/AbstractBigDecimalAssert.java | 20 ++++++ .../assertj/core/error/ShouldHaveScale.java | 30 ++++++++ .../assertj/core/internal/BigDecimals.java | 9 +++ ...gDecimalsAssert_assertHasScaleOf_Test.java | 32 +++++++++ .../error/ShouldHaveScale_create_Test.java | 42 +++++++++++ .../core/internal/NumbersBaseTest.java | 9 ++- .../BigDecimals_assertHasScale_Test.java | 71 +++++++++++++++++++ 7 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/assertj/core/error/ShouldHaveScale.java create mode 100644 src/test/java/org/assertj/core/api/bigdecimal/BigDecimalsAssert_assertHasScaleOf_Test.java create mode 100644 src/test/java/org/assertj/core/error/ShouldHaveScale_create_Test.java create mode 100644 src/test/java/org/assertj/core/internal/bigdecimals/BigDecimals_assertHasScale_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractBigDecimalAssert.java b/src/main/java/org/assertj/core/api/AbstractBigDecimalAssert.java index a87d72853db..d7b38fbc1f3 100644 --- a/src/main/java/org/assertj/core/api/AbstractBigDecimalAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractBigDecimalAssert.java @@ -263,6 +263,26 @@ public SELF isNotEqualByComparingTo(String notExpected) { return isNotEqualByComparingTo(new BigDecimal(notExpected)); } + /** + * Verifies the BigDecimal under test has the given scale. + *

    + * Example: + *

     // assertions will pass
    +   * assertThat(new BigDecimal("8.00")).hasScaleOf(2);
    +   * assertThat(new BigDecimal("8.00").setScale(4)).hasScaleOf(4);
    +   *
    +   * // assertion will fail
    +   * assertThat(new BigDecimal("8.00")).hasScaleOf(3);
    +   * assertThat(new BigDecimal("8.00").setScale(4)).hasScaleOf(2);
    + * + * @param expectedScale the expected scale value. + * @return {@code this} assertion object. + */ + public SELF hasScaleOf(int expectedScale) { + bigDecimals.assertHasScale(info, actual, expectedScale); + return myself; + } + @Override @CheckReturnValue public SELF usingComparator(Comparator customComparator) { diff --git a/src/main/java/org/assertj/core/error/ShouldHaveScale.java b/src/main/java/org/assertj/core/error/ShouldHaveScale.java new file mode 100644 index 00000000000..939977d90c5 --- /dev/null +++ b/src/main/java/org/assertj/core/error/ShouldHaveScale.java @@ -0,0 +1,30 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +import java.math.BigDecimal; + +public class ShouldHaveScale extends BasicErrorMessageFactory { + + public static ErrorMessageFactory shouldHaveScale(BigDecimal actual, int expectedScale) { + return new ShouldHaveScale(actual, expectedScale); + } + + private ShouldHaveScale(BigDecimal actual, int expectedScale) { + super("%nexpecting actual %s to have a scale of:%n" + + " %s%n" + + "but had a scale of:%n" + + " %s", + actual, expectedScale, actual.scale()); + } +} diff --git a/src/main/java/org/assertj/core/internal/BigDecimals.java b/src/main/java/org/assertj/core/internal/BigDecimals.java index 4f1c7507549..30b4bfac384 100644 --- a/src/main/java/org/assertj/core/internal/BigDecimals.java +++ b/src/main/java/org/assertj/core/internal/BigDecimals.java @@ -14,9 +14,11 @@ import static java.math.BigDecimal.ONE; import static java.math.BigDecimal.ZERO; +import static org.assertj.core.error.ShouldHaveScale.shouldHaveScale; import java.math.BigDecimal; +import org.assertj.core.api.AssertionInfo; import org.assertj.core.util.VisibleForTesting; /** @@ -75,4 +77,11 @@ protected boolean areEqual(BigDecimal value1, BigDecimal value2) { if (value2 == null) return false; return value1.compareTo(value2) == 0; } + + public void assertHasScale(AssertionInfo info, BigDecimal actual, int expectedScale) { + assertNotNull(info, actual); + if (areEqual(actual.scale(), expectedScale)) return; + throw failures.failure(info, shouldHaveScale(actual, expectedScale)); + } + } diff --git a/src/test/java/org/assertj/core/api/bigdecimal/BigDecimalsAssert_assertHasScaleOf_Test.java b/src/test/java/org/assertj/core/api/bigdecimal/BigDecimalsAssert_assertHasScaleOf_Test.java new file mode 100644 index 00000000000..01c33f5e865 --- /dev/null +++ b/src/test/java/org/assertj/core/api/bigdecimal/BigDecimalsAssert_assertHasScaleOf_Test.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.bigdecimal; + +import org.assertj.core.api.BigDecimalAssert; +import org.assertj.core.api.BigDecimalAssertBaseTest; + +import static org.mockito.Mockito.verify; + +class BigDecimalsAssert_assertHasScaleOf_Test extends BigDecimalAssertBaseTest { + + @Override + protected BigDecimalAssert invoke_api_method() { + return assertions.hasScaleOf(0); + } + + @Override + protected void verify_internal_effects() { + verify(bigDecimals).assertHasScale(getInfo(assertions), getActual(assertions), 0); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldHaveScale_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveScale_create_Test.java new file mode 100644 index 00000000000..4a8973b73a3 --- /dev/null +++ b/src/test/java/org/assertj/core/error/ShouldHaveScale_create_Test.java @@ -0,0 +1,42 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +import static java.lang.String.format; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldHaveScale.shouldHaveScale; + +import java.math.BigDecimal; + +import org.assertj.core.description.TextDescription; +import org.assertj.core.presentation.StandardRepresentation; +import org.junit.jupiter.api.Test; + +class ShouldHaveScale_create_Test { + + @Test + public void should_create_error_message() { + // GIVEN + BigDecimal actual = new BigDecimal("1.000"); + ErrorMessageFactory factory = shouldHaveScale(actual, 4); + // WHEN + String message = factory.create(new TextDescription("Test"), new StandardRepresentation()); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "expecting actual %s to have a scale of:%n" + + " 4%n" + + "but had a scale of:%n" + + " 3", actual)); + } + +} diff --git a/src/test/java/org/assertj/core/internal/NumbersBaseTest.java b/src/test/java/org/assertj/core/internal/NumbersBaseTest.java index 07c9013c726..d4669817c70 100644 --- a/src/test/java/org/assertj/core/internal/NumbersBaseTest.java +++ b/src/test/java/org/assertj/core/internal/NumbersBaseTest.java @@ -13,16 +13,19 @@ package org.assertj.core.internal; -import org.assertj.core.util.AbsValueComparator; -import org.junit.jupiter.api.BeforeEach; +import static org.assertj.core.test.TestData.someInfo; +import static org.mockito.Mockito.spy; import java.util.Comparator; -import static org.mockito.Mockito.spy; +import org.assertj.core.api.AssertionInfo; +import org.assertj.core.util.AbsValueComparator; +import org.junit.jupiter.api.BeforeEach; public abstract class NumbersBaseTest, NUMBER_TYPE extends Number> { protected Failures failures; + protected AssertionInfo info = someInfo(); protected NUMBERS_TYPE numbers; protected ComparatorBasedComparisonStrategy comparatorComparisonStrategy; diff --git a/src/test/java/org/assertj/core/internal/bigdecimals/BigDecimals_assertHasScale_Test.java b/src/test/java/org/assertj/core/internal/bigdecimals/BigDecimals_assertHasScale_Test.java new file mode 100644 index 00000000000..b0c1f1921c4 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/bigdecimals/BigDecimals_assertHasScale_Test.java @@ -0,0 +1,71 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.bigdecimals; + +import static java.math.BigDecimal.ONE; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldHaveScale.shouldHaveScale; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.mockito.Mockito.verify; + +import java.math.BigDecimal; + +import org.assertj.core.internal.BigDecimalsBaseTest; +import org.junit.jupiter.api.Test; + +class BigDecimals_assertHasScale_Test extends BigDecimalsBaseTest { + + @Test + void should_fail_if_actual_is_null() { + //GIVEN + BigDecimal nullBigDecimal = null; + // WHEN + AssertionError assertionError = expectAssertionError(() -> numbers.assertHasScale(info, nullBigDecimal, 0)); + // THEN + then(assertionError).hasMessage(actualIsNull()); + } + + @Test + void should_pass_if_scales_are_equal() { + numbers.assertHasScale(info, ONE_WITH_3_DECIMALS, 3); + } + + @Test + void should_pass_if_scales_are_equal_whatever_custom_strategy_is_used() { + numbersWithAbsValueComparisonStrategy.assertHasScale(info, ONE_WITH_3_DECIMALS, 3); + } + + @Test + void should_fail_if_scales_are_not_equal() { + // GIVEN + final int expectedScale = 3; + BigDecimal zeroScaleBigDecimal = ONE; + // WHEN + expectAssertionError(() -> numbers.assertHasScale(info, zeroScaleBigDecimal, expectedScale)); + // THEN + verify(failures).failure(info, shouldHaveScale(zeroScaleBigDecimal, expectedScale)); + } + + @Test + void should_fail_if_scales_are_not_equal_whatever_custom_strategy_is_used() { + // GIVEN + final int expectesScale = 3; + BigDecimal zeroScaleBigDecimal = ONE; + // WHEN + expectAssertionError(() -> numbers.assertHasScale(info, zeroScaleBigDecimal, expectesScale)); + // THEN + verify(failures).failure(info, shouldHaveScale(zeroScaleBigDecimal, expectesScale)); + } + +} From ccc03aca55236e0efa4eb38054e174d5c9c59db6 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 5 Sep 2021 11:26:47 +0200 Subject: [PATCH 105/123] Add bug reference --- ...ndardComparisonStrategy_areEqual_Test.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java b/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java index af0420561d0..acbac9a2078 100644 --- a/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java +++ b/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java @@ -18,18 +18,14 @@ import java.util.stream.Stream; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; /** - * Tests for {@link StandardComparisonStrategy#areEqual(Object, Object)}. - * * @author Joel Costigliola */ -@DisplayName("StandardComparisonStrategy areEqual") class StandardComparisonStrategy_areEqual_Test { private final StandardComparisonStrategy underTest = StandardComparisonStrategy.instance(); @@ -261,16 +257,15 @@ void should_return_false_if_array_is_non_null_and_other_is_null(Object actual) { private static Stream arrays() { return Stream.of( -// new Object[] { "Luke", "Yoda", "Leia" }, // FIXME only "Luke" gets injected as single object - new byte[] { 1, 2, 3 }, - new short[] { 1, 2, 3 }, - new int[] { 1, 2, 3 }, - new long[] { 1L, 2L, 3L }, - new char[] { '1', '2', '3' }, - new float[] { 1.0f, 2.0f, 3.0f }, - new double[] { 1.0, 2.0, 3.0 }, - new boolean[] { true, false } - ); +// new Object[] { "Luke", "Yoda", "Leia" }, // FIXME junit-team/junit5#2708 + new byte[] { 1, 2, 3 }, + new short[] { 1, 2, 3 }, + new int[] { 1, 2, 3 }, + new long[] { 1L, 2L, 3L }, + new char[] { '1', '2', '3' }, + new float[] { 1.0f, 2.0f, 3.0f }, + new double[] { 1.0, 2.0, 3.0 }, + new boolean[] { true, false }); } @Test @@ -309,9 +304,9 @@ void should_delegate_to_inconsistent_equals_implementation() { Object actual = new NonConsistent(); // WHEN boolean[] results = { - underTest.areEqual(actual, actual), - underTest.areEqual(actual, actual), - underTest.areEqual(actual, actual) + underTest.areEqual(actual, actual), + underTest.areEqual(actual, actual), + underTest.areEqual(actual, actual) }; // THEN then(results).containsExactly(true, false, true); From 43edf5862d5984af1a6882323874091455bdab3a Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 5 Sep 2021 22:17:28 +0200 Subject: [PATCH 106/123] Deprecate `Lists.emptyList()` --- .../java/org/assertj/core/util/Lists.java | 3 + .../iterator/IteratorAssert_hasNext_Test.java | 7 +- .../IteratorAssert_isExhausted_Test.java | 7 +- .../ShouldHaveAllNullFields_create_Test.java | 5 +- ..._assertContainsExactlyInAnyOrder_Test.java | 36 +++++---- ..._assertContainsExactlyInAnyOrder_Test.java | 80 +++++++++++-------- ...nAnyOrder_with_Integer_Arguments_Test.java | 71 ++++++++++------ ..._assertContainsExactlyInAnyOrder_Test.java | 79 ++++++++++-------- ..._assertContainsExactlyInAnyOrder_Test.java | 28 ++++--- ...tIsDirectoryContaining_Predicate_Test.java | 2 +- ...ctoryContaining_SyntaxAndPattern_Test.java | 2 +- ...DirectoryNotContaining_Predicate_Test.java | 2 +- ...ryNotContaining_SyntaxAndPattern_Test.java | 2 +- ...yRecursivelyContaining_Predicate_Test.java | 2 +- ...ivelyContaining_SyntaxAndPattern_Test.java | 2 +- .../Files_assertIsEmptyDirectory_Test.java | 6 +- .../Files_assertIsNotEmptyDirectory_Test.java | 2 +- ..._assertContainsExactlyInAnyOrder_Test.java | 76 +++++++++++------- ..._assertContainsExactlyInAnyOrder_Test.java | 80 +++++++++++-------- .../Iterables_assertAnySatisfy_Test.java | 42 +++++----- ..._assertContainsExactlyInAnyOrder_Test.java | 75 ++++++++++------- ...Maps_assertAnySatisfyingConsumer_Test.java | 2 +- ..._assertContainsExactlyInAnyOrder_Test.java | 52 +++++++----- ...sAllNullFieldsOrPropertiesExcept_Test.java | 2 +- ...rectoryContaining_with_Predicate_Test.java | 2 +- ...sDirectoryContaining_with_String_Test.java | 2 +- ...yRecursivelyContaining_Predicate_Test.java | 2 +- ...ivelyContaining_SyntaxAndPattern_Test.java | 2 +- ..._assertContainsExactlyInAnyOrder_Test.java | 74 ++++++++++------- .../core/util/Lists_emptyList_Test.java | 5 +- 30 files changed, 439 insertions(+), 313 deletions(-) diff --git a/src/main/java/org/assertj/core/util/Lists.java b/src/main/java/org/assertj/core/util/Lists.java index d15356bd066..cfae6fa916a 100644 --- a/src/main/java/org/assertj/core/util/Lists.java +++ b/src/main/java/org/assertj/core/util/Lists.java @@ -89,9 +89,12 @@ public static ArrayList newArrayList() { } /** + * @deprecated use {@link Collections#emptyList()} instead. + * * @param the generic type of the {@code List}. * @return an empty, immutable {@code List}. */ + @Deprecated public static List emptyList() { return Collections.emptyList(); } diff --git a/src/test/java/org/assertj/core/api/iterator/IteratorAssert_hasNext_Test.java b/src/test/java/org/assertj/core/api/iterator/IteratorAssert_hasNext_Test.java index ae06b272a7b..cd1379116a8 100644 --- a/src/test/java/org/assertj/core/api/iterator/IteratorAssert_hasNext_Test.java +++ b/src/test/java/org/assertj/core/api/iterator/IteratorAssert_hasNext_Test.java @@ -12,24 +12,21 @@ */ package org.assertj.core.api.iterator; +import static java.util.Collections.emptyIterator; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowableOfType; import static org.assertj.core.error.ShouldHaveNext.shouldHaveNext; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.Mockito.verify; import java.util.Iterator; -import org.assertj.core.api.AbstractIteratorAssert; import org.assertj.core.api.IteratorAssert; import org.assertj.core.api.IteratorAssertBaseTest; import org.junit.jupiter.api.Test; /** - * Tests for {@link AbstractIteratorAssert#hasNext()} ()}. - * * @author Stephan Windmüller */ class IteratorAssert_hasNext_Test extends IteratorAssertBaseTest { @@ -53,7 +50,7 @@ void should_pass_if_actual_has_at_least_one_element() { @Test void should_fail_for_exhausted_iterator() { // GIVEN - Iterator iterator = emptyList().iterator(); + Iterator iterator = emptyIterator(); // WHEN AssertionError error = catchThrowableOfType(assertThat(iterator)::hasNext, AssertionError.class); // THEN diff --git a/src/test/java/org/assertj/core/api/iterator/IteratorAssert_isExhausted_Test.java b/src/test/java/org/assertj/core/api/iterator/IteratorAssert_isExhausted_Test.java index e1c055dd917..a571f96026b 100644 --- a/src/test/java/org/assertj/core/api/iterator/IteratorAssert_isExhausted_Test.java +++ b/src/test/java/org/assertj/core/api/iterator/IteratorAssert_isExhausted_Test.java @@ -16,20 +16,17 @@ import static org.assertj.core.api.Assertions.catchThrowableOfType; import static org.assertj.core.error.ShouldBeExhausted.shouldBeExhausted; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; +import java.util.Collections; import java.util.Iterator; -import org.assertj.core.api.AbstractIteratorAssert; import org.assertj.core.api.IteratorAssert; import org.assertj.core.api.IteratorAssertBaseTest; import org.junit.jupiter.api.Test; /** - * Tests for {@link AbstractIteratorAssert#isExhausted()} ()}. - * * @author Stephan Windmüller */ class IteratorAssert_isExhausted_Test extends IteratorAssertBaseTest { @@ -46,7 +43,7 @@ protected void verify_internal_effects() { @Test void should_pass_for_exhausted_iterator() { - Iterator iterator = emptyList().iterator(); + Iterator iterator = Collections.emptyIterator(); assertThat(iterator).isExhausted(); } diff --git a/src/test/java/org/assertj/core/error/ShouldHaveAllNullFields_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveAllNullFields_create_Test.java index 604d0e7d2bb..93b270db3ce 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveAllNullFields_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveAllNullFields_create_Test.java @@ -13,9 +13,9 @@ package org.assertj.core.error; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldHaveAllNullFields.shouldHaveAllNullFields; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import java.util.List; @@ -26,9 +26,6 @@ import org.junit.jupiter.api.Test; /** - * Tests for - * {@link ShouldHaveAllNullFields#shouldHaveAllNullFields(Object, List, List)} - * * @author Vladimir Chernikov */ class ShouldHaveAllNullFields_create_Test { diff --git a/src/test/java/org/assertj/core/internal/booleanarrays/BooleanArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/booleanarrays/BooleanArrays_assertContainsExactlyInAnyOrder_Test.java index 0b0966b070c..4215377c5f0 100644 --- a/src/test/java/org/assertj/core/internal/booleanarrays/BooleanArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/booleanarrays/BooleanArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.booleanarrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,19 +23,14 @@ import static org.assertj.core.test.BooleanArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.BooleanArrays; import org.assertj.core.internal.BooleanArraysBaseTest; import org.assertj.core.internal.StandardComparisonStrategy; import org.junit.jupiter.api.Test; -/** - * Tests for {@link BooleanArrays#assertContainsExactlyInAnyOrder(AssertionInfo, boolean[], boolean[])}. - */ class BooleanArrays_assertContainsExactlyInAnyOrder_Test extends BooleanArraysBaseTest { @Test @@ -55,12 +51,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(true))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(true))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -73,59 +71,63 @@ void should_throw_error_if_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(true))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(true))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - boolean[] expected = {true, true}; + boolean[] expected = { true, true }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, - newArrayList(true), newArrayList(false), StandardComparisonStrategy.instance())); + newArrayList(true), newArrayList(false), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - boolean[] expected = {true}; + boolean[] expected = { true }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(false), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(false), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(true, false, true); - boolean[] expected = {true, false}; + boolean[] expected = { true, false }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(true), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(true), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(true, false); - boolean[] expected = {true, false, true}; + boolean[] expected = { true, false, true }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(true), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(true), emptyList(), + StandardComparisonStrategy.instance())); } } diff --git a/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_Test.java index a12cbcdd860..1f2be4f1957 100644 --- a/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.bytearrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.ByteArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -55,12 +55,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6, 8))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(6, 8))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -72,60 +74,63 @@ void should_throw_error_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - byte[] expected = {6, 8, 20}; + byte[] expected = { 6, 8, 20 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, - newArrayList((byte) 20), newArrayList((byte) 10), StandardComparisonStrategy.instance())); + newArrayList((byte) 20), newArrayList((byte) 10), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - byte[] expected = {6, 8}; + byte[] expected = { 6, 8 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 10), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 10), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(6, 8, 8); - byte[] expected = {6, 8}; + byte[] expected = { 6, 8 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 8), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 8), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(6, 8); - byte[] expected = {6, 8, 8}; + byte[] expected = { 6, 8, 8 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList((byte) 8), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList((byte) 8), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -139,76 +144,87 @@ void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_ @Test void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() { - byte[] expected = {-6, 10, 8}; + byte[] expected = { -6, 10, 8 }; arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, expected); } @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_is() { assertThatNullPointerException().isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), - actual, - (byte[]) null)) - .withMessage(valuesToLookForIsNull()); + actual, + (byte[]) null)) + .withMessage(valuesToLookForIsNull()); } @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(-8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf(-8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - byte[] expected = {6, -8, 20}; + byte[] expected = { 6, -8, 20 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList((byte) 20), - newArrayList((byte) 10), absValueComparisonStrategy)); + newArrayList((byte) 10), absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - byte[] expected = {6, 8}; + byte[] expected = { 6, 8 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 10), absValueComparisonStrategy)); + verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 10), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(6, 8, 8); - byte[] expected = {6, 8}; + byte[] expected = { 6, 8 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 8), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((byte) 8), + absValueComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(6, 8); - byte[] expected = {6, 8, 8}; + byte[] expected = { 6, 8, 8 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList((byte) 8), emptyList(), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList((byte) 8), emptyList(), + absValueComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_with_Integer_Arguments_Test.java b/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_with_Integer_Arguments_Test.java index 433b176bc13..2ea2fcaad3f 100644 --- a/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_with_Integer_Arguments_Test.java +++ b/src/test/java/org/assertj/core/internal/bytearrays/ByteArrays_assertContainsExactlyInAnyOrder_with_Integer_Arguments_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.bytearrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.ByteArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -56,12 +56,15 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, IntArrays.arrayOf(6, 8))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + IntArrays.arrayOf(6, + 8))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, IntArrays.emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + IntArrays.emptyArray())); } @Test @@ -73,7 +76,8 @@ void should_throw_error_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, IntArrays.arrayOf(8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + IntArrays.arrayOf(8))) .withMessage(actualIsNull()); } @@ -85,7 +89,8 @@ void should_fail_if_actual_does_not_contain_given_values_exactly() { assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8, 20), - newArrayList((byte) 20), newArrayList((byte) 10), StandardComparisonStrategy.instance())); + newArrayList((byte) 20), newArrayList((byte) 10), + StandardComparisonStrategy.instance())); } @Test @@ -96,8 +101,8 @@ void should_fail_if_actual_contains_all_given_values_but_size_differ() { assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 10), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 10), + StandardComparisonStrategy.instance())); } @Test @@ -109,8 +114,8 @@ void should_fail_if_actual_contains_duplicates_and_expected_does_not() { assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 8), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 8), + StandardComparisonStrategy.instance())); } @Test @@ -122,7 +127,8 @@ void should_fail_if_expected_contains_duplicates_and_actual_does_not() { assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8, 8), newArrayList((byte) 8), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8, 8), newArrayList((byte) 8), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -141,43 +147,53 @@ void should_pass_if_actual_contains_given_values_exactly_in_different_order_acco @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, IntArrays.emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + IntArrays.emptyArray())); } @Test void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_is() { assertThatNullPointerException().isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), - actual, - (int[]) null)) - .withMessage(valuesToLookForIsNull()); + actual, + (int[]) null)) + .withMessage(valuesToLookForIsNull()); } @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, IntArrays.arrayOf(-8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + IntArrays.arrayOf(-8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - byte[] expected = {6, -8, 20}; + byte[] expected = { 6, -8, 20 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, IntArrays.arrayOf(6, -8, 20))); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + IntArrays.arrayOf(6, + -8, + 20))); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList((byte) 20), - newArrayList((byte) 10), absValueComparisonStrategy)); + newArrayList((byte) 10), absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, IntArrays.arrayOf(6, 8))); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + IntArrays.arrayOf(6, + 8))); assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 10), absValueComparisonStrategy)); + verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 10), + absValueComparisonStrategy)); } @Test @@ -185,11 +201,14 @@ void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_t AssertionInfo info = someInfo(); actual = arrayOf(6, 8, 8); - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, IntArrays.arrayOf(6, 8))); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + IntArrays.arrayOf(6, + 8))); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 8), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8), emptyList(), newArrayList((byte) 8), + absValueComparisonStrategy)); } @Test @@ -197,11 +216,15 @@ void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_t AssertionInfo info = someInfo(); actual = arrayOf(6, 8); - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, IntArrays.arrayOf(6, 8, 8))); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + IntArrays.arrayOf(6, + 8, + 8))); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8, 8), newArrayList((byte) 8), emptyList(), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, arrayOf(6, 8, 8), newArrayList((byte) 8), emptyList(), + absValueComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/chararrays/CharArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/chararrays/CharArrays_assertContainsExactlyInAnyOrder_Test.java index 073e65b6af4..3856baaddee 100644 --- a/src/test/java/org/assertj/core/internal/chararrays/CharArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/chararrays/CharArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.chararrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.CharArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -55,12 +55,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf('a', 'b'))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf('a', 'b'))); } @Test void should_fail_if_expected_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -71,60 +73,62 @@ void should_throw_error_if_expected_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf('b'))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf('b'))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - char[] expected = {'a', 'b', 'e'}; + char[] expected = { 'a', 'b', 'e' }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList('e'), newArrayList('c'), - StandardComparisonStrategy.instance())); + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - char[] expected = {'a', 'b'}; + char[] expected = { 'a', 'b' }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('c'), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('c'), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf('a', 'b', 'b'); - char[] expected = {'a', 'b'}; + char[] expected = { 'a', 'b' }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('b'), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('b'), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf('a', 'b'); - char[] expected = {'a', 'b', 'b'}; + char[] expected = { 'a', 'b', 'b' }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList('b'), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList('b'), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -138,77 +142,88 @@ void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_ @Test void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() { - char[] expected = {'A', 'c', 'b'}; + char[] expected = { 'A', 'c', 'b' }; arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, expected); } @Test void should_fail_if_expected_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test void should_throw_error_if_expected_null_whatever_custom_comparison_strategy_is() { assertThatNullPointerException().isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), - actual, - null)) - .withMessage(valuesToLookForIsNull()); + actual, + null)) + .withMessage(valuesToLookForIsNull()); } @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf('b'))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf('b'))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - char[] expected = {'a', 'B', 'e'}; + char[] expected = { 'a', 'B', 'e' }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList('e'), newArrayList('c'), - caseInsensitiveComparisonStrategy)); + caseInsensitiveComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - char[] expected = {'a', 'b'}; + char[] expected = { 'a', 'b' }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('c'), caseInsensitiveComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('c'), + caseInsensitiveComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf('a', 'b', 'b'); - char[] expected = {'a', 'b'}; + char[] expected = { 'a', 'b' }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('b'), caseInsensitiveComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList('b'), + caseInsensitiveComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf('a', 'b'); - char[] expected = {'a', 'b', 'b'}; + char[] expected = { 'a', 'b', 'b' }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList('b'), emptyList(), caseInsensitiveComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList('b'), emptyList(), + caseInsensitiveComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/doublearrays/DoubleArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/doublearrays/DoubleArrays_assertContainsExactlyInAnyOrder_Test.java index 54ca713a710..5d5eb47e12e 100644 --- a/src/test/java/org/assertj/core/internal/doublearrays/DoubleArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/doublearrays/DoubleArrays_assertContainsExactlyInAnyOrder_Test.java @@ -13,6 +13,7 @@ package org.assertj.core.internal.doublearrays; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.error.ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder; @@ -21,7 +22,6 @@ import static org.assertj.core.test.DoubleArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import org.assertj.core.api.AssertionInfo; @@ -53,12 +53,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6d, 8d))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(6d, 8d))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -69,7 +71,8 @@ void should_throw_error_if_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8d))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(8d))) .withMessage(actualIsNull()); } @@ -113,9 +116,12 @@ void should_fail_if_actual_contains_duplicates_and_expected_does_not() { @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { actual = arrayOf(1d, 2d); - double[] expected = {1d, 2d, 3d}; - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, expected)) - .withMessage(shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3d), emptyList(), StandardComparisonStrategy.instance()).create()); + double[] expected = { 1d, 2d, 3d }; + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + expected)) + .withMessage(shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3d), + emptyList(), + StandardComparisonStrategy.instance()).create()); } // ------------------------------------------------------------------------------------------------------------------ @@ -135,7 +141,9 @@ void should_pass_if_actual_contains_given_values_exactly_in_different_order_acco @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test @@ -148,7 +156,9 @@ void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_ @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(-8d))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf(-8d))) .withMessage(actualIsNull()); } diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java index 8330bbee76e..3a75470f713 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.files; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.Assertions.catchThrowable; @@ -20,7 +21,6 @@ import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java index 62d41ac90d2..7fe9a9a85b1 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java @@ -13,6 +13,7 @@ package org.assertj.core.internal.files; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.Assertions.catchThrowable; @@ -21,7 +22,6 @@ import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java index 03c5576d5c6..83546d5faa8 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.files; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.Assertions.catchThrowable; @@ -20,7 +21,6 @@ import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java index a40039c8cdc..6c578ebf1a5 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java @@ -13,6 +13,7 @@ package org.assertj.core.internal.files; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -23,7 +24,6 @@ import static org.assertj.core.internal.files.Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.mockPathMatcher; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_Predicate_Test.java index 14268849e3c..350cc53cf79 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_Predicate_Test.java @@ -12,10 +12,10 @@ */ package org.assertj.core.internal.files; +import static java.util.Collections.emptyList; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldContainRecursively.directoryShouldContainRecursively; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.mockito.Mockito.verify; diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java index f9b34c2505a..06126472723 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java @@ -13,10 +13,10 @@ package org.assertj.core.internal.files; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldContainRecursively.directoryShouldContainRecursively; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.Mockito.verify; diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsEmptyDirectory_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsEmptyDirectory_Test.java index 8706e7bf3f4..3ada1928c7f 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsEmptyDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsEmptyDirectory_Test.java @@ -12,13 +12,13 @@ */ package org.assertj.core.internal.files; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldBeEmptyDirectory.shouldBeEmptyDirectory; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -28,14 +28,10 @@ import java.io.FileFilter; import java.util.List; -import org.assertj.core.api.AssertionInfo; -import org.assertj.core.internal.Files; import org.assertj.core.internal.FilesBaseTest; import org.junit.jupiter.api.Test; /** - * Tests for {@link Files#assertIsEmptyDirectory(AssertionInfo, File)} - * * @author Valeriy Vyrva */ class Files_assertIsEmptyDirectory_Test extends FilesBaseTest { diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsNotEmptyDirectory_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsNotEmptyDirectory_Test.java index ab0ff1338af..14c0c1a4a89 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsNotEmptyDirectory_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsNotEmptyDirectory_Test.java @@ -12,13 +12,13 @@ */ package org.assertj.core.internal.files; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; diff --git a/src/test/java/org/assertj/core/internal/floatarrays/FloatArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/floatarrays/FloatArrays_assertContainsExactlyInAnyOrder_Test.java index f495870b0a4..c71dfe51540 100644 --- a/src/test/java/org/assertj/core/internal/floatarrays/FloatArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/floatarrays/FloatArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.floatarrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.FloatArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -55,12 +55,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6f, 8f))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(6f, 8f))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -71,60 +73,62 @@ void should_throw_error_if_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8f))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(8f))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - float[] expected = {6f, 8f, 20f}; + float[] expected = { 6f, 8f, 20f }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20f), newArrayList(10f), - StandardComparisonStrategy.instance())); + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - float[] expected = {6f, 8f}; + float[] expected = { 6f, 8f }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10f), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10f), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1f, 2f, 3f); - float[] expected = {1f, 2f}; + float[] expected = { 1f, 2f }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3f), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3f), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1f, 2f); - float[] expected = {1f, 2f, 3f}; + float[] expected = { 1f, 2f, 3f }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3f), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3f), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -138,13 +142,15 @@ void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_ @Test void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() { - float[] expected = {-6f, 10f, 8f}; + float[] expected = { -6f, 10f, 8f }; arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, expected); } @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test @@ -157,59 +163,67 @@ void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_ @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(-8f))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf(-8f))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - float[] expected = {6f, -8f, 20f}; + float[] expected = { 6f, -8f, 20f }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20f), newArrayList(10f), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20f), newArrayList(10f), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - float[] expected = {6f, -8f}; + float[] expected = { 6f, -8f }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10f), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10f), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1f, 2f, 3f); - float[] expected = {1f, 2f}; + float[] expected = { 1f, 2f }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3f), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3f), + absValueComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1f, 2f); - float[] expected = {1f, 2f, 3f}; + float[] expected = { 1f, 2f, 3f }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3f), emptyList(), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3f), emptyList(), + absValueComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/intarrays/IntArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/intarrays/IntArrays_assertContainsExactlyInAnyOrder_Test.java index 8adaebc0686..9dcb1f55860 100644 --- a/src/test/java/org/assertj/core/internal/intarrays/IntArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/intarrays/IntArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.intarrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.IntArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -45,9 +45,9 @@ void should_pass_if_actual_contains_given_values_exactly_in_any_order() { @Test void should_pass_if_actual_contains_given_values_exactly_in_any_order_with_duplicates() { actual = arrayOf(6, 8, 8, 10); - arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6, 8, 8,10)); + arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6, 8, 8, 10)); } - + @Test void should_pass_if_actual_and_given_values_are_empty() { arrays.assertContainsExactlyInAnyOrder(someInfo(), emptyArray(), emptyArray()); @@ -61,12 +61,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6, 8))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(6, 8))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -77,60 +79,62 @@ void should_throw_error_if_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - int[] expected = {6, 8, 20}; + int[] expected = { 6, 8, 20 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20), newArrayList(10), - StandardComparisonStrategy.instance())); + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - int[] expected = {6, 8}; + int[] expected = { 6, 8 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2, 3); - int[] expected = {1, 2}; + int[] expected = { 1, 2 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2); - int[] expected = {1, 2, 3}; + int[] expected = { 1, 2, 3 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -144,13 +148,15 @@ void should_pass_if_actual_contains_given_values_exactly_according_to_custom_com @Test void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() { - int[] expected = {-6, 10, 8}; + int[] expected = { -6, 10, 8 }; arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, expected); } @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test @@ -163,60 +169,68 @@ void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_ @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(-8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf(-8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - int[] expected = {6, -8, 20}; + int[] expected = { 6, -8, 20 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20), newArrayList(10), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20), newArrayList(10), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - int[] expected = {6, 8}; + int[] expected = { 6, 8 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2, 3); - int[] expected = {1, 2}; + int[] expected = { 1, 2 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3), + absValueComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2); - int[] expected = {1, 2, 3}; + int[] expected = { 1, 2, 3 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3), emptyList(), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3), emptyList(), + absValueComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/iterables/Iterables_assertAnySatisfy_Test.java b/src/test/java/org/assertj/core/internal/iterables/Iterables_assertAnySatisfy_Test.java index f8adb31cfc9..c7eaf5c61d8 100644 --- a/src/test/java/org/assertj/core/internal/iterables/Iterables_assertAnySatisfy_Test.java +++ b/src/test/java/org/assertj/core/internal/iterables/Iterables_assertAnySatisfy_Test.java @@ -13,6 +13,7 @@ package org.assertj.core.internal.iterables; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.Assertions.catchThrowable; @@ -21,7 +22,6 @@ import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.ArgumentMatchers.anyString; @@ -39,7 +39,7 @@ class Iterables_assertAnySatisfy_Test extends IterablesBaseTest { - private List actual = newArrayList("Luke", "Leia", "Yoda", "Obiwan"); + private final List actual = newArrayList("Luke", "Leia", "Yoda", "Obiwan"); @Test void must_not_check_all_elements() { @@ -85,25 +85,25 @@ void should_fail_if_no_elements_satisfy_the_assertions_requirements() { assertThat(error).isInstanceOf(AssertionError.class); List errors = list(unsatisfiedRequirement("Luke", format("%n" + - "Expecting actual:%n" + - " \"Luke\"%n" + - "to contain:%n" + - " \"W\" ")), - unsatisfiedRequirement("Leia", format("%n" + - "Expecting actual:%n" + - " \"Leia\"%n" + - "to contain:%n" + - " \"W\" ")), - unsatisfiedRequirement("Yoda", format("%n" + - "Expecting actual:%n" + - " \"Yoda\"%n" + - "to contain:%n" + - " \"W\" ")), - unsatisfiedRequirement("Obiwan", format("%n" + - "Expected size: 4 but was: 6 in:%n" - + - "\"Obiwan\""))); - verify(failures).failure(info, elementsShouldSatisfyAny(actual, errors, someInfo())); + "Expecting actual:%n" + + " \"Luke\"%n" + + "to contain:%n" + + " \"W\" ")), + unsatisfiedRequirement("Leia", format("%n" + + "Expecting actual:%n" + + " \"Leia\"%n" + + "to contain:%n" + + " \"W\" ")), + unsatisfiedRequirement("Yoda", format("%n" + + "Expecting actual:%n" + + " \"Yoda\"%n" + + "to contain:%n" + + " \"W\" ")), + unsatisfiedRequirement("Obiwan", format("%n" + + "Expected size: 4 but was: 6 in:%n" + + + "\"Obiwan\""))); + verify(failures).failure(info, elementsShouldSatisfyAny(actual, errors, someInfo())); } @Test diff --git a/src/test/java/org/assertj/core/internal/longarrays/LongArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/longarrays/LongArrays_assertContainsExactlyInAnyOrder_Test.java index d79e9a0d6a8..c2fac61a944 100644 --- a/src/test/java/org/assertj/core/internal/longarrays/LongArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/longarrays/LongArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.longarrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.LongArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -55,12 +55,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6L, 8L))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(6L, 8L))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -71,59 +73,62 @@ void should_throw_error_if_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8L))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(8L))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - long[] expected = {6L, 8L, 20L}; + long[] expected = { 6L, 8L, 20L }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20L), newArrayList(10L), - StandardComparisonStrategy.instance())); + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - long[] expected = {6L, 8L}; + long[] expected = { 6L, 8L }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10L), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10L), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1L, 2L, 3L); - long[] expected = {1L, 2L}; + long[] expected = { 1L, 2L }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3L), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3L), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1L, 2L); - long[] expected = {1L, 2L, 3L}; + long[] expected = { 1L, 2L, 3L }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3L), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3L), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -137,13 +142,15 @@ void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_ @Test void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() { - long[] expected = {-6L, 10L, 8L}; + long[] expected = { -6L, 10L, 8L }; arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, expected); } @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test @@ -156,60 +163,68 @@ void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_ @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(-8L))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf(-8L))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - long[] expected = {6L, -8L, 20L}; + long[] expected = { 6L, -8L, 20L }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20L), newArrayList(10L), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(20L), newArrayList(10L), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - long[] expected = {6L, 8L}; + long[] expected = { 6L, 8L }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10L), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(10L), + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1L, 2L, 3L); - long[] expected = {1L, 2L}; + long[] expected = { 1L, 2L }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3L), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList(3L), + absValueComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1L, 2L); - long[] expected = {1L, 2L, 3L}; + long[] expected = { 1L, 2L, 3L }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3L), emptyList(), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList(3L), emptyList(), + absValueComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/maps/Maps_assertAnySatisfyingConsumer_Test.java b/src/test/java/org/assertj/core/internal/maps/Maps_assertAnySatisfyingConsumer_Test.java index e64358780e0..c83fa4208e9 100644 --- a/src/test/java/org/assertj/core/internal/maps/Maps_assertAnySatisfyingConsumer_Test.java +++ b/src/test/java/org/assertj/core/internal/maps/Maps_assertAnySatisfyingConsumer_Test.java @@ -13,6 +13,7 @@ package org.assertj.core.internal.maps; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.data.MapEntry.entry; @@ -22,7 +23,6 @@ import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; diff --git a/src/test/java/org/assertj/core/internal/objectarrays/ObjectArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/objectarrays/ObjectArrays_assertContainsExactlyInAnyOrder_Test.java index f5f45b2e0a1..900d30b1751 100644 --- a/src/test/java/org/assertj/core/internal/objectarrays/ObjectArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/objectarrays/ObjectArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.objectarrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -21,7 +22,6 @@ import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.Arrays.array; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -56,12 +56,15 @@ void should_pass_if_actual_and_given_values_are_empty() { @Test void should_fail_if_array_of_values_to_look_for_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, array())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + array())); } @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, array("Luke", "Yoda"))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + array("Luke", + "Yoda"))); } @Test @@ -72,45 +75,49 @@ void should_throw_error_if_array_of_values_to_look_for_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, array("Yoda"))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + array("Yoda"))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order() { AssertionInfo info = someInfo(); - Object[] expected = {"Luke", "Yoda", "Han"}; + Object[] expected = { "Luke", "Yoda", "Han" }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Han"), newArrayList("Leia"), StandardComparisonStrategy.instance())); + verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Han"), newArrayList("Leia"), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = array("Luke", "Leia", "Luke"); - Object[] expected = {"Luke", "Leia"}; + Object[] expected = { "Luke", "Leia" }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList("Luke"), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList("Luke"), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = array("Luke", "Leia"); - Object[] expected = {"Luke", "Leia", "Luke"}; + Object[] expected = { "Luke", "Leia", "Luke" }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Luke"), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Luke"), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -120,45 +127,50 @@ void should_fail_if_expected_contains_duplicates_and_actual_does_not() { @Test void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() { arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, - array("LUKE", "YODA", "Leia")); + array("LUKE", "YODA", "Leia")); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - Object[] expected = {"Luke", "Yoda", "Han"}; + Object[] expected = { "Luke", "Yoda", "Han" }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Han"), newArrayList("Leia"), - caseInsensitiveStringComparisonStrategy)); + caseInsensitiveStringComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = array("Luke", "Leia", "Luke"); - Object[] expected = {"Luke", "Leia"}; + Object[] expected = { "Luke", "Leia" }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList("Luke"), caseInsensitiveStringComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList("Luke"), + caseInsensitiveStringComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = array("Luke", "Leia"); - Object[] expected = {"Luke", "Leia", "Luke"}; + Object[] expected = { "Luke", "Leia", "Luke" }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Luke"), emptyList(), caseInsensitiveStringComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList("Luke"), emptyList(), + caseInsensitiveStringComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/internal/objects/Objects_assertHasAllNullFieldsOrPropertiesExcept_Test.java b/src/test/java/org/assertj/core/internal/objects/Objects_assertHasAllNullFieldsOrPropertiesExcept_Test.java index 00e12320ffa..cdb14f87aae 100644 --- a/src/test/java/org/assertj/core/internal/objects/Objects_assertHasAllNullFieldsOrPropertiesExcept_Test.java +++ b/src/test/java/org/assertj/core/internal/objects/Objects_assertHasAllNullFieldsOrPropertiesExcept_Test.java @@ -12,12 +12,12 @@ */ package org.assertj.core.internal.objects; +import static java.util.Collections.emptyList; import static org.assertj.core.error.ShouldHaveAllNullFields.shouldHaveAllNullFields; import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.Mockito.verify; diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java index 603a3366019..b62c70c7cc6 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java @@ -14,6 +14,7 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; @@ -22,7 +23,6 @@ import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willThrow; diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java index 8ec4f544a69..a92e9006939 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java @@ -14,6 +14,7 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; @@ -22,7 +23,6 @@ import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willThrow; diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_Predicate_Test.java index c7408fbfdea..943b01f4fa1 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_Predicate_Test.java @@ -12,11 +12,11 @@ */ package org.assertj.core.internal.paths; +import static java.util.Collections.emptyList; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldContainRecursively.directoryShouldContainRecursively; import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.mockito.Mockito.verify; diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java index 2e2eec1cee3..5a64dad6a96 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryRecursivelyContaining_SyntaxAndPattern_Test.java @@ -13,11 +13,11 @@ package org.assertj.core.internal.paths; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldContainRecursively.directoryShouldContainRecursively; import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.list; import static org.mockito.Mockito.verify; diff --git a/src/test/java/org/assertj/core/internal/shortarrays/ShortArrays_assertContainsExactlyInAnyOrder_Test.java b/src/test/java/org/assertj/core/internal/shortarrays/ShortArrays_assertContainsExactlyInAnyOrder_Test.java index 4714d1155b1..5a29542ce7a 100644 --- a/src/test/java/org/assertj/core/internal/shortarrays/ShortArrays_assertContainsExactlyInAnyOrder_Test.java +++ b/src/test/java/org/assertj/core/internal/shortarrays/ShortArrays_assertContainsExactlyInAnyOrder_Test.java @@ -12,6 +12,7 @@ */ package org.assertj.core.internal.shortarrays; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -22,7 +23,6 @@ import static org.assertj.core.test.ShortArrays.emptyArray; import static org.assertj.core.test.TestData.someInfo; import static org.assertj.core.util.FailureMessages.actualIsNull; -import static org.assertj.core.util.Lists.emptyList; import static org.assertj.core.util.Lists.newArrayList; import static org.mockito.Mockito.verify; @@ -55,12 +55,14 @@ void should_pass_if_actual_contains_given_values_exactly_but_in_different_order( @Test void should_fail_if_arrays_have_different_sizes() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6, 8))); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + arrayOf(6, 8))); } @Test void should_fail_if_expected_is_empty_and_actual_is_not() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, + emptyArray())); } @Test @@ -71,60 +73,63 @@ void should_throw_error_if_expected_is_null() { @Test void should_fail_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, + arrayOf(8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly() { AssertionInfo info = someInfo(); - short[] expected = {6, 8, 20}; + short[] expected = { 6, 8, 20 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 20), newArrayList((short) 10), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 20), newArrayList((short) 10), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ() { AssertionInfo info = someInfo(); - short[] expected = {6, 8}; + short[] expected = { 6, 8 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 10), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 10), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2, 3); - short[] expected = {1, 2}; + short[] expected = { 1, 2 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 3), - StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 3), + StandardComparisonStrategy.instance())); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_not() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2); - short[] expected = {1, 2, 3}; + short[] expected = { 1, 2, 3 }; Throwable error = catchThrowable(() -> arrays.assertContainsExactlyInAnyOrder(info, actual, expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 3), emptyList(), StandardComparisonStrategy.instance())); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 3), emptyList(), + StandardComparisonStrategy.instance())); } // ------------------------------------------------------------------------------------------------------------------ @@ -138,13 +143,15 @@ void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_ @Test void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() { - short[] expected = {-6, 10, 8}; + short[] expected = { -6, 10, 8 }; arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, expected); } @Test void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray())); + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + actual, + emptyArray())); } @Test @@ -157,59 +164,66 @@ void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_ @Test void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(-8))) + assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), + null, + arrayOf(-8))) .withMessage(actualIsNull()); } @Test void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - short[] expected = {6, -8, 20}; + short[] expected = { 6, -8, 20 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 20), - newArrayList((short) 10), absValueComparisonStrategy)); + newArrayList((short) 10), absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); - short[] expected = {6, 8}; + short[] expected = { 6, 8 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 10), - absValueComparisonStrategy)); + absValueComparisonStrategy)); } @Test void should_fail_if_actual_contains_duplicates_and_expected_does_notaccording_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2, 3); - short[] expected = {1, 2}; + short[] expected = { 1, 2 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 3), - absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, emptyList(), newArrayList((short) 3), + absValueComparisonStrategy)); } @Test void should_fail_if_expected_contains_duplicates_and_actual_does_notaccording_to_custom_comparison_strategy() { AssertionInfo info = someInfo(); actual = arrayOf(1, 2); - short[] expected = {1, 2, 3}; + short[] expected = { 1, 2, 3 }; - Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected)); + Throwable error = catchThrowable(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, + expected)); assertThat(error).isInstanceOf(AssertionError.class); verify(failures).failure(info, - shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 3), emptyList(), absValueComparisonStrategy)); + shouldContainExactlyInAnyOrder(actual, expected, newArrayList((short) 3), emptyList(), + absValueComparisonStrategy)); } } diff --git a/src/test/java/org/assertj/core/util/Lists_emptyList_Test.java b/src/test/java/org/assertj/core/util/Lists_emptyList_Test.java index 0e3c0124ac8..e75383e10ca 100644 --- a/src/test/java/org/assertj/core/util/Lists_emptyList_Test.java +++ b/src/test/java/org/assertj/core/util/Lists_emptyList_Test.java @@ -19,14 +19,15 @@ import org.junit.jupiter.api.Test; /** - * Tests for {@link Lists#newArrayList()}. - * * @author Christian Rösch */ +@SuppressWarnings("deprecation") class Lists_emptyList_Test { + @Test void should_return_empty_List() { List list = Lists.emptyList(); assertThat(list).isEmpty(); } + } From 6cab52be094ece12818cc41f82028ccf833af201 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 7 Sep 2021 21:31:19 +0200 Subject: [PATCH 107/123] Apply workaround to use an object array argument See junit-team/junit5#2708. --- .../StandardComparisonStrategy_areEqual_Test.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java b/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java index acbac9a2078..66d60de477f 100644 --- a/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java +++ b/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java @@ -256,8 +256,7 @@ void should_return_false_if_array_is_non_null_and_other_is_null(Object actual) { } private static Stream arrays() { - return Stream.of( -// new Object[] { "Luke", "Yoda", "Leia" }, // FIXME junit-team/junit5#2708 + return Stream.of(argument(new Object[] { "Luke", "Yoda", "Leia" }), new byte[] { 1, 2, 3 }, new short[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, @@ -268,6 +267,11 @@ private static Stream arrays() { new boolean[] { true, false }); } + // https://github.com/junit-team/junit5/issues/2708 + private static Arguments argument(Object[] array) { + return () -> new Object[] { array }; + } + @Test void should_fail_if_equals_implementation_fails() { // GIVEN From 387519cb25a702a2235f816ec893f739776e4381 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 7 Sep 2021 23:45:27 +0200 Subject: [PATCH 108/123] Improve workaround description and references --- .../internal/StandardComparisonStrategy_areEqual_Test.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java b/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java index 66d60de477f..b3ca86037b4 100644 --- a/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java +++ b/src/test/java/org/assertj/core/internal/StandardComparisonStrategy_areEqual_Test.java @@ -267,7 +267,8 @@ private static Stream arrays() { new boolean[] { true, false }); } - // https://github.com/junit-team/junit5/issues/2708 + // Arrays of objects require additional wrapping to avoid expanding into individual elements. + // See https://github.com/junit-team/junit5/issues/1665 and https://github.com/junit-team/junit5/issues/2708 private static Arguments argument(Object[] array) { return () -> new Object[] { array }; } From 33778bbe908f82c98f386efdf71ce96fce5c8757 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Wed, 8 Sep 2021 22:28:49 +1200 Subject: [PATCH 109/123] [Breaking change] custom comparison takes precedence over reference comparison in recursive comparison. Fixes #2335 --- ...cursiveComparisonDifferenceCalculator.java | 6 +-- ...t_isEqualTo_withFieldComparators_Test.java | 54 +++++++++++++------ ...rt_isEqualTo_withTypeComparators_Test.java | 31 ++++++++--- 3 files changed, 65 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java b/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java index e8bc8d1a1a4..371dcd7b415 100644 --- a/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java +++ b/src/main/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonDifferenceCalculator.java @@ -203,8 +203,6 @@ private static List determineDifferences(Object actual, Ob final Object actualFieldValue = dualValue.actual; final Object expectedFieldValue = dualValue.expected; - if (actualFieldValue == expectedFieldValue) continue; - // Custom comparators take precedence over all other types of comparison if (recursiveComparisonConfiguration.hasCustomComparator(dualValue)) { if (!propertyOrFieldValuesAreEqual(dualValue, recursiveComparisonConfiguration)) comparisonState.addDifference(dualValue); @@ -212,6 +210,8 @@ private static List determineDifferences(Object actual, Ob continue; } + if (actualFieldValue == expectedFieldValue) continue; + if (actualFieldValue == null || expectedFieldValue == null) { // one of the value is null while the other is not as we already know that actualFieldValue != expectedFieldValue comparisonState.addDifference(dualValue); @@ -679,8 +679,6 @@ private static boolean propertyOrFieldValuesAreEqual(DualValue dualValue, final String fieldName = dualValue.getConcatenatedPath(); final Object actualFieldValue = dualValue.actual; final Object expectedFieldValue = dualValue.expected; - // no need to look into comparators if objects are the same - if (actualFieldValue == expectedFieldValue) return true; // check field comparators as they take precedence over type comparators Comparator fieldComparator = recursiveComparisonConfiguration.getComparatorForField(fieldName); if (fieldComparator != null) return fieldComparator.compare(actualFieldValue, expectedFieldValue) == 0; diff --git a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test.java b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test.java index aed3e2d86d2..eec19f646a8 100644 --- a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test.java +++ b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test.java @@ -13,6 +13,7 @@ package org.assertj.core.api.recursive.comparison; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.internal.objects.SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR; import static org.assertj.core.test.AlwaysDifferentComparator.alwaysDifferent; import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS; @@ -20,11 +21,13 @@ import static org.assertj.core.test.AlwaysEqualComparator.alwaysEqual; import static org.assertj.core.test.NeverEqualComparator.NEVER_EQUALS; import static org.assertj.core.util.Arrays.array; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.junit.jupiter.params.provider.Arguments.arguments; import java.sql.Timestamp; import java.util.Comparator; import java.util.Date; +import java.util.Objects; import java.util.function.BiPredicate; import java.util.stream.Stream; @@ -238,21 +241,6 @@ void should_handle_null_field_with_field_comparator() { .isEqualTo(expected); } - @Test - void should_ignore_comparators_when_fields_are_the_same() { - // GIVEN - Timestamp dateOfBirth = new Timestamp(3L); - Patient actual = new Patient(dateOfBirth); - Patient expected = new Patient(dateOfBirth); - // WHEN - assertThat(actual).usingRecursiveComparison() - .withComparatorForFields(NEVER_EQUALS, "dateOfBirth") - .isEqualTo(expected); - assertThat(actual).usingRecursiveComparison() - .withEqualsForFields((o1, o2) -> false, "dateOfBirth") - .isEqualTo(expected); - } - @Test void should_treat_timestamp_as_equal_to_date_when_registering_a_date_symmetric_comparator() { // GIVEN @@ -313,4 +301,40 @@ void ignoringOverriddenEquals_should_not_interfere_with_field_comparators() { .isEqualTo(expected); } + @Test + void should_use_custom_equal_over_reference_comparison() { + // GIVEN + Foo actual = new Foo(1); + Foo expected = new Foo(1); + BiPredicate greaterThan = (i1, i2) -> Objects.equals(i1, i2 + 1); + // WHEN + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison() + .withEqualsForFields(greaterThan, "bar") + .isEqualTo(expected)); + // THEN + then(assertionError).hasMessageContainingAll("- these fields were compared with the following comparators:", " - bar -> "); + } + + @Test + void should_use_custom_comparator_over_reference_comparison() { + // GIVEN + Foo actual = new Foo(1); + Foo expected = new Foo(1); + BiPredicate greaterThan = (i1, i2) -> Objects.equals(i1, i2 + 1); + // WHEN + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison() + .withComparatorForFields(NEVER_EQUALS, "bar") + .isEqualTo(expected)); + // THEN + then(assertionError).hasMessageContainingAll("- these fields were compared with the following comparators:", " - bar -> "); + } + + private static class Foo { + + private final Integer bar; + + private Foo(Integer bar) { + this.bar = bar; + } + } } diff --git a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test.java b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test.java index c1b8171d28a..fa29589ba22 100644 --- a/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test.java +++ b/src/test/java/org/assertj/core/api/recursive/comparison/RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test.java @@ -14,11 +14,13 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.internal.objects.SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR; import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS; import static org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_TIMESTAMP; import static org.assertj.core.test.Maps.mapOf; import static org.assertj.core.test.NeverEqualComparator.NEVER_EQUALS; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.junit.jupiter.params.provider.Arguments.arguments; import java.sql.Timestamp; @@ -181,18 +183,33 @@ void should_handle_null_field_with_type_comparator() { } @Test - void should_ignore_comparators_when_fields_are_the_same() { + void should_use_custom_comparator_over_reference_comparison() { // GIVEN Timestamp dateOfBirth = new Timestamp(3L); Patient actual = new Patient(dateOfBirth); Patient expected = new Patient(dateOfBirth); // THEN - assertThat(actual).usingRecursiveComparison() - .withComparatorForType(NEVER_EQUALS, Timestamp.class) - .isEqualTo(expected); - assertThat(actual).usingRecursiveComparison() - .withEqualsForType((o1, o2) -> false, Timestamp.class) - .isEqualTo(expected); + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison() + .withComparatorForType(NEVER_EQUALS, + Timestamp.class) + .isEqualTo(expected)); + // THEN + then(assertionError).hasMessageContaining("- java.sql.Timestamp -> org.assertj.core.test.NeverEqualComparator"); + } + + @Test + void should_use_custom_equal_over_reference_comparison() { + // GIVEN + Timestamp dateOfBirth = new Timestamp(3L); + Patient actual = new Patient(dateOfBirth); + Patient expected = new Patient(dateOfBirth); + // THEN + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison() + .withEqualsForType((o1, o2) -> false, + Timestamp.class) + .isEqualTo(expected)); + then(assertionError).hasMessageContaining("- java.sql.Timestamp -> "); + // THEN } @Test From bce11d7960ea32d0ec96b8558f82af323c23b38b Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Thu, 9 Sep 2021 21:04:22 +0200 Subject: [PATCH 110/123] Add `isUnmodifiable` to `Collection` assertions (#2328) --- .../core/api/AbstractCollectionAssert.java | 83 ++++++++++++++ .../core/error/ShouldBeUnmodifiable.java | 45 ++++++++ .../CollectionAssert_isUnmodifiable_Test.java | 107 ++++++++++++++++++ .../core/error/ShouldBeUnmodifiableTest.java | 56 +++++++++ 4 files changed, 291 insertions(+) create mode 100644 src/main/java/org/assertj/core/error/ShouldBeUnmodifiable.java create mode 100644 src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java create mode 100644 src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java diff --git a/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java b/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java index e96bdbb679f..ee70fb443fe 100644 --- a/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractCollectionAssert.java @@ -12,7 +12,16 @@ */ package org.assertj.core.api; +import static java.util.function.UnaryOperator.identity; +import static org.assertj.core.error.ShouldBeUnmodifiable.shouldBeUnmodifiable; + import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.NavigableSet; +import java.util.Set; + +import org.assertj.core.annotations.Beta; /** * Base class for all implementations of assertions for {@link Collection}s. @@ -37,4 +46,78 @@ protected AbstractCollectionAssert(ACTUAL actual, Class selfType) { super(actual, selfType); } + /** + * Verifies that the actual collection is unmodifiable, i.e., throws an {@link UnsupportedOperationException} with + * any attempt to modify the collection. + *

    + * Example: + *

     // assertions will pass
    +   * assertThat(Collections.unmodifiableCollection(new ArrayList<>())).isUnmodifiable();
    +   * assertThat(Collections.unmodifiableList(new ArrayList<>())).isUnmodifiable();
    +   * assertThat(Collections.unmodifiableSet(new HashSet<>())).isUnmodifiable();
    +   *
    +   * // assertions will fail
    +   * assertThat(new ArrayList<>()).isUnmodifiable();
    +   * assertThat(new HashSet<>()).isUnmodifiable();
    + * + * @return {@code this} assertion object. + * @throws AssertionError if the actual collection is modifiable. + * @see Collections#unmodifiableCollection(Collection) + * @see Collections#unmodifiableList(List) + * @see Collections#unmodifiableSet(Set) + */ + @Beta + public SELF isUnmodifiable() { + isNotNull(); + assertIsUnmodifiable(); + return myself; + } + + @SuppressWarnings("unchecked") + private void assertIsUnmodifiable() { + expectUnsupportedOperationException(() -> actual.add(null), "Collection.add(null)"); + expectUnsupportedOperationException(() -> actual.addAll(emptyCollection()), "Collection.addAll(emptyCollection())"); + expectUnsupportedOperationException(() -> actual.clear(), "Collection.clear()"); + expectUnsupportedOperationException(() -> actual.iterator().remove(), "Collection.iterator().remove()"); + expectUnsupportedOperationException(() -> actual.remove(null), "Collection.remove(null)"); + expectUnsupportedOperationException(() -> actual.removeAll(emptyCollection()), "Collection.removeAll(emptyCollection())"); + expectUnsupportedOperationException(() -> actual.removeIf(element -> true), "Collection.removeIf(element -> true)"); + expectUnsupportedOperationException(() -> actual.retainAll(emptyCollection()), "Collection.retainAll(emptyCollection())"); + + if (actual instanceof List) { + List list = (List) actual; + expectUnsupportedOperationException(() -> list.add(0, null), "List.add(0, null)"); + expectUnsupportedOperationException(() -> list.addAll(0, emptyCollection()), "List.addAll(0, emptyCollection())"); + expectUnsupportedOperationException(() -> list.listIterator().add(null), "List.listIterator().add(null)"); + expectUnsupportedOperationException(() -> list.listIterator().remove(), "List.listIterator().remove()"); + expectUnsupportedOperationException(() -> list.listIterator().set(null), "List.listIterator().set(null)"); + expectUnsupportedOperationException(() -> list.remove(0), "List.remove(0)"); + expectUnsupportedOperationException(() -> list.replaceAll(identity()), "List.replaceAll(identity())"); + expectUnsupportedOperationException(() -> list.set(0, null), "List.set(0, null)"); + expectUnsupportedOperationException(() -> list.sort((o1, o2) -> 0), "List.sort((o1, o2) -> 0)"); + } + + if (actual instanceof NavigableSet) { + NavigableSet set = (NavigableSet) actual; + expectUnsupportedOperationException(() -> set.descendingIterator().remove(), "NavigableSet.descendingIterator().remove()"); + expectUnsupportedOperationException(() -> set.pollFirst(), "NavigableSet.pollFirst()"); + expectUnsupportedOperationException(() -> set.pollLast(), "NavigableSet.pollLast()"); + } + } + + private void expectUnsupportedOperationException(Runnable runnable, String method) { + try { + runnable.run(); + throwAssertionError(shouldBeUnmodifiable(method)); + } catch (UnsupportedOperationException e) { + // happy path + } catch (RuntimeException e) { + throwAssertionError(shouldBeUnmodifiable(method, e)); + } + } + + private Collection emptyCollection() { + return Collections.emptyList(); + } + } diff --git a/src/main/java/org/assertj/core/error/ShouldBeUnmodifiable.java b/src/main/java/org/assertj/core/error/ShouldBeUnmodifiable.java new file mode 100644 index 00000000000..73c1556afa3 --- /dev/null +++ b/src/main/java/org/assertj/core/error/ShouldBeUnmodifiable.java @@ -0,0 +1,45 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +public class ShouldBeUnmodifiable extends BasicErrorMessageFactory { + + private static final String UNEXPECTED_SUCCESS_PATTERN = "%n" + + "Expecting actual to be unmodifiable, but invoking%n" + + " %s%n" + + "succeeded instead of throwing java.lang.UnsupportedOperationException"; + + private static final String UNEXPECTED_FAILURE_PATTERN = "%n" + + "Expecting actual to be unmodifiable, but invoking%n" + + " %s%n" + + "thrown%n" + + " %s%n" + + "instead of java.lang.UnsupportedOperationException"; + + public static ErrorMessageFactory shouldBeUnmodifiable(String method) { + return new ShouldBeUnmodifiable(method); + } + + private ShouldBeUnmodifiable(String method) { + super(UNEXPECTED_SUCCESS_PATTERN, method); + } + + public static ErrorMessageFactory shouldBeUnmodifiable(String method, RuntimeException cause) { + return new ShouldBeUnmodifiable(method, cause); + } + + private ShouldBeUnmodifiable(String method, RuntimeException cause) { + super(UNEXPECTED_FAILURE_PATTERN, method, cause.toString()); + } + +} diff --git a/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java b/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java new file mode 100644 index 00000000000..9a12d232865 --- /dev/null +++ b/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java @@ -0,0 +1,107 @@ +package org.assertj.core.api.collection; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeUnmodifiable.shouldBeUnmodifiable; +import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.Lists.list; +import static org.assertj.core.util.Lists.newArrayList; +import static org.assertj.core.util.Sets.newLinkedHashSet; +import static org.assertj.core.util.Sets.newTreeSet; +import static org.assertj.core.util.Sets.set; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.stream.Stream; + +import org.apache.commons.collections4.collection.UnmodifiableCollection; +import org.apache.commons.collections4.list.UnmodifiableList; +import org.apache.commons.collections4.set.UnmodifiableNavigableSet; +import org.apache.commons.collections4.set.UnmodifiableSet; +import org.apache.commons.collections4.set.UnmodifiableSortedSet; +import org.assertj.core.error.ErrorMessageFactory; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Sets; + +class CollectionAssert_isUnmodifiable_Test { + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Collection actual = null; + // WHEN + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isUnmodifiable()); + // THEN + then(assertionError).hasMessage(shouldNotBeNull().create()); + } + + @ParameterizedTest + @MethodSource("modifiableCollections") + void should_fail_if_actual_can_be_modified(Collection actual, ErrorMessageFactory errorMessageFactory) { + // WHEN + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isUnmodifiable()); + // THEN + then(assertionError).as(actual.getClass().getName()) + .hasMessage(errorMessageFactory.create()); + } + + private static Stream modifiableCollections() { + return Stream.of(arguments(new ArrayList<>(), shouldBeUnmodifiable("Collection.add(null)")), + arguments(new LinkedHashSet<>(), shouldBeUnmodifiable("Collection.add(null)")), + arguments(new LinkedList<>(), shouldBeUnmodifiable("Collection.add(null)")), + arguments(new HashSet<>(), shouldBeUnmodifiable("Collection.add(null)")), + arguments(newArrayList(new Object()), shouldBeUnmodifiable("Collection.add(null)")), + arguments(newLinkedHashSet(new Object()), shouldBeUnmodifiable("Collection.add(null)")), + arguments(newTreeSet("element"), shouldBeUnmodifiable("Collection.add(null)", new NullPointerException()))); + } + + // See https://issues.apache.org/jira/browse/COLLECTIONS-799 + @Test + void should_fail_with_commons_collections_UnmodifiableNavigableSet() { + // GIVEN + Collection actual = UnmodifiableNavigableSet.unmodifiableNavigableSet(newTreeSet("element")); + // WHEN + AssertionError assertionError = expectAssertionError(() -> assertThat(actual).isUnmodifiable()); + // THEN + then(assertionError).hasMessage(shouldBeUnmodifiable("NavigableSet.pollFirst()").create()); + } + + @ParameterizedTest + @MethodSource("unmodifiableCollections") + void should_pass(Collection actual) { + // WHEN/THEN + assertThatNoException().as(actual.getClass().getName()) + .isThrownBy(() -> assertThat(actual).isUnmodifiable()); + } + + private static Stream> unmodifiableCollections() { + return Stream.of(Collections.unmodifiableCollection(list(new Object())), + Collections.unmodifiableList(list(new Object())), + Collections.unmodifiableNavigableSet(newTreeSet("element")), + Collections.unmodifiableSet(set(new Object())), + Collections.unmodifiableSortedSet(newTreeSet("element")), + ImmutableList.of(new Object()), + ImmutableSet.of(new Object()), + ImmutableSortedSet.of("element"), + Sets.unmodifiableNavigableSet(newTreeSet("element")), + UnmodifiableCollection.unmodifiableCollection(list(new Object())), + UnmodifiableList.unmodifiableList(list(new Object())), + UnmodifiableSortedSet.unmodifiableSortedSet(newTreeSet("element")), + UnmodifiableSet.unmodifiableSet(set(new Object()))); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java b/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java new file mode 100644 index 00000000000..8ad10aedb05 --- /dev/null +++ b/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java @@ -0,0 +1,56 @@ +package org.assertj.core.error; + +import static java.lang.String.format; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeUnmodifiable.shouldBeUnmodifiable; +import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; + +import org.assertj.core.internal.TestDescription; +import org.junit.jupiter.api.Test; + +class ShouldBeUnmodifiableTest { + + @Test + void should_create_error_message_with_String() { + // GIVEN + ErrorMessageFactory underTest = shouldBeUnmodifiable("method()"); + // WHEN + String message = underTest.create(new TestDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting actual to be unmodifiable, but invoking%n" + + " \"method()\"%n" + + "succeeded instead of throwing java.lang.UnsupportedOperationException")); + } + + @Test + void should_create_error_message_with_String_and_RuntimeException_without_message() { + // GIVEN + ErrorMessageFactory underTest = shouldBeUnmodifiable("method()", new RuntimeException()); + // WHEN + String message = underTest.create(new TestDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting actual to be unmodifiable, but invoking%n" + + " \"method()\"%n" + + "thrown%n" + + " \"java.lang.RuntimeException\"%n" + + "instead of java.lang.UnsupportedOperationException")); + } + + @Test + void should_create_error_message_with_String_and_RuntimeException_with_message() { + // GIVEN + ErrorMessageFactory underTest = shouldBeUnmodifiable("method()", new RuntimeException("message")); + // WHEN + String message = underTest.create(new TestDescription("Test"), STANDARD_REPRESENTATION); + // THEN + then(message).isEqualTo(format("[Test] %n" + + "Expecting actual to be unmodifiable, but invoking%n" + + " \"method()\"%n" + + "thrown%n" + + " \"java.lang.RuntimeException: message\"%n" + + "instead of java.lang.UnsupportedOperationException")); + } + +} From 988f530aaf5fbd78644a3ce1e1aba72d325c1db7 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Mon, 13 Sep 2021 10:11:14 +0200 Subject: [PATCH 111/123] Bump junit-jupiter.version from 5.7.2 to 5.8.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c2fe4a28a3c..5d9884940f7 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 0.1.0 4.13.2 - 5.7.2 + 5.8.0 3.12.4 0.8.7 From 1e8cb972d966e4c06a17c2e84abc2af689a60d07 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 14 Sep 2021 15:24:25 +0200 Subject: [PATCH 112/123] Add missing copyright, bump JUnit versions --- .../CollectionAssert_isUnmodifiable_Test.java | 12 ++++++++++++ .../assertj/core/error/ShouldBeUnmodifiableTest.java | 12 ++++++++++++ verify.bndrun | 10 +++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java b/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java index 9a12d232865..75707c58b9a 100644 --- a/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java +++ b/src/test/java/org/assertj/core/api/collection/CollectionAssert_isUnmodifiable_Test.java @@ -1,3 +1,15 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ package org.assertj.core.api.collection; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java b/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java index 8ad10aedb05..34f67d84515 100644 --- a/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java +++ b/src/test/java/org/assertj/core/error/ShouldBeUnmodifiableTest.java @@ -1,3 +1,15 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ package org.assertj.core.error; import static java.lang.String.format; diff --git a/verify.bndrun b/verify.bndrun index d3d09c918fb..0925fe18a3f 100644 --- a/verify.bndrun +++ b/verify.bndrun @@ -32,9 +32,9 @@ -runbundles: \ assertj-core;version='[3.21.0,3.21.1)',\ assertj-core-tests;version='[3.21.0,3.21.1)',\ - junit-jupiter-api;version='[5.7.2,5.7.3)',\ - junit-jupiter-engine;version='[5.7.2,5.7.3)',\ - junit-platform-commons;version='[1.7.2,1.7.3)',\ - junit-platform-engine;version='[1.7.2,1.7.3)',\ - junit-platform-launcher;version='[1.7.2,1.7.3)',\ + junit-jupiter-api;version='[5.8.0,5.8.1)',\ + junit-jupiter-engine;version='[5.8.0,5.8.1)',\ + junit-platform-commons;version='[1.8.0,1.8.1)',\ + junit-platform-engine;version='[1.8.0,1.8.1)',\ + junit-platform-launcher;version='[1.8.0,1.8.1)',\ org.opentest4j;version='[1.2.0,1.2.1)' From 87eeceaf4c7ce8b3a441e47e7a737f18719c3e84 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Sep 2021 22:16:43 +0200 Subject: [PATCH 113/123] Bump pitest-junit5-plugin from 0.14 to 0.15 (#2342) Bumps [pitest-junit5-plugin](https://github.com/pitest/pitest-junit5-plugin) from 0.14 to 0.15. - [Release notes](https://github.com/pitest/pitest-junit5-plugin/releases) - [Commits](https://github.com/pitest/pitest-junit5-plugin/compare/0.14...0.15) --- updated-dependencies: - dependency-name: org.pitest:pitest-junit5-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5d9884940f7..0acfa002ab9 100644 --- a/pom.xml +++ b/pom.xml @@ -658,7 +658,7 @@ org.pitest pitest-junit5-plugin - 0.14 + 0.15 com.groupcdg From 48ed152ca335612fffb7182646cbe2c13a026806 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Tue, 14 Sep 2021 22:31:21 +0200 Subject: [PATCH 114/123] `Path` and `File` assertions refactoring * Pull up `DirectoryStream.Filter` parameter * Pull up `FileFilter` parameter * Move file name string conversion to `File` error messages * Move path string conversion to `Path` error messages --- .../org/assertj/core/error/ShouldContain.java | 28 +++++++--- .../assertj/core/error/ShouldNotContain.java | 24 ++++++--- .../java/org/assertj/core/internal/Files.java | 54 ++++++++----------- .../core/internal/NioFilesWrapper.java | 7 ++- .../java/org/assertj/core/internal/Paths.java | 30 ++++------- .../core/error/ShouldContain_create_Test.java | 21 ++++---- .../error/ShouldNotContain_create_Test.java | 14 +++-- ...tIsDirectoryContaining_Predicate_Test.java | 3 +- ...ctoryContaining_SyntaxAndPattern_Test.java | 3 +- ...DirectoryNotContaining_Predicate_Test.java | 7 ++- ...ryNotContaining_SyntaxAndPattern_Test.java | 7 ++- ...rectoryContaining_with_Predicate_Test.java | 4 +- ...sDirectoryContaining_with_String_Test.java | 5 +- ...toryNotContaining_with_Predicate_Test.java | 4 +- ...rectoryNotContaining_with_String_Test.java | 5 +- 15 files changed, 109 insertions(+), 107 deletions(-) diff --git a/src/main/java/org/assertj/core/error/ShouldContain.java b/src/main/java/org/assertj/core/error/ShouldContain.java index 1335a660302..3cb5ad0db07 100644 --- a/src/main/java/org/assertj/core/error/ShouldContain.java +++ b/src/main/java/org/assertj/core/error/ShouldContain.java @@ -12,19 +12,21 @@ */ package org.assertj.core.error; +import static java.util.stream.Collectors.toList; +import static org.assertj.core.error.GroupTypeDescription.getGroupTypeDescription; +import static org.assertj.core.util.Strings.escapePercent; + import java.io.File; import java.nio.file.Path; import java.util.List; import org.assertj.core.internal.ComparisonStrategy; import org.assertj.core.internal.StandardComparisonStrategy; -import static org.assertj.core.error.GroupTypeDescription.getGroupTypeDescription; -import static org.assertj.core.util.Strings.escapePercent; /** * Creates an error message indicating that an assertion that verifies a group of elements contains a given set of values failed. * A group of elements can be a collection, an array or a {@code String}.
    - * It also mention the {@link ComparisonStrategy} used. + * It also mentions the {@link ComparisonStrategy} used. * * @author Alex Ruiz * @author Joel Costigliola @@ -70,12 +72,24 @@ public static ErrorMessageFactory shouldContain(Object actual, Object expected, return shouldContain(actual, expected, notFound, StandardComparisonStrategy.instance()); } - public static ErrorMessageFactory directoryShouldContain(File actual, List directoryContent, String filterDescription) { - return new ShouldContain(actual, directoryContent, filterDescription); + public static ErrorMessageFactory directoryShouldContain(File actual, List directoryContent, String filterDescription) { + return new ShouldContain(actual, toFileNames(directoryContent), filterDescription); + } + + private static List toFileNames(List files) { + return files.stream() + .map(File::getName) + .collect(toList()); + } + + public static ErrorMessageFactory directoryShouldContain(Path actual, List directoryContent, String filterDescription) { + return new ShouldContain(actual, toPathNames(directoryContent), filterDescription); } - public static ErrorMessageFactory directoryShouldContain(Path actual, List directoryContent, String filterDescription) { - return new ShouldContain(actual, directoryContent, filterDescription); + private static List toPathNames(List files) { + return files.stream() + .map(Path::toString) + .collect(toList()); } private ShouldContain(Object actual, Object expected, Object notFound, ComparisonStrategy comparisonStrategy, diff --git a/src/main/java/org/assertj/core/error/ShouldNotContain.java b/src/main/java/org/assertj/core/error/ShouldNotContain.java index a6222f9956e..ec42cc3c3e9 100644 --- a/src/main/java/org/assertj/core/error/ShouldNotContain.java +++ b/src/main/java/org/assertj/core/error/ShouldNotContain.java @@ -12,6 +12,8 @@ */ package org.assertj.core.error; +import static java.util.stream.Collectors.toList; + import java.io.File; import java.nio.file.Path; import java.util.List; @@ -56,14 +58,24 @@ private ShouldNotContain(Object actual, Object expected, Object found, Compariso super("%nExpecting%n %s%nnot to contain%n %s%nbut found%n %s%n%s", actual, expected, found, comparisonStrategy); } - public static ErrorMessageFactory directoryShouldNotContain(File actual, List matchingContent, - String filterDescription) { - return new ShouldNotContain(actual, matchingContent, filterDescription); + public static ErrorMessageFactory directoryShouldNotContain(File actual, List matchingContent, String filterDescription) { + return new ShouldNotContain(actual, toFileNames(matchingContent), filterDescription); + } + + private static List toFileNames(List files) { + return files.stream() + .map(File::getName) + .collect(toList()); + } + + public static ErrorMessageFactory directoryShouldNotContain(Path actual, List matchingContent, String filterDescription) { + return new ShouldNotContain(actual, toPathNames(matchingContent), filterDescription); } - public static ErrorMessageFactory directoryShouldNotContain(Path actual, List matchingContent, - String filterDescription) { - return new ShouldNotContain(actual, matchingContent, filterDescription); + private static List toPathNames(List files) { + return files.stream() + .map(Path::toString) + .collect(toList()); } private ShouldNotContain(Object actual, List matchingContent, String filterDescription) { diff --git a/src/main/java/org/assertj/core/internal/Files.java b/src/main/java/org/assertj/core/internal/Files.java index e01a759b51e..04edb7556df 100644 --- a/src/main/java/org/assertj/core/internal/Files.java +++ b/src/main/java/org/assertj/core/internal/Files.java @@ -45,6 +45,7 @@ import static org.assertj.core.util.Preconditions.checkArgument; import java.io.File; +import java.io.FileFilter; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; @@ -75,7 +76,7 @@ public class Files { private static final String UNABLE_TO_COMPARE_FILE_CONTENTS = "Unable to compare contents of files:<%s> and:<%s>"; private static final Files INSTANCE = new Files(); - private static final Predicate ANY = any -> true; + private static final FileFilter ANY = any -> true; /** * Returns the singleton instance of this class. @@ -475,20 +476,19 @@ public void assertIsNotEmptyDirectory(AssertionInfo info, File actual) { public void assertIsDirectoryContaining(AssertionInfo info, File actual, Predicate filter) { requireNonNull(filter, "The files filter should not be null"); - assertIsDirectoryContaining(info, actual, filter, "the given filter"); + assertIsDirectoryContaining(info, actual, filter::test, "the given filter"); } public void assertIsDirectoryContaining(AssertionInfo info, File actual, String syntaxAndPattern) { requireNonNull(syntaxAndPattern, "The syntax and pattern should not be null"); - Predicate fileMatcher = fileMatcher(info, actual, syntaxAndPattern); - assertIsDirectoryContaining(info, actual, fileMatcher, format("the '%s' pattern", syntaxAndPattern)); + FileFilter filter = fileFilter(info, actual, syntaxAndPattern); + assertIsDirectoryContaining(info, actual, filter, format("the '%s' pattern", syntaxAndPattern)); } public void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File actual, String syntaxAndPattern) { requireNonNull(syntaxAndPattern, "The syntax and pattern should not be null"); - Predicate fileMatcher = fileMatcher(info, actual, syntaxAndPattern); - assertIsDirectoryRecursivelyContaining(info, actual, fileMatcher, - format("the '%s' pattern", syntaxAndPattern)); + FileFilter filter = fileFilter(info, actual, syntaxAndPattern); + assertIsDirectoryRecursivelyContaining(info, actual, filter::accept, format("the '%s' pattern", syntaxAndPattern)); } public void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File actual, Predicate filter) { @@ -498,27 +498,20 @@ public void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File actu public void assertIsDirectoryNotContaining(AssertionInfo info, File actual, Predicate filter) { requireNonNull(filter, "The files filter should not be null"); - assertIsDirectoryNotContaining(info, actual, filter, "the given filter"); + assertIsDirectoryNotContaining(info, actual, filter::test, "the given filter"); } public void assertIsDirectoryNotContaining(AssertionInfo info, File actual, String syntaxAndPattern) { requireNonNull(syntaxAndPattern, "The syntax and pattern should not be null"); - Predicate fileMatcher = fileMatcher(info, actual, syntaxAndPattern); - assertIsDirectoryNotContaining(info, actual, fileMatcher, format("the '%s' pattern", syntaxAndPattern)); + FileFilter filter = fileFilter(info, actual, syntaxAndPattern); + assertIsDirectoryNotContaining(info, actual, filter, format("the '%s' pattern", syntaxAndPattern)); } - @VisibleForTesting - public static List toFileNames(List files) { - return files.stream() - .map(File::getName) - .collect(toList()); - } - - // non public section + // non-public section - private List filterDirectory(AssertionInfo info, File actual, Predicate filter) { + private List filterDirectory(AssertionInfo info, File actual, FileFilter filter) { assertIsDirectory(info, actual); - File[] items = actual.listFiles(filter::test); + File[] items = actual.listFiles(filter); requireNonNull(items, "Directory listing should not be null"); return list(items); } @@ -527,25 +520,20 @@ private List directoryContent(AssertionInfo info, File actual) { return filterDirectory(info, actual, ANY); } - private void assertIsDirectoryContaining(AssertionInfo info, File actual, Predicate filter, String filterPresentation) { + private void assertIsDirectoryContaining(AssertionInfo info, File actual, FileFilter filter, String filterPresentation) { List matchingFiles = filterDirectory(info, actual, filter); if (matchingFiles.isEmpty()) { - throw failures.failure(info, directoryShouldContain(actual, directoryContentDescription(info, actual), filterPresentation)); + throw failures.failure(info, directoryShouldContain(actual, directoryContent(info, actual), filterPresentation)); } } - private void assertIsDirectoryNotContaining(AssertionInfo info, File actual, Predicate filter, - String filterPresentation) { + private void assertIsDirectoryNotContaining(AssertionInfo info, File actual, FileFilter filter, String filterPresentation) { List matchingFiles = filterDirectory(info, actual, filter); - if (matchingFiles.size() > 0) { - throw failures.failure(info, directoryShouldNotContain(actual, toFileNames(matchingFiles), filterPresentation)); + if (!matchingFiles.isEmpty()) { + throw failures.failure(info, directoryShouldNotContain(actual, matchingFiles, filterPresentation)); } } - private List directoryContentDescription(AssertionInfo info, File actual) { - return toFileNames(directoryContent(info, actual)); - } - private boolean isDirectoryRecursivelyContaining(AssertionInfo info, File actual, Predicate filter) { assertIsDirectory(info, actual); try (Stream actualContent = recursiveContentOf(actual)) { @@ -578,10 +566,10 @@ private void assertIsDirectoryRecursivelyContaining(AssertionInfo info, File act } } - private static Predicate fileMatcher(AssertionInfo info, File actual, String syntaxAndPattern) { + private static FileFilter fileFilter(AssertionInfo info, File actual, String syntaxAndPattern) { assertNotNull(info, actual); - PathMatcher pathMatcher = actual.toPath().getFileSystem().getPathMatcher(syntaxAndPattern); - return file -> pathMatcher.matches(file.toPath()); + PathMatcher matcher = actual.toPath().getFileSystem().getPathMatcher(syntaxAndPattern); + return file -> matcher.matches(file.toPath()); } private static void assertNotNull(AssertionInfo info, File actual) { diff --git a/src/main/java/org/assertj/core/internal/NioFilesWrapper.java b/src/main/java/org/assertj/core/internal/NioFilesWrapper.java index 253cb2802da..cfc80da6618 100644 --- a/src/main/java/org/assertj/core/internal/NioFilesWrapper.java +++ b/src/main/java/org/assertj/core/internal/NioFilesWrapper.java @@ -15,11 +15,10 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.DirectoryStream; +import java.nio.file.DirectoryStream.Filter; import java.nio.file.Files; -import java.nio.file.LinkOption; import java.nio.file.OpenOption; import java.nio.file.Path; -import java.util.function.Predicate; /** * Wrapper for {@link java.nio.file.Files} to test methods throwing {@link IOException}. @@ -38,8 +37,8 @@ public InputStream newInputStream(Path path, OpenOption... options) throws IOExc return Files.newInputStream(path, options); } - public DirectoryStream newDirectoryStream(Path path, Predicate matcher) throws IOException { - return Files.newDirectoryStream(path, matcher::test); + public DirectoryStream newDirectoryStream(Path dir, Filter filter) throws IOException { + return Files.newDirectoryStream(dir, filter); } public long size(Path path) throws IOException { diff --git a/src/main/java/org/assertj/core/internal/Paths.java b/src/main/java/org/assertj/core/internal/Paths.java index e2e273ce383..f8c3788a3ea 100644 --- a/src/main/java/org/assertj/core/internal/Paths.java +++ b/src/main/java/org/assertj/core/internal/Paths.java @@ -55,6 +55,7 @@ import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.nio.file.DirectoryStream; +import java.nio.file.DirectoryStream.Filter; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; @@ -80,7 +81,7 @@ public class Paths { private static final String UNABLE_TO_COMPARE_PATH_CONTENTS = "Unable to compare contents of paths:<%s> and:<%s>"; private static final Paths INSTANCE = new Paths(); - private static final Predicate ANY = any -> true; + private static final Filter ANY = any -> true; @VisibleForTesting Diff diff = new Diff(); @@ -314,7 +315,7 @@ public void assertHasDigest(AssertionInfo info, Path actual, String algorithm, S public void assertIsDirectoryContaining(AssertionInfo info, Path actual, Predicate filter) { requireNonNull(filter, "The paths filter should not be null"); - assertIsDirectoryContaining(info, actual, filter, "the given filter"); + assertIsDirectoryContaining(info, actual, filter::test, "the given filter"); } public void assertIsDirectoryContaining(AssertionInfo info, Path actual, String syntaxAndPattern) { @@ -337,7 +338,7 @@ public void assertIsDirectoryRecursivelyContaining(AssertionInfo info, Path actu public void assertIsDirectoryNotContaining(AssertionInfo info, Path actual, Predicate filter) { requireNonNull(filter, "The paths filter should not be null"); - assertIsDirectoryNotContaining(info, actual, filter, "the given filter"); + assertIsDirectoryNotContaining(info, actual, filter::test, "the given filter"); } public void assertIsDirectoryNotContaining(AssertionInfo info, Path actual, String syntaxAndPattern) { @@ -374,15 +375,9 @@ public void assertIsNotEmptyFile(AssertionInfo info, Path actual) { } } - public static List toPathNames(List files) { - return files.stream() - .map(Path::toString) - .collect(toList()); - } - - // non public section + // non-public section - private List filterDirectory(AssertionInfo info, Path actual, Predicate filter) { + private List filterDirectory(AssertionInfo info, Path actual, Filter filter) { assertIsDirectory(info, actual); try (DirectoryStream stream = nioFilesWrapper.newDirectoryStream(actual, filter)) { return stream(stream.spliterator(), false).collect(toList()); @@ -395,10 +390,10 @@ private List directoryContent(AssertionInfo info, Path actual) { return filterDirectory(info, actual, ANY); } - private void assertIsDirectoryContaining(AssertionInfo info, Path actual, Predicate filter, String filterPresentation) { + private void assertIsDirectoryContaining(AssertionInfo info, Path actual, Filter filter, String filterPresentation) { List matchingFiles = filterDirectory(info, actual, filter); if (matchingFiles.isEmpty()) { - throw failures.failure(info, directoryShouldContain(actual, directoryContentDescription(info, actual), filterPresentation)); + throw failures.failure(info, directoryShouldContain(actual, directoryContent(info, actual), filterPresentation)); } } @@ -430,18 +425,13 @@ private void assertIsDirectoryRecursivelyContaining(AssertionInfo info, Path act } } - private void assertIsDirectoryNotContaining(AssertionInfo info, Path actual, Predicate filter, - String filterPresentation) { + private void assertIsDirectoryNotContaining(AssertionInfo info, Path actual, Filter filter, String filterPresentation) { List matchingPaths = filterDirectory(info, actual, filter); if (matchingPaths.size() > 0) { - throw failures.failure(info, directoryShouldNotContain(actual, toPathNames(matchingPaths), filterPresentation)); + throw failures.failure(info, directoryShouldNotContain(actual, matchingPaths, filterPresentation)); } } - private List directoryContentDescription(AssertionInfo info, Path actual) { - return toPathNames(directoryContent(info, actual)); - } - private PathMatcher pathMatcher(AssertionInfo info, Path actual, String syntaxAndPattern) { assertNotNull(info, actual); return actual.getFileSystem().getPathMatcher(syntaxAndPattern); diff --git a/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java b/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java index 8df88fccab2..5d4ff8b55bc 100644 --- a/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldContain_create_Test.java @@ -25,6 +25,8 @@ import java.io.File; import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; import java.util.Map; import org.assertj.core.data.MapEntry; @@ -35,10 +37,6 @@ import org.junit.jupiter.api.Test; /** - * Tests for - * {@link ShouldContain#create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation)} - * . - * * @author Alex Ruiz * @author Yvonne Wang * @author Joel Costigliola @@ -295,7 +293,8 @@ void should_create_error_message_for_file_directory() { // GIVEN File directory = mock(File.class); given(directory.getAbsolutePath()).willReturn("root"); - ErrorMessageFactory factory = directoryShouldContain(directory, list("foo.txt", "bar.txt"), "glob:**.java"); + List directoryContent = list(new File("root", "foo.txt"), new File("root", "bar.txt")); + ErrorMessageFactory factory = directoryShouldContain(directory, directoryContent, "glob:**.java"); // WHEN String message = factory.create(new TextDescription("Test")); // THEN @@ -312,7 +311,8 @@ void should_create_error_message_for_file_directory_escaping_percent() { // GIVEN File directory = mock(File.class); given(directory.getAbsolutePath()).willReturn("root%dir"); - ErrorMessageFactory factory = directoryShouldContain(directory, list("foo%1.txt", "bar%2.txt"), "glob:**%Test.java"); + List directoryContent = list(new File("root%dir", "foo%1.txt"), new File("root%dir", "bar%2.txt")); + ErrorMessageFactory factory = directoryShouldContain(directory, directoryContent, "glob:**%Test.java"); // WHEN String message = factory.create(new TextDescription("Test")); // THEN @@ -327,9 +327,9 @@ void should_create_error_message_for_file_directory_escaping_percent() { @Test void should_create_error_message_for_path_directory() { // GIVEN - Path directory = mock(Path.class); - given(directory.toString()).willReturn("root"); - ErrorMessageFactory factory = directoryShouldContain(directory, list("foo.txt", "bar.txt"), "glob:**.java"); + Path directory = Paths.get("root"); + List directoryContent = list(directory.resolve("foo.txt"), directory.resolve("bar.txt")); + ErrorMessageFactory factory = directoryShouldContain(directory, directoryContent, "glob:**.java"); // WHEN String message = factory.create(new TextDescription("Test")); // THEN @@ -338,7 +338,8 @@ void should_create_error_message_for_path_directory() { " root%n" + "to contain at least one file matching glob:**.java but there was none.%n" + "The directory content was:%n" + - " [foo.txt, bar.txt]")); + " [%s, %s]", + directory.resolve("foo.txt"), directory.resolve("bar.txt"))); } } diff --git a/src/test/java/org/assertj/core/error/ShouldNotContain_create_Test.java b/src/test/java/org/assertj/core/error/ShouldNotContain_create_Test.java index 07ef89fdce8..b4089a09ab2 100644 --- a/src/test/java/org/assertj/core/error/ShouldNotContain_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldNotContain_create_Test.java @@ -23,6 +23,8 @@ import java.io.File; import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; import org.assertj.core.description.TextDescription; import org.assertj.core.internal.ComparatorBasedComparisonStrategy; @@ -82,7 +84,8 @@ void should_create_error_message_for_file_directory() { // GIVEN File directory = mock(File.class); given(directory.getAbsolutePath()).willReturn("root"); - ErrorMessageFactory factory = directoryShouldNotContain(directory, list("foo.txt", "bar.txt"), "glob:**.java"); + List matchingContent = list(new File("root", "foo.txt"), new File("root", "bar.txt")); + ErrorMessageFactory factory = directoryShouldNotContain(directory, matchingContent, "glob:**.java"); // WHEN String message = factory.create(new TextDescription("Test")); // THEN @@ -96,9 +99,9 @@ void should_create_error_message_for_file_directory() { @Test void should_create_error_message_for_path_directory() { // GIVEN - Path directory = mock(Path.class); - given(directory.toString()).willReturn("root"); - ErrorMessageFactory factory = directoryShouldNotContain(directory, list("foo.txt", "bar.txt"), "glob:**.java"); + Path directory = Paths.get("root"); + List matchingContent = list(directory.resolve("foo.txt"), directory.resolve("bar.txt")); + ErrorMessageFactory factory = directoryShouldNotContain(directory, matchingContent, "glob:**.java"); // WHEN String message = factory.create(new TextDescription("Test")); // THEN @@ -106,7 +109,8 @@ void should_create_error_message_for_path_directory() { "Expecting directory:%n" + " root%n" + "not to contain any files matching glob:**.java but found some:%n" + - " [foo.txt, bar.txt]")); + " [%s, %s]", + directory.resolve("foo.txt"), directory.resolve("bar.txt"))); } } diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java index 3a75470f713..c96a9a3dc25 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_Predicate_Test.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldContain.directoryShouldContain; -import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.core.util.Lists.list; @@ -156,6 +155,6 @@ void should_fail_if_actual_does_not_contain_any_files_matching_the_given_predica // WHEN expectAssertionError(() -> files.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE)); // THEN - verify(failures).failure(INFO, directoryShouldContain(actual, toFileNames(items), "the given filter")); + verify(failures).failure(INFO, directoryShouldContain(actual, items, "the given filter")); } } diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java index 7fe9a9a85b1..590e2530212 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldContain.directoryShouldContain; -import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.core.util.Lists.list; @@ -172,7 +171,7 @@ void should_fail_if_actual_does_not_contain_any_files_matching_the_given_pathMat // WHEN expectAssertionError(() -> files.assertIsDirectoryContaining(INFO, actual, JAVA_SOURCE_PATTERN)); // THEN - verify(failures).failure(INFO, directoryShouldContain(actual, toFileNames(items), JAVA_SOURCE_PATTERN_DESCRIPTION)); + verify(failures).failure(INFO, directoryShouldContain(actual, items, JAVA_SOURCE_PATTERN_DESCRIPTION)); } static void mockPathMatcher(File actual) { diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java index 83546d5faa8..aa0c631d458 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_Predicate_Test.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; -import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.core.util.Lists.list; @@ -126,7 +125,7 @@ void should_fail_if_one_actual_file_matches_the_filter() { // WHEN expectAssertionError(() -> files.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toFileNames(items), "the given filter")); + verify(failures).failure(INFO, directoryShouldNotContain(actual, items, "the given filter")); } @Test @@ -139,7 +138,7 @@ void should_fail_if_all_actual_files_match_the_filter() { // WHEN expectAssertionError(() -> files.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toFileNames(items), "the given filter")); + verify(failures).failure(INFO, directoryShouldNotContain(actual, items, "the given filter")); } @Test @@ -155,7 +154,7 @@ void should_fail_if_some_actual_files_match_the_filter() { // WHEN expectAssertionError(() -> files.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE)); // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toFileNames(list(file2, file4)), "the given filter")); + verify(failures).failure(INFO, directoryShouldNotContain(actual, list(file2, file4), "the given filter")); } } diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java index 6c578ebf1a5..63ca001c9eb 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertIsDirectoryNotContaining_SyntaxAndPattern_Test.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; -import static org.assertj.core.internal.Files.toFileNames; import static org.assertj.core.internal.files.Files_assertIsDirectoryContaining_SyntaxAndPattern_Test.mockPathMatcher; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; @@ -135,7 +134,7 @@ void should_fail_if_one_actual_file_matches_the_filter() { // WHEN expectAssertionError(() -> files.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toFileNames(items), JAVA_SOURCE_PATTERN_DESCRIPTION)); + verify(failures).failure(INFO, directoryShouldNotContain(actual, items, JAVA_SOURCE_PATTERN_DESCRIPTION)); } @Test @@ -149,7 +148,7 @@ void should_fail_if_all_actual_files_match_the_filter() { // WHEN expectAssertionError(() -> files.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); // THEN - verify(failures).failure(INFO, directoryShouldNotContain(actual, toFileNames(items), JAVA_SOURCE_PATTERN_DESCRIPTION)); + verify(failures).failure(INFO, directoryShouldNotContain(actual, items, JAVA_SOURCE_PATTERN_DESCRIPTION)); } @Test @@ -167,7 +166,7 @@ void should_fail_if_some_actual_files_match_the_filter() { expectAssertionError(() -> files.assertIsDirectoryNotContaining(INFO, actual, JAVA_SOURCE_PATTERN)); // THEN verify(failures).failure(INFO, - directoryShouldNotContain(actual, toFileNames(list(file2, file4)), JAVA_SOURCE_PATTERN_DESCRIPTION)); + directoryShouldNotContain(actual, list(file2, file4), JAVA_SOURCE_PATTERN_DESCRIPTION)); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java index b62c70c7cc6..202f1e23905 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_Predicate_Test.java @@ -15,7 +15,6 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; @@ -23,6 +22,7 @@ import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willThrow; @@ -129,7 +129,7 @@ void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_predica // WHEN AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, filter)); // THEN - then(error).hasMessage(directoryShouldContain(actual, singletonList(directory.toString()), "the given filter").create()); + then(error).hasMessage(directoryShouldContain(actual, list(directory), "the given filter").create()); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java index a92e9006939..34c011a25d8 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java @@ -15,7 +15,6 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; @@ -23,6 +22,7 @@ import static org.assertj.core.error.ShouldExist.shouldExist; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willThrow; @@ -128,8 +128,7 @@ void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_pattern // WHEN AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); // THEN - then(error).hasMessage(directoryShouldContain(actual, singletonList(directory.toString()), - "the 'glob:**file' pattern").create()); + then(error).hasMessage(directoryShouldContain(actual, list(directory), "the 'glob:**file' pattern").create()); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java index 91cd31ed350..d854ef6fb41 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_Predicate_Test.java @@ -14,7 +14,6 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; @@ -22,6 +21,7 @@ import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willThrow; @@ -116,7 +116,7 @@ void should_fail_if_actual_contains_at_least_one_path_matching_the_given_predica // WHEN AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, filter)); // THEN - then(error).hasMessage(directoryShouldNotContain(actual, singletonList(file.toString()), "the given filter").create()); + then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the given filter").create()); } @Test diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java index e4abaf148e6..8107fb92761 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java @@ -14,7 +14,6 @@ import static java.nio.file.Files.createDirectory; import static java.nio.file.Files.createFile; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.catchThrowable; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeDirectory.shouldBeDirectory; @@ -22,6 +21,7 @@ import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Lists.list; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.willThrow; @@ -114,8 +114,7 @@ void should_fail_if_actual_contains_at_least_one_path_matching_the_given_pattern // WHEN AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); // THEN - then(error).hasMessage(directoryShouldNotContain(actual, singletonList(file.toString()), - "the 'glob:**file' pattern").create()); + then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the 'glob:**file' pattern").create()); } @Test From 9e5161f5ff6b271bda2e1e387d3b22f762f8ec82 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Wed, 15 Sep 2021 23:05:13 +0200 Subject: [PATCH 115/123] Use Java 17 GA, remove EOL Java 16 --- .github/workflows/cross-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cross-version.yml b/.github/workflows/cross-version.yml index 0892dab4d5d..956b4a7af7b 100644 --- a/.github/workflows/cross-version.yml +++ b/.github/workflows/cross-version.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - java: [16, 17-ea, 18-ea] + java: [17, 18-ea] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From a0e7214c866252ac390aff6f48f0c2b7a4536051 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Sep 2021 23:26:18 +0200 Subject: [PATCH 116/123] Bump spring-core from 5.3.9 to 5.3.10 (#2344) Bumps [spring-core](https://github.com/spring-projects/spring-framework) from 5.3.9 to 5.3.10. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v5.3.9...v5.3.10) --- updated-dependencies: - dependency-name: org.springframework:spring-core dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0acfa002ab9..276f9b77ee1 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ org.springframework spring-core - 5.3.9 + 5.3.10 test From 620ec2983e15e3d15ab05e15605ba81789d62892 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Sep 2021 23:26:47 +0200 Subject: [PATCH 117/123] Bump org.eclipse.osgi from 3.16.300 to 3.17.0 (#2343) Bumps org.eclipse.osgi from 3.16.300 to 3.17.0. --- updated-dependencies: - dependency-name: org.eclipse.platform:org.eclipse.osgi dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 276f9b77ee1..85186777ff2 100644 --- a/pom.xml +++ b/pom.xml @@ -145,7 +145,7 @@ org.eclipse.platform org.eclipse.osgi - 3.16.300 + 3.17.0 test From daf13ee9e651ddfc58ea48d76f488e1ff2350103 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Thu, 16 Sep 2021 23:14:38 +0200 Subject: [PATCH 118/123] Add additional tests for `Path` assertions --- ...sDirectoryContaining_with_String_Test.java | 46 +++++++++++++++---- ...rectoryNotContaining_with_String_Test.java | 42 ++++++++++++++--- 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java index 34c011a25d8..2e2ce9d3bc5 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java @@ -32,6 +32,8 @@ import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * @author Valeriy Vyrva @@ -108,27 +110,55 @@ void should_fail_if_actual_is_empty() throws IOException { then(error).hasMessage(directoryShouldContain(actual, emptyList(), "the 'glob:**' pattern").create()); } - @Test - void should_pass_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException { + @ParameterizedTest + @ValueSource(strings = { + "glob:**file", +// "glob:file", // fails due to gh-2329 + "regex:.*file", +// "regex:file", // fails due to gh-2329 + }) + void should_pass_if_actual_directly_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); - createFile(actual.resolve("file")); createDirectory(actual.resolve("directory")); - String syntaxAndPattern = "glob:**file"; + createFile(actual.resolve("file")); // WHEN/THEN paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern); } - @Test - void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException { + @ParameterizedTest + @ValueSource(strings = { + "glob:**file", + "glob:file", + "regex:.*file", + "regex:file", + }) + void should_fail_if_actual_does_not_contain_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Path directory = createDirectory(actual.resolve("directory")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); + // THEN + then(error).hasMessage(directoryShouldContain(actual, list(directory), "the '" + syntaxAndPattern + "' pattern").create()); + } + + @ParameterizedTest + @ValueSource(strings = { + "glob:**file", + "glob:file", + "regex:.*file", + "regex:file", + }) + void should_fail_if_actual_recursively_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); Path directory = createDirectory(actual.resolve("directory")); - String syntaxAndPattern = "glob:**file"; + createFile(directory.resolve("file")); // WHEN AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern)); // THEN - then(error).hasMessage(directoryShouldContain(actual, list(directory), "the 'glob:**file' pattern").create()); + then(error).hasMessage(directoryShouldContain(actual, list(directory), "the '" + syntaxAndPattern + "' pattern").create()); } } diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java index 8107fb92761..8fe96d34136 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java @@ -31,6 +31,8 @@ import org.assertj.core.internal.PathsBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * @author Valeriy Vyrva @@ -105,24 +107,50 @@ void should_pass_if_actual_is_empty() throws IOException { paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern); } - @Test - void should_fail_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException { + @ParameterizedTest + @ValueSource(strings = { + "glob:**file", +// "glob:file", // fails due to gh-2329 + "regex:.*file", +// "regex:file", // fails due to gh-2329 + }) + void should_fail_if_actual_directly_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); Path file = createFile(actual.resolve("file")); - String syntaxAndPattern = "glob:**file"; // WHEN AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern)); // THEN - then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the 'glob:**file' pattern").create()); + then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the '" + syntaxAndPattern + "' pattern").create()); } - @Test - void should_pass_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException { + @ParameterizedTest + @ValueSource(strings = { + "glob:**file", + "glob:file", + "regex:.*file", + "regex:file", + }) + void should_pass_if_actual_does_not_contain_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException { // GIVEN Path actual = createDirectory(tempDir.resolve("actual")); createDirectory(actual.resolve("directory")); - String syntaxAndPattern = "glob:**file"; + // WHEN/THEN + paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern); + } + + @ParameterizedTest + @ValueSource(strings = { + "glob:**file", + "glob:file", + "regex:.*file", + "regex:file", + }) + void should_pass_if_actual_recursively_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("actual")); + Path directory = createDirectory(actual.resolve("directory")); + createFile(directory.resolve("file")); // WHEN/THEN paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern); } From cd2ce8251adac65884460c0f2db0e56adcc1d9ae Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Fri, 17 Sep 2021 22:12:09 +1200 Subject: [PATCH 119/123] Javadoc improvements --- .../core/api/AbstractCharSequenceAssert.java | 4 +-- .../assertj/core/api/AbstractPathAssert.java | 31 +++++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java b/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java index ca5316295b9..88de31b9458 100644 --- a/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractCharSequenceAssert.java @@ -665,10 +665,10 @@ public SELF contains(CharSequence... values) { * Verifies that the actual {@code CharSequence} contains any of the given values. *

    * Example: - *

     // assertions will pass
    +   * 
     // assertion succeeds
        * assertThat("Gandalf the grey").containsAnyOf("grey", "black");
        *
    -   * // assertions will fail
    +   * // assertion fails
        * assertThat("Gandalf the grey").containsAnyOf("white", "black");
    * * @param values the values to look for. diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index a7503e0f0a9..048495f5f79 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -1117,20 +1117,14 @@ public SELF hasNoParentRaw() { *

    * * Examples: - *
     // Given the following empty paths
    -   * /root/sub-dir-1/foo.ext
    -   * /root/sub-dir-1/bar.ext
    +   * 
    
    +   * Path foxPath = Files.write(Paths.get("/fox.txt"), "The Quick Brown Fox.".getBytes());
    +   * 
    +   * // this assertion succeeds
    +   * assertThat(foxPath).hasSize(20);
        *
    -   * Path emptyPath = Paths.get("/root/sub-dir-1/foo.ext")
    -   * Path nonEmptyPath = Files.write(Paths.get("/root/sub-dir-1/bar.ext"),
    -   *                                 "The Quick Brown Fox.".getBytes());
    -   * // the following assertions pass
    -   * assertThat(emptyPath).hasSize(0);
    -   * assertThat(nonEmptyPath).hasSize(20);
    -   *
    -   * // the following assertions fail
    -   * assertThat(emptyPath).hasSize(5);
    -   * assertThat(nonEmptyPath).hasSize(0);
    + * // this assertion fails + * assertThat(foxPath).hasSize(3);
    * * @param expectedSize the expected {@code Path} file size in bytes * @return {@code this} assertion object @@ -1912,18 +1906,17 @@ private String readPath(Charset charset) { /** * Verifies that the actual {@code Path} has given extension. - * *

    * Example: *

     Path path = Paths.get("file.java");
        *
    -   * // assertion will pass
    +   * // assertion succeeds:
        * assertThat(path).hasExtension("java");
        *
    -   * // assertion will fail
    +   * // assertion fails:
        * assertThat(path).hasExtension("png");
    * - * @param expected the expected extension, without the {@code '.'}. + * @param expectedExtension the expected extension, without the {@code '.'}. * @return {@code this} assertion object. * @throws NullPointerException if the expected extension is {@code null}. * @throws AssertionError if the actual {@code Path} is {@code null}. @@ -1931,8 +1924,8 @@ private String readPath(Charset charset) { * @throws AssertionError if the actual {@code Path} does not have the expected extension. * @since 3.21.0 */ - public SELF hasExtension(String expected) { - paths.assertHasExtension(info, actual, expected); + public SELF hasExtension(String expectedExtension) { + paths.assertHasExtension(info, actual, expectedExtension); return myself; } From 931b5920e9a1eaa93dd7fd30885db3f7a4d22cdf Mon Sep 17 00:00:00 2001 From: Szymon Linowski Date: Sat, 11 Sep 2021 18:01:31 +0200 Subject: [PATCH 120/123] Add hasNoExtension to Path assertions --- .../assertj/core/api/AbstractPathAssert.java | 25 +++++- .../core/error/ShouldHaveNoExtension.java | 31 +++++++ .../java/org/assertj/core/internal/Paths.java | 7 ++ .../path/PathAssert_hasNoExtension_Test.java | 32 +++++++ .../ShouldHaveNoExtension_create_Test.java | 42 ++++++++++ .../Paths_assertHasNoExtension_Test.java | 83 +++++++++++++++++++ 6 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java create mode 100644 src/test/java/org/assertj/core/api/path/PathAssert_hasNoExtension_Test.java create mode 100644 src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java create mode 100644 src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoExtension_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index 048495f5f79..c31856700ac 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -1910,10 +1910,10 @@ private String readPath(Charset charset) { * Example: *
     Path path = Paths.get("file.java");
        *
    -   * // assertion succeeds:
    +   * // assertion succeeds
        * assertThat(path).hasExtension("java");
        *
    -   * // assertion fails:
    +   * // assertion fails
        * assertThat(path).hasExtension("png");
    * * @param expectedExtension the expected extension, without the {@code '.'}. @@ -1929,4 +1929,25 @@ public SELF hasExtension(String expectedExtension) { return myself; } + /** + * Verifies that the actual {@code Path} has no extension. + * + *

    + * Example: + *

     // assertion succeeds
    +   * assertThat(Paths.get("file")).hasNoExtension();
    +   *
    +   * // assertion fails
    +   * assertThat(Paths.get("file.txt")).hasNoExtension();
    + * + * @return {@code this} assertion object. + * @throws AssertionError if the actual {@code Path} is {@code null}. + * @throws AssertionError if the actual {@code Path} is not a regular file. + * @throws AssertionError if the actual {@code Path} does have an extension. + */ + public SELF hasNoExtension() { + paths.assertHasNoExtension(info, actual); + return myself; + } + } diff --git a/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java b/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java new file mode 100644 index 00000000000..29afc5e0630 --- /dev/null +++ b/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java @@ -0,0 +1,31 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +import java.nio.file.Path; + +/** + * Creates an error message indicating that a {@code Path} should have no extension. + */ +public class ShouldHaveNoExtension extends BasicErrorMessageFactory { + + private static final String PATH_HAS_EXTENSION = "%nExpected actual path:%n %s%n not to have an extension, but extension was: %s"; + + public static ShouldHaveNoExtension shouldHaveNoExtension(Path actual, String extension) { + return new ShouldHaveNoExtension(actual, extension); + } + + private ShouldHaveNoExtension(Path actual, String extension) { + super(PATH_HAS_EXTENSION, actual, extension); + } +} diff --git a/src/main/java/org/assertj/core/internal/Paths.java b/src/main/java/org/assertj/core/internal/Paths.java index f8c3788a3ea..988d8578007 100644 --- a/src/main/java/org/assertj/core/internal/Paths.java +++ b/src/main/java/org/assertj/core/internal/Paths.java @@ -40,6 +40,7 @@ import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; import static org.assertj.core.error.ShouldHaveExtension.shouldHaveExtension; import static org.assertj.core.error.ShouldHaveName.shouldHaveName; +import static org.assertj.core.error.ShouldHaveNoExtension.shouldHaveNoExtension; import static org.assertj.core.error.ShouldHaveNoParent.shouldHaveNoParent; import static org.assertj.core.error.ShouldHaveParent.shouldHaveParent; import static org.assertj.core.error.ShouldHaveSameContent.shouldHaveSameContent; @@ -468,6 +469,12 @@ public void assertHasExtension(AssertionInfo info, Path actual, String expected) if (!expected.equals(extension)) throw failures.failure(info, shouldHaveExtension(actual, extension, expected)); } + public void assertHasNoExtension(AssertionInfo info, Path actual) { + assertIsRegularFile(info, actual); + Optional extension = getExtension(actual); + if (extension.isPresent()) throw failures.failure(info, shouldHaveNoExtension(actual, extension.get())); + } + private static Optional getExtension(Path path) { String fileName = path.getFileName().toString(); int dotAt = fileName.lastIndexOf('.'); diff --git a/src/test/java/org/assertj/core/api/path/PathAssert_hasNoExtension_Test.java b/src/test/java/org/assertj/core/api/path/PathAssert_hasNoExtension_Test.java new file mode 100644 index 00000000000..8d0b9d6f830 --- /dev/null +++ b/src/test/java/org/assertj/core/api/path/PathAssert_hasNoExtension_Test.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.path; + +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.PathAssert; +import org.assertj.core.api.PathAssertBaseTest; + +class PathAssert_hasNoExtension_Test extends PathAssertBaseTest { + + @Override + protected PathAssert invoke_api_method() { + return assertions.hasNoExtension(); + } + + @Override + protected void verify_internal_effects() { + verify(paths).assertHasNoExtension(getInfo(assertions), getActual(assertions)); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java new file mode 100644 index 00000000000..4329b096186 --- /dev/null +++ b/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java @@ -0,0 +1,42 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.error; + +import static java.lang.String.format; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldHaveNoExtension.shouldHaveNoExtension; +import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; +import static org.mockito.Mockito.mock; + +import java.nio.file.Path; + +import org.assertj.core.internal.TestDescription; +import org.junit.jupiter.api.Test; + +class ShouldHaveNoExtension_create_Test { + + private static final TestDescription TEST_DESCRIPTION = new TestDescription("Test"); + + @Test + void should_create_error_message() { + // GIVEN + final Path path = mock(Path.class); + // WHEN + String actualMessage = shouldHaveNoExtension(path, "java").create(TEST_DESCRIPTION, STANDARD_REPRESENTATION); + // THEN + then(actualMessage).isEqualTo(format("[Test] %n" + + "Expected actual path:%n" + + " %s%n" + + " not to have an extension, but extension was: \"java\"", path)); + } +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoExtension_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoExtension_Test.java new file mode 100644 index 00000000000..4778f5e6bcb --- /dev/null +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoExtension_Test.java @@ -0,0 +1,83 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.paths; + +import static java.nio.file.Files.createDirectory; +import static java.nio.file.Files.createFile; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeRegularFile.shouldBeRegularFile; +import static org.assertj.core.error.ShouldExist.shouldExist; +import static org.assertj.core.error.ShouldHaveNoExtension.shouldHaveNoExtension; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; + +import java.io.IOException; +import java.nio.file.Path; + +import org.assertj.core.internal.PathsBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class Paths_assertHasNoExtension_Test extends PathsBaseTest { + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + Path actual = null; + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + Path actual = tempDir.resolve("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); + // THEN + then(error).hasMessage(shouldExist(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_regular_file() throws IOException { + // GIVEN + Path actual = createDirectory(tempDir.resolve("directory")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); + // THEN + then(error).hasMessage(shouldBeRegularFile(actual).create()); + } + + @Test + void should_fail_if_actual_has_extension() throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve("file.txt")); + // WHEN + AssertionError error = expectAssertionError(() -> paths.assertHasNoExtension(info, actual)); + // THEN + then(error).hasMessage(shouldHaveNoExtension(actual, "txt").create()); + } + + @ParameterizedTest + @ValueSource(strings = { "file", "file." }) + void should_pass_if_actual_has_no_extension(String filename) throws IOException { + // GIVEN + Path actual = createFile(tempDir.resolve(filename)); + // WHEN/THEN + paths.assertHasNoExtension(info, actual); + } + +} From 5bef9b2915334eebc419ea4b45e20236918c6077 Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Fri, 17 Sep 2021 13:39:51 +0200 Subject: [PATCH 121/123] Bump byte-buddy.version from 1.11.15 to 1.11.16 Fixes #2340. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 85186777ff2..e3f6daa78b5 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ -Dfile.encoding=${project.build.sourceEncoding} -html5 --allow-script-in-comments --no-module-directories - 1.11.15 + 1.11.16 2.2 1.2.0 5.3.0 From a7ef096951d363d3bc5eb72d38685d77c70acbf5 Mon Sep 17 00:00:00 2001 From: Joel Costigliola Date: Sat, 18 Sep 2021 23:08:53 +1200 Subject: [PATCH 122/123] Add hasNoExtension to File assertions. Commonize how to get a file/path extension. --- .../assertj/core/api/AbstractFileAssert.java | 22 +++++ .../assertj/core/api/AbstractPathAssert.java | 3 +- .../core/error/ShouldHaveExtension.java | 4 + .../core/error/ShouldHaveNoExtension.java | 10 +++ .../java/org/assertj/core/internal/Files.java | 20 +++-- .../java/org/assertj/core/internal/Paths.java | 6 +- .../java/org/assertj/core/util/Files.java | 11 ++- .../file/FileAssert_hasNoExtension_Test.java | 32 ++++++++ .../ShouldHaveNoExtension_create_Test.java | 20 ++++- .../assertj/core/internal/FilesBaseTest.java | 4 + .../files/Files_assertHasExtension_Test.java | 81 +++++++++++------- .../Files_assertHasNoExtension_Test.java | 82 +++++++++++++++++++ .../paths/Paths_assertHasExtension_Test.java | 2 +- 13 files changed, 251 insertions(+), 46 deletions(-) create mode 100644 src/test/java/org/assertj/core/api/file/FileAssert_hasNoExtension_Test.java create mode 100644 src/test/java/org/assertj/core/internal/files/Files_assertHasNoExtension_Test.java diff --git a/src/main/java/org/assertj/core/api/AbstractFileAssert.java b/src/main/java/org/assertj/core/api/AbstractFileAssert.java index 2b55278feb6..2803d2d17c2 100644 --- a/src/main/java/org/assertj/core/api/AbstractFileAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractFileAssert.java @@ -1372,6 +1372,28 @@ public AbstractStringAssert content(Charset charset) { return internalContent(charset); } + /** + * Verifies that the actual {@code File} has no extension. + * + *

    + * Example: + *

     // assertions succeed
    +   * assertThat(new File("file")).hasNoExtension();
    +   * assertThat(new File("file.")).hasNoExtension();
    +   *
    +   * // assertion fails
    +   * assertThat(new File("file.txt")).hasNoExtension();
    + * + * @return {@code this} assertion object. + * @throws AssertionError if the actual {@code File} is {@code null}. + * @throws AssertionError if the actual {@code File} is not a file (ie a directory or does not exist). + * @throws AssertionError if the actual {@code File} does have an extension. + */ + public SELF hasNoExtension() { + files.assertHasNoExtension(info, actual); + return myself; + } + // this method was introduced to avoid to avoid double proxying in soft assertions for content() private AbstractStringAssert internalContent(Charset charset) { files.assertCanRead(info, actual); diff --git a/src/main/java/org/assertj/core/api/AbstractPathAssert.java b/src/main/java/org/assertj/core/api/AbstractPathAssert.java index c31856700ac..2d13a2964af 100644 --- a/src/main/java/org/assertj/core/api/AbstractPathAssert.java +++ b/src/main/java/org/assertj/core/api/AbstractPathAssert.java @@ -1934,8 +1934,9 @@ public SELF hasExtension(String expectedExtension) { * *

    * Example: - *

     // assertion succeeds
    +   * 
     // assertions succeed
        * assertThat(Paths.get("file")).hasNoExtension();
    +   * assertThat(Paths.get("file.")).hasNoExtension();
        *
        * // assertion fails
        * assertThat(Paths.get("file.txt")).hasNoExtension();
    diff --git a/src/main/java/org/assertj/core/error/ShouldHaveExtension.java b/src/main/java/org/assertj/core/error/ShouldHaveExtension.java index f06fdf257a5..35cb013d834 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveExtension.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveExtension.java @@ -43,6 +43,10 @@ public static ShouldHaveExtension shouldHaveExtension(Path actual, String expect return new ShouldHaveExtension(actual, expectedExtension); } + public static ShouldHaveExtension shouldHaveExtension(File actual, String expectedExtension) { + return new ShouldHaveExtension(actual, expectedExtension); + } + private ShouldHaveExtension(Object actual, String expectedExtension) { super("%nExpecting%n %s%nto have extension:%n %s%nbut had no extension.", actual, expectedExtension); } diff --git a/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java b/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java index 29afc5e0630..e2c339694c0 100644 --- a/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java +++ b/src/main/java/org/assertj/core/error/ShouldHaveNoExtension.java @@ -12,6 +12,7 @@ */ package org.assertj.core.error; +import java.io.File; import java.nio.file.Path; /** @@ -20,12 +21,21 @@ public class ShouldHaveNoExtension extends BasicErrorMessageFactory { private static final String PATH_HAS_EXTENSION = "%nExpected actual path:%n %s%n not to have an extension, but extension was: %s"; + private static final String FILE_HAS_EXTENSION = "%nExpected actual file:%n %s%n not to have an extension, but extension was: %s"; public static ShouldHaveNoExtension shouldHaveNoExtension(Path actual, String extension) { return new ShouldHaveNoExtension(actual, extension); } + public static ShouldHaveNoExtension shouldHaveNoExtension(File actual, String extension) { + return new ShouldHaveNoExtension(actual, extension); + } + private ShouldHaveNoExtension(Path actual, String extension) { super(PATH_HAS_EXTENSION, actual, extension); } + + private ShouldHaveNoExtension(File actual, String extension) { + super(FILE_HAS_EXTENSION, actual, extension); + } } diff --git a/src/main/java/org/assertj/core/internal/Files.java b/src/main/java/org/assertj/core/internal/Files.java index 04edb7556df..a4f6fcb8063 100644 --- a/src/main/java/org/assertj/core/internal/Files.java +++ b/src/main/java/org/assertj/core/internal/Files.java @@ -33,6 +33,7 @@ import static org.assertj.core.error.ShouldHaveDigest.shouldHaveDigest; import static org.assertj.core.error.ShouldHaveExtension.shouldHaveExtension; import static org.assertj.core.error.ShouldHaveName.shouldHaveName; +import static org.assertj.core.error.ShouldHaveNoExtension.shouldHaveNoExtension; import static org.assertj.core.error.ShouldHaveNoParent.shouldHaveNoParent; import static org.assertj.core.error.ShouldHaveParent.shouldHaveParent; import static org.assertj.core.error.ShouldHaveSameContent.shouldHaveSameContent; @@ -41,6 +42,7 @@ import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; import static org.assertj.core.error.ShouldNotExist.shouldNotExist; import static org.assertj.core.internal.Digests.digestDiff; +import static org.assertj.core.util.Files.getFileNameExtension; import static org.assertj.core.util.Lists.list; import static org.assertj.core.util.Preconditions.checkArgument; @@ -56,6 +58,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; @@ -395,9 +398,14 @@ public void assertHasParent(AssertionInfo info, File actual, File expected) { public void assertHasExtension(AssertionInfo info, File actual, String expected) { requireNonNull(expected, "The expected extension should not be null."); assertIsFile(info, actual); - String actualExtension = getFileExtension(actual); - if (expected.equals(actualExtension)) return; - throw failures.failure(info, shouldHaveExtension(actual, actualExtension, expected)); + String extension = getFileExtension(actual).orElseThrow(() -> failures.failure(info, shouldHaveExtension(actual, expected))); + if (!expected.equals(extension)) throw failures.failure(info, shouldHaveExtension(actual, extension, expected)); + } + + public void assertHasNoExtension(AssertionInfo info, File actual) { + assertIsFile(info, actual); + Optional extension = getFileExtension(actual); + if (extension.isPresent()) throw failures.failure(info, shouldHaveNoExtension(actual, extension.get())); } /** @@ -576,10 +584,8 @@ private static void assertNotNull(AssertionInfo info, File actual) { Objects.instance().assertNotNull(info, actual); } - private String getFileExtension(File file) { - String name = file.getName(); - int dotAt = name.lastIndexOf('.'); - return dotAt == -1 ? null : name.substring(dotAt + 1); + private Optional getFileExtension(File file) { + return getFileNameExtension(file.getName()); } private void verifyIsFile(File expected) { diff --git a/src/main/java/org/assertj/core/internal/Paths.java b/src/main/java/org/assertj/core/internal/Paths.java index 988d8578007..3d29279a099 100644 --- a/src/main/java/org/assertj/core/internal/Paths.java +++ b/src/main/java/org/assertj/core/internal/Paths.java @@ -49,6 +49,7 @@ import static org.assertj.core.error.ShouldNotContain.directoryShouldNotContain; import static org.assertj.core.error.ShouldNotExist.shouldNotExist; import static org.assertj.core.error.ShouldStartWithPath.shouldStartWith; +import static org.assertj.core.util.Files.getFileNameExtension; import static org.assertj.core.util.Preconditions.checkArgument; import java.io.IOException; @@ -477,10 +478,7 @@ public void assertHasNoExtension(AssertionInfo info, Path actual) { private static Optional getExtension(Path path) { String fileName = path.getFileName().toString(); - int dotAt = fileName.lastIndexOf('.'); - if (dotAt == -1) return Optional.empty(); - String extension = fileName.substring(dotAt + 1); - return extension.equals("") ? Optional.empty() : Optional.of(extension); + return getFileNameExtension(fileName); } } diff --git a/src/main/java/org/assertj/core/util/Files.java b/src/main/java/org/assertj/core/util/Files.java index 7947b5a9659..76cd0a2a1f0 100644 --- a/src/main/java/org/assertj/core/util/Files.java +++ b/src/main/java/org/assertj/core/util/Files.java @@ -26,6 +26,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; /** @@ -35,6 +36,9 @@ * @author Alex Ruiz */ public class Files { + + private Files() {} + /** * Returns the names of the files inside the specified directory. * @@ -311,6 +315,11 @@ private static void checkArgumentCharsetIsSupported(String charsetName) { checkArgument(Charset.isSupported(charsetName), "Charset:<'%s'> is not supported on this system", charsetName); } - private Files() {} + public static Optional getFileNameExtension(String fileName) { + int dotAt = fileName.lastIndexOf('.'); + if (dotAt == -1) return Optional.empty(); + String extension = fileName.substring(dotAt + 1); + return extension.equals("") ? Optional.empty() : Optional.of(extension); + } } diff --git a/src/test/java/org/assertj/core/api/file/FileAssert_hasNoExtension_Test.java b/src/test/java/org/assertj/core/api/file/FileAssert_hasNoExtension_Test.java new file mode 100644 index 00000000000..77214c6e7c0 --- /dev/null +++ b/src/test/java/org/assertj/core/api/file/FileAssert_hasNoExtension_Test.java @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.api.file; + +import static org.mockito.Mockito.verify; + +import org.assertj.core.api.FileAssert; +import org.assertj.core.api.FileAssertBaseTest; + +class FileAssert_hasNoExtension_Test extends FileAssertBaseTest { + + @Override + protected FileAssert invoke_api_method() { + return assertions.hasNoExtension(); + } + + @Override + protected void verify_internal_effects() { + verify(files).assertHasNoExtension(getInfo(assertions), getActual(assertions)); + } + +} diff --git a/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java b/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java index 4329b096186..c6affe8a02b 100644 --- a/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java +++ b/src/test/java/org/assertj/core/error/ShouldHaveNoExtension_create_Test.java @@ -18,6 +18,7 @@ import static org.assertj.core.presentation.StandardRepresentation.STANDARD_REPRESENTATION; import static org.mockito.Mockito.mock; +import java.io.File; import java.nio.file.Path; import org.assertj.core.internal.TestDescription; @@ -28,7 +29,7 @@ class ShouldHaveNoExtension_create_Test { private static final TestDescription TEST_DESCRIPTION = new TestDescription("Test"); @Test - void should_create_error_message() { + void should_create_error_message_for_path() { // GIVEN final Path path = mock(Path.class); // WHEN @@ -37,6 +38,21 @@ void should_create_error_message() { then(actualMessage).isEqualTo(format("[Test] %n" + "Expected actual path:%n" + " %s%n" + - " not to have an extension, but extension was: \"java\"", path)); + " not to have an extension, but extension was: \"java\"", + STANDARD_REPRESENTATION.toStringOf(path))); + } + + @Test + void should_create_error_message_for_file() { + // GIVEN + final File file = new File("foo.java"); + // WHEN + String actualMessage = shouldHaveNoExtension(file, "java").create(TEST_DESCRIPTION, STANDARD_REPRESENTATION); + // THEN + then(actualMessage).isEqualTo(format("[Test] %n" + + "Expected actual file:%n" + + " %s%n" + + " not to have an extension, but extension was: \"java\"", + STANDARD_REPRESENTATION.toStringOf(file))); } } diff --git a/src/test/java/org/assertj/core/internal/FilesBaseTest.java b/src/test/java/org/assertj/core/internal/FilesBaseTest.java index 7ef765959b2..42dadd509fa 100644 --- a/src/test/java/org/assertj/core/internal/FilesBaseTest.java +++ b/src/test/java/org/assertj/core/internal/FilesBaseTest.java @@ -35,6 +35,7 @@ import org.assertj.core.api.AssertionInfo; import org.assertj.core.util.diff.Delta; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; /** * Base class for testing {@link Files}, set up diff and failures attributes (which is why it is in @@ -46,6 +47,8 @@ public class FilesBaseTest { protected static final AssertionInfo INFO = someInfo(); + @TempDir + protected File tempDir; protected File actual; protected Failures failures; protected Files files; @@ -55,6 +58,7 @@ public class FilesBaseTest { protected BinaryDiff binaryDiff; protected NioFilesWrapper nioFilesWrapper; + @SuppressWarnings("unchecked") @BeforeEach public void setUp() { actual = mock(File.class); diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertHasExtension_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertHasExtension_Test.java index 88c7fc432b2..43838d94b5f 100644 --- a/src/test/java/org/assertj/core/internal/files/Files_assertHasExtension_Test.java +++ b/src/test/java/org/assertj/core/internal/files/Files_assertHasExtension_Test.java @@ -12,20 +12,21 @@ */ package org.assertj.core.internal.files; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNullPointerException; import static org.assertj.core.api.Assertions.catchThrowable; +import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.error.ShouldBeFile.shouldBeFile; import static org.assertj.core.error.ShouldHaveExtension.shouldHaveExtension; -import static org.assertj.core.test.TestData.someInfo; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; import static org.assertj.core.util.FailureMessages.actualIsNull; +import static org.assertj.core.util.Files.newFile; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import org.assertj.core.api.AssertionInfo; +import java.io.File; + import org.assertj.core.internal.FilesBaseTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * Tests for @@ -39,45 +40,65 @@ class Files_assertHasExtension_Test extends FilesBaseTest { private String expectedExtension = "java"; @Test - void should_throw_error_if_actual_is_null() { - assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> files.assertHasExtension(someInfo(), null, - expectedExtension)) - .withMessage(actualIsNull()); + void should_fail_if_actual_is_null() { + // GIVEN + File actual = null; + String expected = "txt"; + // WHEN + AssertionError error = expectAssertionError(() -> files.assertHasExtension(INFO, actual, expected)); + // THEN + then(error).hasMessage(actualIsNull()); } @Test - void should_throw_npe_if_extension_is_null() { - assertThatNullPointerException().isThrownBy(() -> files.assertHasExtension(someInfo(), actual, null)) - .withMessage("The expected extension should not be null."); + void should_fail_if_expected_extension_is_null() { + // GIVEN + File actual = new File("file.txt"); + String expected = null; + // WHEN + Throwable thrown = catchThrowable(() -> files.assertHasExtension(INFO, actual, expected)); + // THEN + then(thrown).isInstanceOf(NullPointerException.class) + .hasMessage("The expected extension should not be null."); } @Test void should_throw_error_if_actual_is_not_a_file() { - AssertionInfo info = someInfo(); - when(actual.isFile()).thenReturn(false); - - Throwable error = catchThrowable(() -> files.assertHasExtension(info, actual, expectedExtension)); - - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldBeFile(actual)); + // GIVEN + File actual = tempDir; + // WHEN + expectAssertionError(() -> files.assertHasExtension(INFO, actual, expectedExtension)); + // THEN + verify(failures).failure(INFO, shouldBeFile(actual)); } @Test void should_throw_error_if_actual_does_not_have_the_expected_extension() { - AssertionInfo info = someInfo(); - when(actual.isFile()).thenReturn(true); - when(actual.getName()).thenReturn("file.png"); - - Throwable error = catchThrowable(() -> files.assertHasExtension(info, actual, expectedExtension)); + // GIVEN + File actual = newFile(tempDir.getAbsolutePath() + "/file.png"); + // WHEN + expectAssertionError(() -> files.assertHasExtension(INFO, actual, expectedExtension)); + // THEN + verify(failures).failure(INFO, shouldHaveExtension(actual, "png", expectedExtension)); + } - assertThat(error).isInstanceOf(AssertionError.class); - verify(failures).failure(info, shouldHaveExtension(actual, "png", expectedExtension)); + @ParameterizedTest + @ValueSource(strings = { "file", "file." }) + void should_fail_if_actual_has_no_extension(String filename) { + // GIVEN + File actual = newFile(tempDir.getAbsolutePath() + "/" + filename); + String expected = "log"; + // WHEN + AssertionError error = expectAssertionError(() -> files.assertHasExtension(INFO, actual, expected)); + // THEN + then(error).hasMessage(shouldHaveExtension(actual, expected).create()); } @Test void should_pass_if_actual_has_expected_extension() { - when(actual.isFile()).thenReturn(true); - when(actual.getName()).thenReturn("file.java"); - files.assertHasExtension(someInfo(), actual, expectedExtension); + // GIVEN + File actual = newFile(tempDir.getAbsolutePath() + "/file.java"); + // WHEN/THEN + files.assertHasExtension(INFO, actual, expectedExtension); } } diff --git a/src/test/java/org/assertj/core/internal/files/Files_assertHasNoExtension_Test.java b/src/test/java/org/assertj/core/internal/files/Files_assertHasNoExtension_Test.java new file mode 100644 index 00000000000..1325c541e68 --- /dev/null +++ b/src/test/java/org/assertj/core/internal/files/Files_assertHasNoExtension_Test.java @@ -0,0 +1,82 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2021 the original author or authors. + */ +package org.assertj.core.internal.files; + +import static com.google.common.io.Files.touch; +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.error.ShouldBeFile.shouldBeFile; +import static org.assertj.core.error.ShouldHaveNoExtension.shouldHaveNoExtension; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; +import static org.assertj.core.util.FailureMessages.actualIsNull; + +import java.io.File; +import java.io.IOException; + +import org.assertj.core.internal.FilesBaseTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class Files_assertHasNoExtension_Test extends FilesBaseTest { + + @Test + void should_fail_if_actual_is_null() { + // GIVEN + File actual = null; + // WHEN + AssertionError error = expectAssertionError(() -> files.assertHasNoExtension(INFO, actual)); + // THEN + then(error).hasMessage(actualIsNull()); + } + + @Test + void should_fail_if_actual_does_not_exist() { + // GIVEN + File actual = new File("non-existent"); + // WHEN + AssertionError error = expectAssertionError(() -> files.assertHasNoExtension(INFO, actual)); + // THEN + then(error).hasMessage(shouldBeFile(actual).create()); + } + + @Test + void should_fail_if_actual_is_not_a_file() { + // GIVEN + File actual = tempDir; + // WHEN + AssertionError error = expectAssertionError(() -> files.assertHasNoExtension(INFO, actual)); + // THEN + then(error).hasMessage(shouldBeFile(actual).create()); + } + + @Test + void should_fail_if_actual_has_extension() { + // GIVEN + File actual = new File("src/test/resources/ascii.txt"); + // WHEN + AssertionError error = expectAssertionError(() -> files.assertHasNoExtension(INFO, actual)); + // THEN + then(error).hasMessage(shouldHaveNoExtension(actual, "txt").create()); + } + + @ParameterizedTest + @ValueSource(strings = { "file", "file." }) + void should_pass_if_actual_has_no_extension(String filename) throws IOException { + // GIVEN + File actual = new File(tempDir.getAbsolutePath() + "/" + filename); + touch(actual); + // WHEN/THEN + files.assertHasNoExtension(INFO, actual); + } + +} diff --git a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java index 83ba575ec9d..6958053d8e5 100644 --- a/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java +++ b/src/test/java/org/assertj/core/internal/paths/Paths_assertHasExtension_Test.java @@ -66,7 +66,7 @@ void should_fail_if_actual_is_not_a_regular_file() throws IOException { } @Test - void should_fail_if_expected_is_null() throws IOException { + void should_fail_if_expected_extension_is_null() throws IOException { // GIVEN Path actual = createFile(tempDir.resolve("file.txt")); String expected = null; From 8f8b742a20885a14e8b1af9418e7f219f084738e Mon Sep 17 00:00:00 2001 From: Stefano Cordio Date: Sun, 19 Sep 2021 19:20:11 +0200 Subject: [PATCH 123/123] [maven-release-plugin] prepare release assertj-core-3.21.0 --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e3f6daa78b5..0845b8eec6c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ org.assertj assertj-parent-pom 2.2.13 - + assertj-core - 3.21.0-SNAPSHOT + 3.21.0 jar AssertJ fluent assertions @@ -20,7 +20,7 @@ scm:git:git@github.com:assertj/assertj-core.git scm:git:git@github.com:assertj/assertj-core.git git@github.com:assertj/assertj-core - HEAD + assertj-core-3.21.0 github @@ -220,7 +220,7 @@ - + @@ -297,7 +297,7 @@ *:*:*:jar:compile - + [11,)