├── .github
└── workflows
│ ├── ci.yml
│ └── release.yml
├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
├── renovate.json
└── src
├── main
└── kotlin
│ └── in
│ └── rcard
│ └── assertj
│ └── arrowcore
│ ├── AbstractEitherAssert.kt
│ ├── AbstractNonEmptyListAssert.kt
│ ├── AbstractOptionAssert.kt
│ ├── AbstractRaiseAssert.kt
│ ├── EitherAssert.kt
│ ├── NonEmptyListAssert.kt
│ ├── OptionAssert.kt
│ ├── RaiseAssert.kt
│ └── errors
│ ├── EitherShouldBeLeft.kt
│ ├── EitherShouldBeRight.kt
│ ├── EitherShouldContain.kt
│ ├── EitherShouldContainInstanceOf.kt
│ ├── NonEmptyListShouldBeSingleElement.kt
│ ├── NonEmptyListShouldBeSorted.kt
│ ├── NonEmptyListShouldContain.kt
│ ├── NonEmptyListShouldContainOnly.kt
│ ├── NonEmptyListShouldHaveDuplicates.kt
│ ├── NonEmptyListShouldNotContain.kt
│ ├── OptionShouldBeEmpty.kt
│ ├── OptionShouldBePresent.kt
│ ├── OptionShouldContain.kt
│ ├── OptionShouldContainInstanceOf.kt
│ ├── RaiseShouldFailButSucceeds.kt
│ ├── RaiseShouldFailWith.kt
│ ├── RaiseShouldSucceedButFailed.kt
│ ├── RaiseShouldSucceedWith.kt
│ ├── RaiseShouldSucceedWithButFailed.kt
│ └── RaiseShouldThrowAnException.kt
└── test
└── kotlin
└── in
└── rcard
└── assertj
└── arrowcore
├── Dummy.kt
├── EitherAssert_asLeft_Test.kt
├── EitherAssert_asRight_Test.kt
├── EitherAssert_assertThat_Test.kt
├── EitherAssert_containsOnLeftInstanceOf_Test.kt
├── EitherAssert_containsOnLeft_Test.kt
├── EitherAssert_containsOnRightInstanceOf_Test.kt
├── EitherAssert_containsOnRight_Test.kt
├── EitherAssert_hasLeftValueSatisfying_Test.kt
├── EitherAssert_hasRightValueSatisfying_Test.kt
├── EitherAssert_isLeft_Test.kt
├── EitherAssert_isRight_Test.kt
├── NonEmptyListAssert_shouldBeSingleElement_Test.kt
├── NonEmptyListAssert_shouldBeSorted_Test.kt
├── NonEmptyListAssert_shouldContainAll_Test.kt
├── NonEmptyListAssert_shouldContainNoNulls_Test.kt
├── NonEmptyListAssert_shouldContainNull_Test.kt
├── NonEmptyListAssert_shouldContainOnlyNulls_Test.kt
├── NonEmptyListAssert_shouldContain_Test.kt
├── NonEmptyListAssert_shouldHaveDuplicates_Test.kt
├── OptionAssert_assertThat_Test.kt
├── OptionAssert_containsInstanceOf_Test.kt
├── OptionAssert_contains_Test.kt
├── OptionAssert_get_Test.kt
├── OptionAssert_hasValueSatisfying_Test.kt
├── OptionAssert_isDefined_Test.kt
├── OptionAssert_isEmpty_Test.kt
├── RaiseAssert_assertThatRaisedBy_Test.kt
├── RaiseAssert_assertThatThrownBy_Test.kt
├── RaiseAssert_assertThat_Test.kt
├── RaiseAssert_error_Test.kt
├── RaiseAssert_fails_Test.kt
├── RaiseAssert_raises_Test.kt
├── RaiseAssert_result_Test.kt
├── RaiseAssert_succeedsWith_Test.kt
└── RaiseAssert_suceeded_Test.kt
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: assertj-arrow-core
2 |
3 | on:
4 | push:
5 | branches:
6 | - '**'
7 | pull_request:
8 | branches: [ main ]
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v4
14 | - name: Set up JDK
15 | uses: actions/setup-java@v4
16 | with:
17 | java-version: '17'
18 | distribution: 'temurin'
19 | - name: Build with Maven
20 | run: mvn -B package --file pom.xml
21 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Publish package to the Maven Central Repository
2 | on:
3 | push:
4 | tags:
5 | - v*
6 | jobs:
7 | publish:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v4
11 | - name: Set up Java
12 | uses: actions/setup-java@v4
13 | with:
14 | java-version: '17'
15 | distribution: 'temurin'
16 | - name: Publish package
17 | env:
18 | JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_USERNAME }}
19 | JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.JRELEASER_MAVENCENTRAL_PASSWORD }}
20 | JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
21 | JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
22 | JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
23 | JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 | run: mvn -Prelease deploy jreleaser:deploy -DaltDeploymentRepository=local::file:./target/staging-deploy
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # Maven build directory
26 | target/
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | 
3 | 
4 | 
5 | [](https://javadoc.io/doc/in.rcard/assertj-arrow-core)
6 |
7 |
8 | # assertj-arrow-core
9 |
10 | This project provides a set of [AssertJ](https://assertj.github.io/doc/) assertions for
11 | the [Arrow](https://arrow-kt.io/) library. In detail, the project provides assertions for the following Arrow types:
12 |
13 | - [x] `Either`
14 | - [x] `Option`
15 | - [x] `Raise.() -> A`
16 | - [x] `NonEmptyList`
17 |
18 | Maybe you're asking yourself: "Why do we need AssertJ assertions for Arrow types?". The answer is simple: We often use
19 | Kotlin and Arrow Kt inside a Java project using Spring Boot. In this case, we already have AssertJ in the classpath as
20 | an assertion library. So, why not use it to assert Arrow types?
21 |
22 | ## Usage
23 |
24 | The library is available on Maven Central. To use it, add the following dependency to your `pom.xml` file:
25 |
26 | ```xml
27 |
28 |
29 | in.rcard
30 | assertj-arrow-core
31 | 2.0.0
32 | test
33 |
34 | ```
35 |
36 | Otherwise, if you're using Gradle, add the following dependency to your `build.gradle.kts` file:
37 |
38 | ```kotlin
39 | testImplementation("in.rcard:assertj-arrow-core:2.0.0")
40 | ```
41 |
42 | ## Assertions Guide
43 |
44 | This section describes the assertions provided by the `assertj-arrow-core` library.
45 |
46 | ### `Option`
47 |
48 | Use the `in.rcard.assertj.arrowcore.OptionAssert` class as an entry point to assert `Option` instances.
49 |
50 | | Assertions | Description |
51 | |----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
52 | | `isEmpty` | Verifies that the actual `Option` is empty. |
53 | | `contains` | Verifies that the actual `Option` contains the given value. |
54 | | `containsInstanceOf` | Verifies that the actual `Option` contains a value that is an instance of the argument. |
55 | | `get` | Verifies that the actual Option is not null and not empty and returns an Object assertion that allows chaining (object) assertions on the optional value. |
56 | | `isDefined` | Verifies that there is a value present in the actual `Option`. |
57 |
58 | ### `Either`
59 |
60 | Use the `in.rcard.assertj.arrowcore.EitherAssert` class as an entry point to assert `Either` instances.
61 |
62 | | Assertions | Description |
63 | |---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
64 | | `isRight` | Verifies that the actual `Either` is right. |
65 | | `isLeft` | Verifies that the actual `Either` is left. |
66 | | `containsOnRight` | Verifies that the actual `Either` is `Either.Right` and contains the given value. |
67 | | `containsRightInstanceOf` | Verifies that the actual right-sided `Either` contains a value that is an instance of the argument. |
68 | | `asRight` | Verifies that the actual `Either` is not `null` and contains a right-sided value and returns an `Object` assertion that allows chaining (object) assertions on the value. |
69 | | `containsOnLeft` | Verifies that the actual `Either` is `Either.Left` and contains the given value. |
70 | | `containsLeftInstanceOf` | Verifies that the actual left-sided `Either` contains a value that is an instance of the argument. |
71 | | `asLeft` | Verifies that the actual `Either` is not `null` and contains a left-sided value and returns an `Object` assertion that allows chaining (object) assertions on the value. |
72 |
73 | ### `Raise.() -> A`
74 |
75 | Use the `in.rcard.assertj.arrowcore.RaiseAssert` class as an entry point to assert `Raise.() -> A` instances. There
76 | are many different entry points, all of them available boh for regular and `suspend` functions:
77 |
78 | | Entry Point | Description |
79 | |----------------------|-----------------------------------------------------------------------------------------------------------------------------|
80 | | `assertThat` | Entry point to assert a `Raise.() -> A` instance. |
81 | | `assertThatThrownBy` | Verifies that the function in the `Raise` context throws an exception and let chaining assertion on the thrown exception |
82 | | `assertThatRaisedBy` | Verifies that the function in the `Raise` context raises a logic-typed error and let chaining assertion on the raised error |
83 |
84 | The available assertions are:
85 |
86 | | Assertions | Description |
87 | |----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
88 | | `succeedsWith` | Verifies that the function in the `Raise` context succeeds with the given value. |
89 | | `succeeds` | Verifies that the function in the `Raise` context succeeded. No check on the value returned by the function is performed. |
90 | | `raises` | Verifies that the function in the Raise context fails with the given error. |
91 | | `fails` | Verifies that the function in the Raise context fails, no matter the type of the logical error. |
92 | | `result` | Verifies that the actual function in the `Raise` context succeeds and returns an `Object` assertion that allows chaining (object) assertions on the returned value. |
93 | | `error` | Verifies that the actual function in the Raise context fails and returns an Object assertion that allows chaining (object) assertions on the raised error. |
94 |
95 | ### `NonEmptyList`
96 |
97 | Use the `in.rcard.assertj.arrowcore.NonEmptyListAssert` class as an entry point to assert `NonEmptyList` instances.
98 |
99 | | Assertions | Description |
100 | |-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
101 | | `shouldContain` | Verifies that the actual `NonEmptyList` contains the expected element. |
102 | | `shouldContainAll` | Verifies that the actual `NonEmptyList` contains all the expected elements. |
103 | | `shouldContainNoNulls` | Verifies that the actual `NonEmptyList` does not contain null. |
104 | | `shouldContainOnlyNulls` | Verifies that the actual `NonEmptyList` contains only null. |
105 | | `shouldContainNull` | Verifies that the actual `NonEmptyList` contains null. |
106 | | `shouldHaveDuplicates` | Verifies that the actual `NonEmptyList` contains at least one duplicate. |
107 | | `shouldBeSingleElement` | Verifies that the actual `NonEmptyList` has a single element which is expected element. |
108 | | `shouldBeSorted` | Verifies that the actual `NonEmptyList` is sorted. |
109 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | 4.0.0
6 |
7 | in.rcard
8 | assertj-arrow-core
9 | 2.0.0
10 |
11 | AssertJ fluent assertions for Kotlin Arrow Core library
12 | Rich and fluent assertions for testing Kotlin Arrow Core types
13 | 2023
14 |
15 |
16 | scm:git:git://github.com/rcardin/assertj-arrow-core.git
17 | scm:git:ssh://github.com:rcardin/assertj-arrow-core.git
18 | http://github.com/rcardin/assertj-arrow-core/tree/master
19 |
20 |
21 |
22 |
23 | MIT License
24 | https://opensource.org/licenses/MIT
25 |
26 |
27 |
28 | 17
29 | 3.27.5
30 | 2.2.20
31 | 2.1.2
32 | 5.13.4
33 | 1.9.0
34 | 3.5.2
35 | 1.9.0
36 |
37 |
38 | https://github.com/rcardin/assertj-arrow-core
39 |
40 |
41 |
42 | Riccardo Cardin
43 | https://github.com/rcardin
44 | rcardin
45 |
46 |
47 |
48 |
49 | github
50 | https://github.com/rcardin/assertj-arrow-core/issues
51 |
52 |
53 |
54 |
55 | org.assertj
56 | assertj-core
57 | ${assertj-core.version}
58 |
59 |
60 | org.jetbrains.kotlin
61 | kotlin-stdlib
62 | ${kotlin-stdlib.version}
63 |
64 |
65 | io.arrow-kt
66 | arrow-core
67 | ${arrow-core.version}
68 | pom
69 |
70 |
71 | org.junit.jupiter
72 | junit-jupiter-api
73 | ${junit-jupiter.version}
74 | test
75 |
76 |
77 | org.junit.jupiter
78 | junit-jupiter-engine
79 | ${junit-jupiter.version}
80 | test
81 |
82 |
83 | org.jetbrains.kotlin
84 | kotlin-test
85 | ${kotlin-stdlib.version}
86 | test
87 |
88 |
89 | org.jetbrains.kotlinx
90 | kotlinx-coroutines-test
91 | ${kotlinx-coroutines-test.version}
92 | pom
93 | test
94 |
95 |
96 |
97 |
98 | ${project.basedir}/src/main/kotlin
99 | ${project.basedir}/src/test/kotlin
100 |
101 |
102 |
103 |
104 | org.apache.maven.plugins
105 | maven-deploy-plugin
106 | 3.0.0
107 |
108 |
109 | org.apache.maven.plugins
110 | maven-compiler-plugin
111 | 3.10.1
112 |
113 |
114 | org.apache.maven.plugins
115 | maven-javadoc-plugin
116 | 3.2.0
117 |
118 |
119 | org.apache.maven.plugins
120 | maven-source-plugin
121 | 3.2.1
122 |
123 |
124 |
125 |
126 |
127 |
128 | org.jetbrains.kotlin
129 | kotlin-maven-plugin
130 | ${kotlin-stdlib.version}
131 |
132 |
133 | compile
134 |
135 | compile
136 |
137 |
138 |
139 | test-compile
140 |
141 | test-compile
142 |
143 |
144 |
145 |
146 |
147 | -Xcontext-receivers
148 |
149 |
150 |
151 |
152 | org.apache.maven.plugins
153 | maven-compiler-plugin
154 |
155 | 17
156 | 17
157 | ${project.build.sourceEncoding}
158 |
159 |
160 |
161 |
162 | org.apache.maven.plugins
163 | maven-surefire-plugin
164 | ${maven-surefire-plugin.version}
165 |
166 |
167 |
168 |
169 |
170 | release
171 |
172 | local::file:./target/staging-deploy
173 |
174 |
175 |
176 |
177 | org.jetbrains.dokka
178 | dokka-maven-plugin
179 | ${dokka-maven-plugin.version}
180 |
181 |
182 | install
183 |
184 | javadocJar
185 |
186 |
187 |
188 |
189 |
190 | org.apache.maven.plugins
191 | maven-source-plugin
192 | 3.2.1
193 |
194 |
195 | attach-source
196 |
197 | jar
198 |
199 |
200 |
201 |
202 |
203 | org.jreleaser
204 | jreleaser-maven-plugin
205 | 1.19.0
206 | false
207 |
208 |
209 |
210 | ALWAYS
211 | true
212 |
213 |
214 |
215 |
216 |
217 | ALWAYS
218 | https://central.sonatype.com/api/v1/publisher
219 | target/staging-deploy
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "config:recommended"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/AbstractEitherAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeLeft.Companion.shouldBeLeft
5 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
6 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContain.Companion.shouldContainOnLeft
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContain.Companion.shouldContainOnRight
8 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContainInstanceOf.Companion.shouldContainOnLeftInstanceOf
9 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContainInstanceOf.Companion.shouldContainOnRightInstanceOf
10 | import org.assertj.core.api.AbstractObjectAssert
11 | import org.assertj.core.api.Assertions
12 | import org.assertj.core.internal.ComparisonStrategy
13 | import org.assertj.core.internal.StandardComparisonStrategy
14 |
15 | /**
16 | * Assertions for [Either].
17 | *
18 | * @param SELF the "self" type of this assertion class.
19 | * @param LEFT type of the left value contained in the [Either].
20 | * @param RIGHT type of the right value contained in the [Either].
21 | * @author Riccardo Cardin
22 | * @author Simon Frost
23 | *
24 | * @since 0.0.1
25 | */
26 | abstract class AbstractEitherAssert<
27 | SELF : AbstractEitherAssert,
28 | LEFT : Any?,
29 | RIGHT : Any?,
30 | > internal constructor(
31 | either: Either?,
32 | ) : AbstractObjectAssert>(either, AbstractEitherAssert::class.java) {
33 | private val comparisonStrategy: ComparisonStrategy = StandardComparisonStrategy.instance()
34 |
35 | /**
36 | * Verifies that the actual [Either] is right.
37 | *
38 | * @return this assertion object.
39 | */
40 | fun isRight(): SELF {
41 | isNotNull
42 | assertIsRight()
43 | return myself
44 | }
45 |
46 | /**
47 | * Verifies that the actual [Either] is left.
48 | *
49 | * @return this assertion object.
50 | */
51 | fun isLeft(): SELF {
52 | assertIsLeft()
53 | return myself
54 | }
55 |
56 | /**
57 | * Verifies that the actual [Either] is [Either.Right] and contains the given value.
58 | *
59 | * @param expectedValue the expected value inside the [Either].
60 | * @return this assertion object.
61 | */
62 | fun containsOnRight(expectedValue: RIGHT): SELF {
63 | assertIsRight()
64 | actual.onRight { right ->
65 | if (!comparisonStrategy.areEqual(right, expectedValue)) {
66 | throwAssertionError(shouldContainOnRight(actual, expectedValue))
67 | }
68 | }
69 | return myself
70 | }
71 |
72 | /**
73 | * Verifies that the actual right-sided [Either] contains a value that is an
74 | * instance of the argument.
75 | *
76 | * @param expectedClass the expected class of the value inside the right-sided [Either].
77 | * @return this assertion object.
78 | */
79 | fun containsRightInstanceOf(expectedClass: Class<*>): SELF {
80 | assertIsRight()
81 | actual.onRight { right ->
82 | if (!expectedClass.isInstance(right)) {
83 | throwAssertionError(shouldContainOnRightInstanceOf(actual, expectedClass))
84 | }
85 | }
86 | return myself
87 | }
88 |
89 | /**
90 | * Verifies that the actual [Either] contains a right-sided value and gives this value to the given
91 | * consumer for further assertions. Should be used as a way of deeper asserting on the
92 | * containing object, as further requirement(s) for the value.
93 | *
94 | * @param requirement the consumer that will accept the right-sided value for deep asserting.
95 | * @return this assertion object.
96 | *
97 | * @since 0.1.0
98 | */
99 | @Deprecated(
100 | "hasRightValueSatisfying can be replaced using the method asRight() and chaining assertions on the returned object.",
101 | ReplaceWith("asRight().satisfies(requirement)"),
102 | )
103 | fun hasRightValueSatisfying(requirement: (RIGHT) -> Unit): SELF {
104 | assertIsRight()
105 | actual.onRight { requirement(it) }
106 | return myself
107 | }
108 |
109 | /**
110 | * Verifies that the actual [Either] is not null and contains a right-sided value and returns an Object assertion
111 | * that allows chaining (object) assertions on the value.
112 | *
113 | * @since 0.2.0
114 | * @return a new [AbstractObjectAssert] for assertions chaining on the right-sided value of the [Either].
115 | */
116 | fun asRight(): AbstractObjectAssert<*, RIGHT> {
117 | assertIsRight()
118 | return Assertions.assertThat(actual.getOrNull())
119 | }
120 |
121 | private fun assertIsRight() {
122 | isNotNull
123 | if (!actual.isRight()) {
124 | throwAssertionError(shouldBeRight(actual))
125 | }
126 | }
127 |
128 | /**
129 | * Verifies that the actual [Either] is [Either.Left] and contains the given value.
130 | *
131 | * @param expectedValue the expected value inside the [Either].
132 | * @return this assertion object.
133 | */
134 | fun containsOnLeft(expectedValue: LEFT): SELF {
135 | assertIsLeft()
136 | actual.onLeft { left ->
137 | if (!comparisonStrategy.areEqual(left, expectedValue)) {
138 | throwAssertionError(shouldContainOnLeft(actual, expectedValue))
139 | }
140 | }
141 | return myself
142 | }
143 |
144 | /**
145 | * Verifies that the actual left-sided [Either] contains a value that is an
146 | * instance of the argument.
147 | *
148 | * @param expectedClass the expected class of the value inside the left-sided [Either].
149 | * @return this assertion object.
150 | */
151 | fun containsLeftInstanceOf(expectedClass: Class<*>): SELF {
152 | assertIsLeft()
153 | actual.onLeft { left ->
154 | if (!expectedClass.isInstance(left)) {
155 | throwAssertionError(shouldContainOnLeftInstanceOf(actual, expectedClass))
156 | }
157 | }
158 | return myself
159 | }
160 |
161 | /**
162 | * Verifies that the actual [Either] contains a left-sided value and gives this value to the given
163 | * consumer for further assertions. Should be used as a way of deeper asserting on the
164 | * containing object, as further requirement(s) for the value.
165 | *
166 | * @param requirement the consumer that will accept the left-sided value for deep asserting.
167 | * @return this assertion object.
168 | * @since 0.1.0
169 | */
170 | @Deprecated(
171 | "hasLeftValueSatisfying can be replaced using the method asLeft() and chaining assertions on the returned object.",
172 | ReplaceWith("asLeft().satisfies(requirement)"),
173 | )
174 | fun hasLeftValueSatisfying(requirement: (LEFT) -> Unit): SELF {
175 | assertIsLeft()
176 | actual.onLeft { requirement(it) }
177 | return myself
178 | }
179 |
180 | /**
181 | * Verifies that the actual [Either] is not null and contains a left-sided value and returns an Object assertion
182 | * that allows chaining (object) assertions on the value.
183 | *
184 | * @since 0.2.0
185 | * @return a new [AbstractObjectAssert] for assertions chaining on the left-sided value of the [Either].
186 | */
187 | fun asLeft(): AbstractObjectAssert<*, LEFT> {
188 | assertIsLeft()
189 | return Assertions.assertThat(actual.leftOrNull())
190 | }
191 |
192 | private fun assertIsLeft() {
193 | isNotNull
194 | if (!actual.isLeft()) {
195 | throwAssertionError(shouldBeLeft(actual))
196 | }
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/AbstractNonEmptyListAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldNotContain.Companion.shouldNotContain
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldContain.Companion.shouldContain
6 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldContainOnly.Companion.shouldContainOnly
7 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldBeSingleElement.Companion.shouldBeSingleElement
8 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldHaveDuplicates.Companion.shouldHaveDuplicates
9 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldBeSorted.Companion.shouldBeSorted
10 | import org.assertj.core.api.AbstractAssert
11 | import org.assertj.core.api.AssertFactory
12 | import org.assertj.core.api.FactoryBasedNavigableListAssert
13 | import org.assertj.core.internal.StandardComparisonStrategy
14 |
15 |
16 | /**
17 | * Assertions for [NonEmptyList].
18 | *
19 | * @param SELF the "self" type of this assertion class.
20 | * @param ELEMENT type of the element contained in the [NonEmptyList].
21 | * @param ELEMENT_ASSERT type used for assertion of element contained in the [NonEmptyList].
22 | * @author Hamza Faraji
23 | *
24 | * @since 1.2.0
25 | */
26 | open class AbstractNonEmptyListAssert<
27 | SELF : AbstractNonEmptyListAssert,
28 | ELEMENT : Any?,
29 | ELEMENT_ASSERT : AbstractAssert
30 | > internal constructor(
31 | list: NonEmptyList?,
32 | assertFactory: AssertFactory?,
33 | ) : FactoryBasedNavigableListAssert, ELEMENT, ELEMENT_ASSERT>(
34 | list,
35 | AbstractNonEmptyListAssert::class.java,
36 | assertFactory
37 | ) {
38 | private val comparisonStrategy: StandardComparisonStrategy = StandardComparisonStrategy.instance()
39 |
40 | /**
41 | * Verifies that the actual [NonEmptyList] contains the expected element
42 | *
43 | * @return the assertion object
44 | */
45 | fun shouldContain(expectedValue: ELEMENT): SELF {
46 | isNotNull
47 | assertContains(expectedValue)
48 | return myself
49 | }
50 |
51 | /**
52 | * Verifies that the actual [NonEmptyList] contains all the expected elements
53 | *
54 | * @return the assertion object
55 | */
56 | fun shouldContainAll(vararg elements: ELEMENT): SELF {
57 | isNotNull
58 | if (!actual.containsAll(elements.toList())) {
59 | throwAssertionError(shouldContain(actual, elements))
60 | }
61 | return myself
62 | }
63 |
64 | /**
65 | * Verifies that the actual [NonEmptyList] contains null
66 | *
67 | * @return the assertion object
68 | */
69 | fun shouldContainNull(): SELF {
70 | isNotNull
71 | assertContains(null)
72 | return myself
73 | }
74 |
75 | /**
76 | * Verifies that the actual [NonEmptyList] does not contain null
77 | *
78 | * @return the assertion object
79 | */
80 | fun shouldContainNoNulls(): SELF {
81 | isNotNull
82 | if (actual.contains(null)) {
83 | throwAssertionError(shouldNotContain(actual, null))
84 | }
85 | return myself
86 | }
87 |
88 | /**
89 | * Verifies that the actual [NonEmptyList] contains only null
90 | *
91 | * @return the assertion object
92 | */
93 | fun shouldContainOnlyNulls(): SELF {
94 | isNotNull
95 | if (!actual.none { it != null }) {
96 | throwAssertionError(shouldContainOnly(actual, null))
97 | }
98 | return myself
99 | }
100 |
101 | /**
102 | * Verifies that the actual [NonEmptyList] contains at least one duplicate
103 | *
104 | * @return the assertion object
105 | */
106 | fun shouldHaveDuplicates(): SELF {
107 | isNotNull
108 | if (actual.distinct().size == actual.size) {
109 | throwAssertionError(shouldHaveDuplicates(actual))
110 | }
111 | return myself
112 | }
113 |
114 | /**
115 | * Verifies that the actual [NonEmptyList] has a single element which is expected element
116 | *
117 | * @return the assertion object
118 | */
119 | fun shouldBeSingleElement(expectedValue: ELEMENT): SELF {
120 | isNotNull
121 | if (actual.size != 1 || !comparisonStrategy.areEqual(actual.first(), expectedValue)) {
122 | throwAssertionError(shouldBeSingleElement(actual, expectedValue))
123 | }
124 | return myself
125 | }
126 |
127 | /**
128 | * Verifies that the actual [NonEmptyList] is sorted
129 | *
130 | * @return the assertion object
131 | */
132 | fun shouldBeSorted(): SELF {
133 | isNotNull
134 | if (actual.sortedWith { first, second ->
135 | when {
136 | comparisonStrategy.areEqual(first, second) -> 0
137 | comparisonStrategy.isLessThanOrEqualTo(first, second) -> -1
138 | else -> 1
139 | }
140 | } != actual) {
141 | throwAssertionError(shouldBeSorted(actual))
142 | }
143 |
144 | return myself
145 | }
146 |
147 | private fun assertContains(expectedValue: ELEMENT?) {
148 | isNotNull
149 | if (!actual.contains(expectedValue)) {
150 | throwAssertionError(shouldContain(actual, expectedValue))
151 | }
152 | }
153 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/AbstractOptionAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Option
4 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBeEmpty.Companion.shouldBeEmpty
5 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBePresent.Companion.shouldBePresent
6 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldContain.Companion.shouldContain
7 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldContainInstanceOf.Companion.shouldContainInstanceOf
8 | import org.assertj.core.api.AbstractObjectAssert
9 | import org.assertj.core.api.Assertions
10 | import org.assertj.core.internal.ComparisonStrategy
11 | import org.assertj.core.internal.StandardComparisonStrategy
12 |
13 | /**
14 | * Assertions for [Option].
15 | *
16 | * @param SELF the "self" type of this assertion class.
17 | * @param VALUE type of the value contained in the [Option].
18 | * @author Riccardo Cardin
19 | * @author Simon Frost
20 | * @since 0.0.1
21 | */
22 | abstract class AbstractOptionAssert<
23 | SELF : AbstractOptionAssert, VALUE : Any,
24 | > internal constructor(
25 | option: Option?,
26 | ) : AbstractObjectAssert>(option, AbstractOptionAssert::class.java) {
27 |
28 | private val comparisonStrategy: ComparisonStrategy = StandardComparisonStrategy.instance()
29 |
30 | /**
31 | * Verifies that the actual [Option] is empty.
32 | *
33 | * @return this assertion object.
34 | */
35 | fun isEmpty(): SELF {
36 | isNotNull
37 | if (actual.isSome()) throwAssertionError(shouldBeEmpty(actual))
38 | return myself
39 | }
40 |
41 | /**
42 | * Verifies that the actual [Option] contains the given value.
43 | *
44 | * @param expectedValue the expected value inside the [Option].
45 | * @return this assertion object.
46 | */
47 | fun contains(expectedValue: VALUE): SELF {
48 | isNotNull
49 | actual.fold(
50 | { throwAssertionError(shouldContain(actual, expectedValue)) },
51 | { actualValue ->
52 | if (!comparisonStrategy.areEqual(actualValue, expectedValue)) {
53 | throwAssertionError(shouldContain(actual, expectedValue))
54 | }
55 | },
56 | )
57 | return myself
58 | }
59 |
60 | /**
61 | * Verifies that the actual [Option] contains a value that is an instance of the argument.
62 | *
63 | * @param expectedClass the expected class of the value inside the [Option].
64 | * @return this assertion object.
65 | */
66 | fun containsInstanceOf(expectedClass: Class<*>): SELF {
67 | assertValueIsPresent()
68 | actual.onSome { value ->
69 | if (!expectedClass.isInstance(value)) {
70 | throwAssertionError(
71 | shouldContainInstanceOf(
72 | actual,
73 | expectedClass,
74 | ),
75 | )
76 | }
77 | }
78 | return myself
79 | }
80 |
81 | /**
82 | * Verifies that the actual [Option] contains a value and gives this value to the given
83 | * consumer for further assertions. Should be used as a way of deeper asserting on the
84 | * containing object, as further requirement(s) for the value.
85 | *
86 | * @param requirement to further assert on the object contained inside the [Option].
87 | * @return this assertion object.
88 | * @since 0.1.0
89 | */
90 | @Deprecated(
91 | "hasValueSatisfying can be replaced using the method get() and chaining assertions on the returned object.",
92 | ReplaceWith("get().satisfies(requirement)"),
93 | )
94 | fun hasValueSatisfying(requirement: (VALUE) -> Unit): SELF {
95 | assertValueIsPresent()
96 | actual.onSome { requirement(it) }
97 | return myself
98 | }
99 |
100 | /**
101 | * Verifies that the actual [Option] is not null and not empty and returns an Object assertion that allows
102 | * chaining (object) assertions on the optional value.
103 | *
104 | * @since 0.2.0
105 | * @return a new [AbstractObjectAssert] for assertions chaining on the value of the [Option].
106 | */
107 | fun get(): AbstractObjectAssert<*, VALUE> {
108 | isDefined()
109 | return Assertions.assertThat(actual.getOrNull())
110 | }
111 |
112 | /**
113 | * Verifies that there is a value present in the actual [Option].
114 | *
115 | * @return this assertion object.
116 | */
117 | fun isDefined(): SELF {
118 | assertValueIsPresent()
119 | return myself
120 | }
121 |
122 | private fun assertValueIsPresent() {
123 | isNotNull
124 | if (actual.isNone()) throwAssertionError(shouldBePresent())
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/AbstractRaiseAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.raise.Raise
4 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailButSucceedsWith
5 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailWithButSucceedsWith
6 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailWith.Companion.shouldFailWith
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedButFailed.Companion.shouldSucceedButFailed
8 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedWith.Companion.shouldSucceedWith
9 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedWithButFailed.Companion.shouldSucceedWithButFailed
10 | import org.assertj.core.api.AbstractAssert
11 | import org.assertj.core.api.AbstractObjectAssert
12 | import org.assertj.core.api.Assertions
13 | import org.assertj.core.internal.ComparisonStrategy
14 | import org.assertj.core.internal.StandardComparisonStrategy
15 |
16 | /**
17 | * Assertions for functions within a [Raise] context.
18 | *
19 | * @param VALUE type of the value returned by the function.
20 | * @param ERROR type of the logical error raised by the function.
21 | * @author Riccardo Cardin
22 | * @since 0.2.0
23 | */
24 | abstract class AbstractRaiseAssert<
25 | SELF : AbstractRaiseAssert,
26 | ERROR : Any?,
27 | VALUE : Any?,
28 | > internal constructor(
29 | raiseResult: RaiseResult,
30 | ) : AbstractAssert<
31 | SELF,
32 | RaiseResult,
33 | >(raiseResult, AbstractRaiseAssert::class.java) {
34 | private val comparisonStrategy: ComparisonStrategy = StandardComparisonStrategy.instance()
35 |
36 | /**
37 | * Verifies that the function in the [Raise] context succeeds with the given value.
38 | * @param expectedValue the expected value returned by the function.
39 | */
40 | fun succeedsWith(expectedValue: VALUE) =
41 | when (actual) {
42 | is RaiseResult.Failure -> {
43 | throwAssertionError(
44 | shouldSucceedWithButFailed(expectedValue, (actual as RaiseResult.Failure).error),
45 | )
46 | }
47 |
48 | is RaiseResult.FailureWithException -> {
49 | throw (actual as RaiseResult.FailureWithException).exception
50 | }
51 |
52 | is RaiseResult.Success -> {
53 | val actualValue = (actual as RaiseResult.Success).value
54 | if (!comparisonStrategy.areEqual(actualValue, expectedValue)) {
55 | throwAssertionError(shouldSucceedWith(expectedValue, actualValue))
56 | } else {
57 | // Nothing to do
58 | }
59 | }
60 | }
61 |
62 | /**
63 | * Verifies that the function in the [Raise] context succeeded. No check on the value returned by the function is
64 | * performed.
65 | *
66 | * @see succeedsWith
67 | */
68 | fun succeeds() =
69 | when (actual) {
70 | is RaiseResult.Failure ->
71 | throwAssertionError(
72 | shouldSucceedButFailed((actual as RaiseResult.Failure).error),
73 | )
74 |
75 | is RaiseResult.FailureWithException -> {
76 | throw (actual as RaiseResult.FailureWithException).exception
77 | }
78 |
79 | is RaiseResult.Success -> {
80 | // Nothing to do
81 | }
82 | }
83 |
84 | /**
85 | * Verifies that the function in the [Raise] context fails with the given error.
86 | * @param expectedError the expected error raised by the function.
87 | */
88 | fun raises(expectedError: ERROR) =
89 | when (actual) {
90 | is RaiseResult.Failure -> {
91 | val actualError = (actual as RaiseResult.Failure).error
92 | if (!comparisonStrategy.areEqual(actualError, expectedError)) {
93 | throwAssertionError(shouldFailWith(expectedError, actualError))
94 | } else {
95 | // Nothing to do
96 | }
97 | }
98 |
99 | is RaiseResult.FailureWithException -> {
100 | throw (actual as RaiseResult.FailureWithException).exception
101 | }
102 |
103 | is RaiseResult.Success -> {
104 | throwAssertionError(
105 | shouldFailWithButSucceedsWith(expectedError, (actual as RaiseResult.Success).value),
106 | )
107 | }
108 | }
109 |
110 | /**
111 | * Verifies that the function in the [Raise] context fails, no matter the type of the logical error.
112 | *
113 | * @see raises
114 | */
115 | fun fails() =
116 | when (actual) {
117 | is RaiseResult.Failure -> {
118 | // Nothing to do
119 | }
120 |
121 | is RaiseResult.FailureWithException -> {
122 | throw (actual as RaiseResult.FailureWithException).exception
123 | }
124 |
125 | is RaiseResult.Success ->
126 | throwAssertionError(
127 | shouldFailButSucceedsWith((actual as RaiseResult.Success).value),
128 | )
129 | }
130 |
131 | /**
132 | * Verifies that the actual function in the [Raise] context succeeds and returns an Object assertion
133 | * that allows chaining (object) assertions on the returned value.
134 | *
135 | * @since 1.1.0
136 | * @return a new [AbstractObjectAssert] for assertions chaining on the result value of the function
137 | * in the [Raise] context.
138 | */
139 | fun result(): AbstractObjectAssert<*, VALUE> {
140 | succeeds()
141 | return Assertions.assertThat((actual as RaiseResult.Success).value)
142 | }
143 |
144 | /**
145 | * Verifies that the actual function in the [Raise] context fails and returns an Object assertion
146 | * that allows chaining (object) assertions on the raised error.
147 | *
148 | * @since 1.1.0
149 | * @return a new [AbstractObjectAssert] for assertions chaining on the raised error of the function
150 | * in the [Raise] context.
151 | */
152 | fun error(): AbstractObjectAssert<*, ERROR> {
153 | fails()
154 | return Assertions.assertThat((actual as RaiseResult.Failure).error)
155 | }
156 | }
157 |
158 | sealed interface RaiseResult {
159 | data class Success(
160 | val value: VALUE,
161 | ) : RaiseResult
162 |
163 | data class Failure(
164 | val error: ERROR,
165 | ) : RaiseResult
166 |
167 | data class FailureWithException(
168 | val exception: Throwable,
169 | ) : RaiseResult
170 | }
171 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/EitherAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 |
5 | /**
6 | * Assertions for [Either].
7 | *
8 | * @param LEFT type of the value on the left contained in the [Either].
9 | * @param RIGHT type of the value on the right contained in the [Either].
10 | * @author Riccardo Cardin
11 | * @since 0.0.1
12 | */
13 | class EitherAssert private constructor(either: Either?) :
14 | AbstractEitherAssert, LEFT, RIGHT>(either) {
15 | companion object {
16 | fun assertThat(actual: Either?): EitherAssert =
17 | EitherAssert(actual)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.api.AssertFactory
5 | import org.assertj.core.api.ObjectAssert
6 |
7 | /**
8 | * Assertions for [NonEmptyList].
9 | *
10 | * @param ELEMENT type of the element contained in the [NonEmptyList].
11 | * @author Hamza Faraji
12 | *
13 | * @since 1.2.0
14 | */
15 | class NonEmptyListAssert private constructor(nel: NonEmptyList?) :
16 | AbstractNonEmptyListAssert, ELEMENT, ObjectAssert>(
17 | nel,
18 | AssertFactory { actual: ELEMENT -> ObjectAssert(actual) }
19 | ) {
20 | companion object {
21 | fun assertThat(list: NonEmptyList?): NonEmptyListAssert =
22 | NonEmptyListAssert(list)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/OptionAssert.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Option
4 |
5 | /**
6 | * Assertions for [Option].
7 | *
8 | * @param VALUE type of the value contained in the [Option].
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | class OptionAssert private constructor(option: Option?) :
13 | AbstractOptionAssert, VALUE>(option) {
14 | companion object {
15 | fun assertThat(option: Option?): OptionAssert =
16 | OptionAssert(option)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/RaiseAssert.kt:
--------------------------------------------------------------------------------
1 | @file:OptIn(ExperimentalTypeInference::class)
2 |
3 | package `in`.rcard.assertj.arrowcore
4 |
5 | import arrow.core.raise.Raise
6 | import arrow.core.raise.fold
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailButSucceedsWith
8 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldThrowAnException.Companion.shouldThrowAnException
9 | import org.assertj.core.api.AbstractObjectAssert
10 | import org.assertj.core.api.AbstractThrowableAssert
11 | import org.assertj.core.api.Assertions
12 | import org.assertj.core.api.Fail
13 | import org.assertj.core.internal.Failures
14 | import kotlin.experimental.ExperimentalTypeInference
15 |
16 | /**
17 | * Assertions for functions within a [Raise] context.
18 | *
19 | * @param VALUE type of the value returned by the function.
20 | * @param ERROR type of the logical error raised by the function.
21 | * @author Riccardo Cardin
22 | *
23 | * @since 0.2.0
24 | */
25 | class RaiseAssert(
26 | raiseResult: RaiseResult,
27 | ) : AbstractRaiseAssert, ERROR, VALUE>(raiseResult) {
28 | companion object {
29 | inline fun assertThat(
30 | @BuilderInference lambda: Raise.() -> VALUE,
31 | ): RaiseAssert {
32 | val raiseResult =
33 | fold(
34 | block = lambda,
35 | catch = { throwable -> RaiseResult.FailureWithException(throwable) },
36 | recover = { error -> RaiseResult.Failure(error) },
37 | transform = { value -> RaiseResult.Success(value) },
38 | )
39 | return RaiseAssert(raiseResult)
40 | }
41 |
42 | /**
43 | * Verifies that the function in the [Raise] context throws an exception.
44 | * ### Example:
45 | * ```kotlin
46 | * val throwsException: Raise.() -> Int = {
47 | * throw RuntimeException("AN EXCEPTION")
48 | * }
49 | * assertThatThrownBy { throwsException() }
50 | * .isInstanceOf(RuntimeException::class.java)
51 | * .hasMessage("AN EXCEPTION")
52 | * ```
53 | *
54 | * @param shouldRaiseThrowable the function to be executed in the [Raise] context.
55 | * @return the [AbstractThrowableAssert] to be used to verify the exception.
56 | */
57 | inline fun assertThatThrownBy(
58 | @BuilderInference shouldRaiseThrowable: Raise.() -> VALUE,
59 | ): AbstractThrowableAssert<*, out Throwable> {
60 | val throwable: Throwable? =
61 | fold(
62 | block = shouldRaiseThrowable,
63 | recover = { null },
64 | transform = { null },
65 | catch = { exception -> exception },
66 | )
67 |
68 | @Suppress("KotlinConstantConditions")
69 | return throwable?.let { return Assertions.assertThat(throwable) } ?: throw Failures
70 | .instance()
71 | .failure(Assertions.assertThat(throwable).writableAssertionInfo, shouldThrowAnException())
72 | }
73 |
74 | /**
75 | * Verifies that the function in the [Raise] context raises an error.
76 | * ### Example:
77 | * ```kotlin
78 | * val raisesError: Raise.() -> Int = { raise("LOGICAL ERROR") }
79 | * assertThatRaisedBy { raisesError() }.isEqualTo("LOGICAL ERROR")
80 | * ```
81 | * @param shouldRaiseError the function to be executed in the [Raise] context.
82 | * @return the [AbstractObjectAssert] to be used to verify the error.
83 | */
84 | inline fun assertThatRaisedBy(
85 | @BuilderInference shouldRaiseError: Raise.() -> VALUE,
86 | ): AbstractObjectAssert<*, out ERROR> {
87 | val error =
88 | fold(
89 | block = shouldRaiseError,
90 | recover = { error -> error },
91 | transform = { value ->
92 | Fail.fail(
93 | shouldFailButSucceedsWith(value).create(),
94 | )
95 | },
96 | )
97 | return Assertions.assertThat(error)
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/EitherShouldBeLeft.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Either
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when an [Either] should be left.
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class EitherShouldBeLeft private constructor(actual: Either<*, *>) :
13 | BasicErrorMessageFactory("%nExpecting an Either to be left but was <$actual>.") {
14 | companion object {
15 | internal fun shouldBeLeft(actual: Either<*, *>): EitherShouldBeLeft = EitherShouldBeLeft(actual)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/EitherShouldBeRight.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Either
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when an [Either] should be right.
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class EitherShouldBeRight private constructor(actual: Either<*, *>) :
13 | BasicErrorMessageFactory("%nExpecting an Either to be right but was <$actual>.") {
14 | companion object {
15 | internal fun shouldBeRight(actual: Either<*, *>): EitherShouldBeRight = EitherShouldBeRight(actual)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/EitherShouldContain.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Either
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when an [Either] should contain a specific value.
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class EitherShouldContain private constructor(message: String, actual: Either, expected: Any?) :
13 | BasicErrorMessageFactory(message, actual, expected) {
14 |
15 | companion object {
16 |
17 | private const val EXPECTING_TO_CONTAIN_ON_RIGHT =
18 | "%nExpecting:%n <%s>%nto contain:%n <%s> on the [RIGHT]%nbut did not."
19 | private const val EXPECTING_TO_CONTAIN_ON_LEFT =
20 | "%nExpecting:%n <%s>%nto contain:%n <%s> on the [LEFT]%nbut did not."
21 |
22 | /**
23 | * Indicates that the provided [Either] does not contain the provided argument as right value.
24 | *
25 | * @param actual the [Either] which contains a value.
26 | * @param expectedValue the value we expect to be in the provided [Either] on the right side.
27 | * @param LEFT the type of the value contained in the [Either] on the left side.
28 | * @param RIGHT the type of the value contained in the [Either] on the right side.
29 | * @return an error message factory
30 | */
31 | internal fun shouldContainOnRight(
32 | actual: Either,
33 | expectedValue: RIGHT,
34 | ): EitherShouldContain = EitherShouldContain(
35 | EXPECTING_TO_CONTAIN_ON_RIGHT,
36 | actual,
37 | expectedValue,
38 | )
39 |
40 | /**
41 | * Indicates that the provided [Either] does not contain the provided argument as right value.
42 | *
43 | * @param actual the [Either] which contains a value.
44 | * @param expectedValue the value we expect to be in the provided [Either] on the left side.
45 | * @param LEFT the type of the value contained in the [Either] on the left side.
46 | * @param RIGHT the type of the value contained in the [Either] on the right side.
47 | * @return an error message factory
48 | */
49 | internal fun shouldContainOnLeft(
50 | actual: Either,
51 | expectedValue: RIGHT,
52 | ): EitherShouldContain = EitherShouldContain(
53 | EXPECTING_TO_CONTAIN_ON_LEFT,
54 | actual,
55 | expectedValue,
56 | )
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/EitherShouldContainInstanceOf.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Either
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when an [Either] should contain a value being an instance of a specific
8 | * class.
9 | *
10 | * @author Riccardo Cardin
11 | * @since 0.0.1
12 | */
13 | internal class EitherShouldContainInstanceOf private constructor(message: String) : BasicErrorMessageFactory(message) {
14 | companion object {
15 | private const val EXPECTING_TO_CONTAIN_DIFFERENT_INSTANCE =
16 | "%nExpecting:%n <%s>%nto contain a value that is an instance of:%n <%s>%nbut did contain an instance of:%n <%s>"
17 |
18 | private const val EXPECTING_TO_CONTAIN_BUT_IS_LEFT =
19 | "%nExpecting:%n <%s>%nto contain on right side:%n <%s>%nbut was left-sided."
20 |
21 | private const val EXPECTING_TO_CONTAIN_BUT_IS_RIGHT =
22 | "%nExpecting:%n <%s>%nto contain on left side:%n <%s>%nbut was right-sided."
23 |
24 | /**
25 | * Indicates that a value should be present in a right-sided [Either].
26 | *
27 | * @param actual Either to be checked.
28 | * @param expectedClass expected class of a right value
29 | * @return an error message factory.
30 | * @throws java.lang.NullPointerException if either is null.
31 | */
32 | internal fun shouldContainOnRightInstanceOf(
33 | actual: Either,
34 | expectedClass: Class<*>,
35 | ): EitherShouldContainInstanceOf =
36 | actual.fold(
37 | {
38 | EitherShouldContainInstanceOf(
39 | EXPECTING_TO_CONTAIN_BUT_IS_LEFT.format(
40 | actual.javaClass.simpleName,
41 | expectedClass.name,
42 | ),
43 | )
44 | },
45 | { rightValue ->
46 | EitherShouldContainInstanceOf(
47 | EXPECTING_TO_CONTAIN_DIFFERENT_INSTANCE.format(
48 | actual.javaClass.simpleName,
49 | expectedClass.name,
50 | rightValue?.javaClass?.name ?: "null",
51 | ),
52 | )
53 | },
54 | )
55 |
56 | internal fun shouldContainOnLeftInstanceOf(
57 | actual: Either,
58 | expectedClass: Class<*>,
59 | ): EitherShouldContainInstanceOf =
60 | actual.fold(
61 | { leftValue ->
62 | EitherShouldContainInstanceOf(
63 | EXPECTING_TO_CONTAIN_DIFFERENT_INSTANCE.format(
64 | actual.javaClass.simpleName,
65 | expectedClass.name,
66 | leftValue?.javaClass?.name ?: "null",
67 | ),
68 | )
69 | },
70 | {
71 | EitherShouldContainInstanceOf(
72 | EXPECTING_TO_CONTAIN_BUT_IS_RIGHT.format(
73 | actual.javaClass.simpleName,
74 | expectedClass.name,
75 | ),
76 | )
77 | },
78 | )
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/NonEmptyListShouldBeSingleElement.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a [NonEmptyList] does not have a single element equal a specific value.
8 | *
9 | * @author Hamza Faraji
10 | * @since 1.2.0
11 | */
12 | class NonEmptyListShouldBeSingleElement private constructor(message: String, actual: NonEmptyList, expected: Any?) :
13 | BasicErrorMessageFactory(message, actual, expected) {
14 | companion object {
15 | private const val EXPECTING_TO_HAVE_SINGLE_ELEMENT_EQUAL =
16 | "%nExpecting:%n <%s>%nto have single element:%n <%s>%nbut did not."
17 |
18 | internal fun shouldBeSingleElement(
19 | actual: NonEmptyList,
20 | expected: ELEMENT?
21 | ): NonEmptyListShouldBeSingleElement = NonEmptyListShouldBeSingleElement(
22 | EXPECTING_TO_HAVE_SINGLE_ELEMENT_EQUAL,
23 | actual,
24 | expected
25 | )
26 | }
27 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/NonEmptyListShouldBeSorted.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a [NonEmptyList] is not sorted.
8 | *
9 | * @author Hamza Faraji
10 | * @since 1.2.0
11 | */
12 | class NonEmptyListShouldBeSorted private constructor(message: String, actual: NonEmptyList) :
13 | BasicErrorMessageFactory(message, actual) {
14 | companion object {
15 | private const val EXPECTING_TO_BE_SORTED =
16 | "%nExpecting:%n <%s>%nto be sorted, but it is not."
17 |
18 | internal fun shouldBeSorted(
19 | actual: NonEmptyList
20 | ): NonEmptyListShouldBeSorted = NonEmptyListShouldBeSorted(
21 | EXPECTING_TO_BE_SORTED,
22 | actual
23 | )
24 | }
25 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/NonEmptyListShouldContain.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a [NonEmptyList] does not contain a specific value.
8 | *
9 | * @author Hamza Faraji
10 | * @since 1.2.0
11 | */
12 | internal class NonEmptyListShouldContain private constructor(message: String, actual: NonEmptyList, expected: Any?) :
13 | BasicErrorMessageFactory(message, actual, expected) {
14 | companion object {
15 | private const val EXPECTING_TO_CONTAIN =
16 | "%nExpecting:%n <%s>%nto contain:%n <%s>%nbut did not."
17 |
18 | internal fun shouldContain(
19 | actual: NonEmptyList,
20 | vararg expected: ELEMENT?
21 | ): NonEmptyListShouldContain = NonEmptyListShouldContain(
22 | EXPECTING_TO_CONTAIN,
23 | actual,
24 | expected
25 | )
26 | }
27 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/NonEmptyListShouldContainOnly.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a [NonEmptyList] does not contain only a specific value.
8 | *
9 | * @author Hamza Faraji
10 | * @since 1.2.0
11 | */
12 | class NonEmptyListShouldContainOnly private constructor(message: String, actual: NonEmptyList, expected: Any?) :
13 | BasicErrorMessageFactory(message, actual, expected) {
14 |
15 | companion object {
16 | private const val EXPECTING_TO_CONTAIN_ONLY =
17 | "%nExpecting:%n <%s>%nto contain only:%n <%s>%nbut did not."
18 |
19 | internal fun shouldContainOnly(
20 | actual: NonEmptyList,
21 | expected: ELEMENT?
22 | ): NonEmptyListShouldContainOnly = NonEmptyListShouldContainOnly(
23 | EXPECTING_TO_CONTAIN_ONLY,
24 | actual,
25 | expected
26 | )
27 | }
28 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/NonEmptyListShouldHaveDuplicates.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a [NonEmptyList] has no duplicates.
8 | *
9 | * @author Hamza Faraji
10 | * @since 1.2.0
11 | */
12 | class NonEmptyListShouldHaveDuplicates private constructor(message: String, actual: NonEmptyList) :
13 | BasicErrorMessageFactory(message, actual) {
14 | companion object {
15 | private const val EXPECTING_TO_CONTAIN_DUPLICATES =
16 | "%nExpecting:%n <%s>%nto contain duplicates but did not."
17 |
18 | internal fun shouldHaveDuplicates(
19 | actual: NonEmptyList
20 | ): NonEmptyListShouldHaveDuplicates = NonEmptyListShouldHaveDuplicates(
21 | EXPECTING_TO_CONTAIN_DUPLICATES,
22 | actual
23 | )
24 | }
25 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/NonEmptyListShouldNotContain.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.NonEmptyList
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a [NonEmptyList] contains a specific value.
8 | *
9 | * @author Hamza Faraji
10 | * @since 1.2.0
11 | */
12 | class NonEmptyListShouldNotContain(message: String, actual: NonEmptyList, expected: Any?) :
13 | BasicErrorMessageFactory(message, actual, expected) {
14 | companion object {
15 | private const val EXPECTING_NOT_TO_CONTAIN =
16 | "%nExpecting:%n <%s>%nnot to contain any:%n <%s>%nbut it did."
17 |
18 | internal fun shouldNotContain(
19 | actual: NonEmptyList,
20 | expected: ELEMENT
21 | ): NonEmptyListShouldNotContain = NonEmptyListShouldNotContain(
22 | EXPECTING_NOT_TO_CONTAIN,
23 | actual,
24 | expected
25 | )
26 | }
27 | }
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/OptionShouldBeEmpty.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Option
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when an [Option] should be empty.
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class OptionShouldBeEmpty private constructor(expected: Option<*>) :
13 | BasicErrorMessageFactory("%nExpecting an Option to be empty but was <%s>.", expected.getOrNull()) {
14 | companion object {
15 | internal fun shouldBeEmpty(actual: Option<*>): OptionShouldBeEmpty =
16 | OptionShouldBeEmpty(actual)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/OptionShouldBePresent.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Option
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when a value should be present in an [Option].
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class OptionShouldBePresent private constructor() :
13 | BasicErrorMessageFactory("%nExpecting Option to contain a value but it didn't.") {
14 | companion object {
15 | /**
16 | * Indicates that a value should be present in an empty [Option].
17 | *
18 | * @return a error message factory.
19 | */
20 | internal fun shouldBePresent(): OptionShouldBePresent = OptionShouldBePresent()
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/OptionShouldContain.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Option
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build error message when an [Option] should contain a specific value.
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class OptionShouldContain private constructor(message: String, vararg objs: Any) :
13 | BasicErrorMessageFactory(message, *objs) {
14 |
15 | companion object {
16 | private const val EXPECTING_TO_CONTAIN =
17 | "%nExpecting:%n <%s>%nto contain:%n <%s>%nbut did not."
18 | private const val EXPECTING_TO_CONTAIN_BUT_WAS_EMPTY =
19 | "%nExpecting Option to contain:%n <%s>%nbut was empty."
20 |
21 | /**
22 | * Indicates that the provided [Option] does not contain the provided argument.
23 | *
24 | * @param VALUE the type of the value contained in the [Option].
25 | * @param option the [Option] which contains a value.
26 | * @param expectedValue the value we expect to be in the provided [Option].
27 | * @return an error message factory
28 | */
29 | internal fun shouldContain(
30 | option: Option,
31 | expectedValue: VALUE,
32 | ): OptionShouldContain =
33 | option.fold(
34 | { OptionShouldContain(EXPECTING_TO_CONTAIN_BUT_WAS_EMPTY, expectedValue) },
35 | { _ ->
36 | OptionShouldContain(
37 | EXPECTING_TO_CONTAIN,
38 | option,
39 | expectedValue,
40 | )
41 | },
42 | )
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/OptionShouldContainInstanceOf.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import arrow.core.Option
4 | import org.assertj.core.error.BasicErrorMessageFactory
5 |
6 | /**
7 | * Build an error message when a value should be instance of a specific class.
8 | *
9 | * @author Riccardo Cardin
10 | * @since 0.0.1
11 | */
12 | internal class OptionShouldContainInstanceOf private constructor(message: String) : BasicErrorMessageFactory(message) {
13 |
14 | companion object {
15 | /**
16 | * Indicates that a value of a specific class should be present in an empty [Option].
17 | *
18 | * @param option Option to be checked.
19 | * @param clazz expected class of a value
20 | * @return an error message factory.
21 | * @throws java.lang.NullPointerException if option is null.
22 | */
23 | internal fun shouldContainInstanceOf(
24 | option: Option,
25 | clazz: Class<*>,
26 | ): OptionShouldContainInstanceOf = option.fold(
27 | {
28 | OptionShouldContainInstanceOf(
29 | "%nExpecting:%n <%s>%nto contain a value that is an instance of:%n <%s>%nbut was empty".format(
30 | option,
31 | clazz.name,
32 | ),
33 | )
34 | },
35 | { value ->
36 | OptionShouldContainInstanceOf(
37 | "%nExpecting:%n <%s>%nto contain a value that is an instance of:%n <%s>%nbut did contain an instance of:%n <%s>".format(
38 | option,
39 | clazz.name,
40 | value.javaClass.name,
41 | ),
42 | )
43 | },
44 | )
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/RaiseShouldFailButSucceeds.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import org.assertj.core.error.BasicErrorMessageFactory
4 |
5 | private const val SHOULD_FAIL_WITH_BUT_SUCCEEDS_WITH_MESSAGE: String =
6 | "%nExpecting the lambda to fail with:%n <%s> %nbut it succeeded with:%n <%s>"
7 |
8 | private const val SHOULD_FAIL_BUT_SUCCEEDS_WITH_MESSAGE: String =
9 | "%nExpecting the lambda to fail<%s>, but it succeeded with:%n <%s>"
10 |
11 | /**
12 | * Build error message when a lambda should fail with a logic error but it succeeded with a value.
13 | *
14 | * @author Riccardo Cardin
15 | * @since 0.2.0
16 | */
17 | class RaiseShouldFailButSucceeds private constructor(
18 | expectedError: Any?,
19 | actualSucceededValue: Any?,
20 | message: String,
21 | ) : BasicErrorMessageFactory(message, expectedError, actualSucceededValue) {
22 | companion object {
23 | internal fun shouldFailWithButSucceedsWith(
24 | expectedError: Any?,
25 | actualSucceededValue: Any?,
26 | ): RaiseShouldFailButSucceeds =
27 | RaiseShouldFailButSucceeds(expectedError, actualSucceededValue, SHOULD_FAIL_WITH_BUT_SUCCEEDS_WITH_MESSAGE)
28 |
29 | fun shouldFailButSucceedsWith(actualSucceededValue: Any?): RaiseShouldFailButSucceeds =
30 | RaiseShouldFailButSucceeds("", actualSucceededValue, SHOULD_FAIL_BUT_SUCCEEDS_WITH_MESSAGE)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/RaiseShouldFailWith.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import org.assertj.core.error.BasicErrorMessageFactory
4 |
5 | private const val SHOULD_FAIL_WITH_MESSAGE: String =
6 | "%nExpecting the lambda to fail with:%n <%s> %nbut it actual failed with:%n <%s>"
7 |
8 | /**
9 | * Build error message when a lambda should fail with a logic error but it fails with a different value.
10 | *
11 | * @author Riccardo Cardin
12 | * @since 0.2.0
13 | */
14 | internal class RaiseShouldFailWith private constructor(
15 | expectedError: Any?,
16 | actualError: Any?,
17 | ) : BasicErrorMessageFactory(SHOULD_FAIL_WITH_MESSAGE, expectedError, actualError) {
18 | companion object {
19 | internal fun shouldFailWith(
20 | expectedError: Any?,
21 | actualError: Any?,
22 | ): RaiseShouldFailWith = RaiseShouldFailWith(expectedError, actualError)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/RaiseShouldSucceedButFailed.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import org.assertj.core.error.BasicErrorMessageFactory
4 |
5 | private const val SHOULD_SUCCEED_BUT_FAILED_MESSAGE: String =
6 | "%nExpecting the lambda to succeed but it failed with:%n <%s>"
7 |
8 | /**
9 | * Build error message when a lambda should succeed, but it fails with a logic error.
10 | *
11 | * @author Riccardo Cardin
12 | * @since 1.0.0
13 | */
14 | internal class RaiseShouldSucceedButFailed private constructor(
15 | actualRaisedError: Any?,
16 | ) : BasicErrorMessageFactory(SHOULD_SUCCEED_BUT_FAILED_MESSAGE, actualRaisedError) {
17 | companion object {
18 | internal fun shouldSucceedButFailed(actualRaisedError: Any?): RaiseShouldSucceedButFailed =
19 | RaiseShouldSucceedButFailed(actualRaisedError)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/RaiseShouldSucceedWith.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import org.assertj.core.error.BasicErrorMessageFactory
4 |
5 | private const val SHOULD_SUCCEED_WITH_MESSAGE: String =
6 | "%nExpecting the lambda to succeed with:%n <%s> %nbut it actual succeed with:%n <%s>"
7 |
8 | /**
9 | * Build error message when a lambda should succeed with a value but it succeeds with a different value.
10 | *
11 | * @author Riccardo Cardin
12 | * @since 0.2.0
13 | */
14 | internal class RaiseShouldSucceedWith private constructor(
15 | expected: Any?,
16 | actual: Any?,
17 | ) : BasicErrorMessageFactory(SHOULD_SUCCEED_WITH_MESSAGE, expected, actual) {
18 | companion object {
19 | internal fun shouldSucceedWith(
20 | expected: Any?,
21 | actual: Any?,
22 | ): RaiseShouldSucceedWith = RaiseShouldSucceedWith(expected, actual)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/RaiseShouldSucceedWithButFailed.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import org.assertj.core.error.BasicErrorMessageFactory
4 |
5 | private const val SHOULD_SUCCEED_WITH_BUT_FAILED_MESSAGE: String =
6 | "%nExpecting the lambda to succeed with:%n <%s> %nbut it failed with:%n <%s>"
7 |
8 | /**
9 | * Build error message when a lambda should succeed with a value, but it fails with a logic error.
10 | *
11 | * @author Riccardo Cardin
12 | * @since 0.2.0
13 | */
14 | internal class RaiseShouldSucceedWithButFailed private constructor(
15 | expected: Any?,
16 | actualRaisedError: Any?,
17 | ) : BasicErrorMessageFactory(SHOULD_SUCCEED_WITH_BUT_FAILED_MESSAGE, expected, actualRaisedError) {
18 | companion object {
19 | internal fun shouldSucceedWithButFailed(
20 | expected: Any?,
21 | actualRaisedError: Any?,
22 | ): RaiseShouldSucceedWithButFailed = RaiseShouldSucceedWithButFailed(expected, actualRaisedError)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/kotlin/in/rcard/assertj/arrowcore/errors/RaiseShouldThrowAnException.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore.errors
2 |
3 | import org.assertj.core.error.BasicErrorMessageFactory
4 |
5 | private const val SHOULD_THROW_AN_EXCEPTION_MESSAGE = "%nExpecting code to throw a throwable."
6 |
7 | /**
8 | * Build error message when a lambda should throw an exception but it doesn't.
9 | *
10 | * @author Riccardo Cardin
11 | * @since 0.2.0
12 | */
13 | class RaiseShouldThrowAnException private constructor() : BasicErrorMessageFactory(SHOULD_THROW_AN_EXCEPTION_MESSAGE) {
14 | companion object {
15 | fun shouldThrowAnException(): RaiseShouldThrowAnException = RaiseShouldThrowAnException()
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/Dummy.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.raise.Raise
4 |
5 | internal object Dummy {
6 | fun Raise.aFunctionWithContext(input: Int): Int = input
7 |
8 | fun Raise.aFunctionThatRaisesAnError(): Int = raise("LOGICAL ERROR")
9 |
10 | fun Raise.aFunctionThatThrowsAnException(): Int = throw RuntimeException("AN EXCEPTION")
11 |
12 | suspend fun Raise.aSuspendFunctionWithContext(input: Int): Int = input
13 |
14 | suspend fun Raise.aSuspendFunctionThatThrowsAnException(): Int = throw RuntimeException("AN EXCEPTION")
15 |
16 | suspend fun Raise.aSuspendFunctionThatRaisesAnError(): Int = raise("LOGICAL ERROR")
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_asLeft_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.EitherAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeLeft.Companion.shouldBeLeft
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class EitherAssert_asLeft_Test {
13 |
14 | @Test
15 | internal fun `should return a valid Object assert if the either contains a left-sided value`() {
16 | val actualLeftValue: Either = 42.left()
17 | assertThat(actualLeftValue).asLeft().isEqualTo(42)
18 | }
19 |
20 | @Test
21 | internal fun `should return a valid Object assert if the either contains a left-sided null`() {
22 | val actualLeftValue: Either = null.left()
23 | assertThat(actualLeftValue).asLeft().isEqualTo(null)
24 | }
25 |
26 | @Test
27 | internal fun `should fail if the either contains a right-sided value`() {
28 | val actualRightValue: Either = "42".right()
29 | Assertions.assertThatThrownBy { assertThat(actualRightValue).asLeft() }
30 | .isInstanceOf(AssertionError::class.java)
31 | .hasMessage(shouldBeLeft(actualRightValue).create())
32 | }
33 |
34 | @Test
35 | internal fun `should fail if the either contains a right-sided null`() {
36 | val actualRightValue: Either = null.right()
37 | Assertions.assertThatThrownBy { assertThat(actualRightValue).asLeft() }
38 | .isInstanceOf(AssertionError::class.java)
39 | .hasMessage(shouldBeLeft(actualRightValue).create())
40 | }
41 |
42 | @Test
43 | internal fun `should fail if the either itself is null`() {
44 | val actualLeftValue: Either? = null
45 | Assertions.assertThatThrownBy { assertThat(actualLeftValue).asLeft() }
46 | .isInstanceOf(AssertionError::class.java)
47 | .hasMessage(FailureMessages.actualIsNull())
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_asRight_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.EitherAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class EitherAssert_asRight_Test {
13 |
14 | @Test
15 | internal fun `should return a valid Object assert if the either contains a right-sided value`() {
16 | val actualRightValue: Either = 42.right()
17 | assertThat(actualRightValue).asRight().isEqualTo(42)
18 | }
19 |
20 | @Test
21 | internal fun `should return a valid Object assert if either contains a right-sided null`() {
22 | val actualRightValue: Either = null.right()
23 | assertThat(actualRightValue).asRight().isEqualTo(null)
24 | }
25 |
26 | @Test
27 | internal fun `should fail if the either contains a left-sided value`() {
28 | val actualLeftValue: Either = "42".left()
29 | Assertions.assertThatThrownBy { assertThat(actualLeftValue).asRight() }
30 | .isInstanceOf(AssertionError::class.java)
31 | .hasMessage(shouldBeRight(actualLeftValue).create())
32 | }
33 |
34 | @Test
35 | internal fun `should fail if either contains a left-sided null`() {
36 | val actualLeftValue: Either = null.left()
37 | Assertions.assertThatThrownBy { assertThat(actualLeftValue).asRight() }
38 | .isInstanceOf(AssertionError::class.java)
39 | .hasMessage(shouldBeRight(actualLeftValue).create())
40 | }
41 |
42 | @Test
43 | internal fun `should fail if the either itself is null`() {
44 | val actualRightValue: Either? = null
45 | Assertions.assertThatThrownBy { assertThat(actualRightValue).asRight() }
46 | .isInstanceOf(AssertionError::class.java)
47 | .hasMessage(FailureMessages.actualIsNull())
48 | }
49 | }
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_assertThat_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.right
5 | import org.assertj.core.api.BDDAssertions.then
6 | import org.junit.jupiter.api.Test
7 |
8 | internal class EitherAssert_assertThat_Test {
9 | @Test
10 | internal fun `should create an assertion instance when given object is not null`() {
11 | // GIVEN
12 | val rightValue = 42.right()
13 | // WHEN
14 | val assertion = EitherAssert.assertThat(rightValue)
15 | // THEN
16 | then(assertion).isNotNull.isInstanceOf(EitherAssert::class.java)
17 | }
18 |
19 | @Test
20 | internal fun `should create an assertion instance when given object is null`() {
21 | // GIVEN
22 | val rightValue: Either? = null
23 | // WHEN
24 | val assertion = EitherAssert.assertThat(rightValue)
25 | // THEN
26 | then(assertion).isNotNull.isInstanceOf(EitherAssert::class.java)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_containsOnLeftInstanceOf_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.EitherAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeLeft.Companion.shouldBeLeft
8 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContainInstanceOf.Companion.shouldContainOnLeftInstanceOf
9 | import org.assertj.core.api.Assertions
10 | import org.assertj.core.util.FailureMessages
11 | import org.junit.jupiter.api.Test
12 |
13 | internal class EitherAssert_containsOnLeftInstanceOf_Test {
14 | @Test
15 | internal fun `should fail if either is null`() {
16 | val actual: Either? = null
17 | Assertions.assertThatThrownBy {
18 | assertThat(actual).containsLeftInstanceOf(
19 | Any::class.java,
20 | )
21 | }
22 | .isInstanceOf(AssertionError::class.java)
23 | .hasMessage(FailureMessages.actualIsNull())
24 | }
25 |
26 | @Test
27 | internal fun `should fail if either is right`() {
28 | val actual: Either = "some".right()
29 | Assertions.assertThatThrownBy {
30 | assertThat(actual).containsLeftInstanceOf(
31 | Any::class.java,
32 | )
33 | }
34 | .isInstanceOf(AssertionError::class.java)
35 | .hasMessage(shouldBeLeft(actual).create())
36 | }
37 |
38 | @Test
39 | internal fun `should fail if either contains a right-sided null`() {
40 | val actual: Either = null.right()
41 | Assertions.assertThatThrownBy {
42 | assertThat(actual).containsLeftInstanceOf(
43 | Any::class.java,
44 | )
45 | }
46 | .isInstanceOf(AssertionError::class.java)
47 | .hasMessage(shouldBeLeft(actual).create())
48 | }
49 |
50 | @Test
51 | internal fun `should pass if either contains required type on left`() {
52 | val actual: Either = "something".left()
53 | assertThat(actual)
54 | .containsLeftInstanceOf(String::class.java)
55 | }
56 |
57 | @Test
58 | internal fun `should fail if either contains null value for type on left`() {
59 | val actual: Either = null.left()
60 | Assertions.assertThatThrownBy {
61 | assertThat(actual)
62 | .containsLeftInstanceOf(String::class.java)
63 | }
64 | .isInstanceOf(AssertionError::class.java)
65 | .hasMessage(
66 | shouldContainOnLeftInstanceOf(
67 | actual,
68 | String::class.java
69 | ).create()
70 | )
71 | }
72 |
73 | @Test
74 | internal fun `should pass if either contains required type subclass on left`() {
75 | val actual = Child().left()
76 | assertThat(actual).containsLeftInstanceOf(Parent::class.java)
77 | }
78 |
79 | @Test
80 | internal fun `should fail if either contains other type on left than required`() {
81 | val actual: Either = "something".left()
82 | Assertions.assertThatThrownBy {
83 | assertThat(actual).containsLeftInstanceOf(Int::class.java)
84 | }
85 | .isInstanceOf(AssertionError::class.java)
86 | .hasMessage(
87 | shouldContainOnLeftInstanceOf(
88 | actual,
89 | Int::class.java,
90 | ).create(),
91 | )
92 | }
93 |
94 | private open class Parent
95 |
96 | private class Child : Parent()
97 | }
98 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_containsOnLeft_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeLeft.Companion.shouldBeLeft
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContain.Companion.shouldContainOnLeft
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages.actualIsNull
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class EitherAssert_containsOnLeft_Test {
13 | @Test
14 | internal fun `should fail when either is null`() {
15 | val leftValue: Either? = null
16 | Assertions.assertThatThrownBy {
17 | EitherAssert.assertThat(leftValue).containsOnLeft(
18 | "something",
19 | )
20 | }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(actualIsNull())
23 | }
24 |
25 | @Test
26 | internal fun `should pass if either contains expected value on left side`() {
27 | val leftValue = "something".left()
28 | EitherAssert.assertThat(leftValue).containsOnLeft("something")
29 | }
30 |
31 | @Test
32 | internal fun `should pass if either contains an expected null on left side`() {
33 | val leftValue = null.left()
34 | EitherAssert.assertThat(leftValue).containsOnLeft(null)
35 | }
36 |
37 | @Test
38 | internal fun `should fail if either does not contain expected value on left side`() {
39 | val actual: Either = "something".left()
40 | val expectedValue = "nothing"
41 | Assertions.assertThatThrownBy {
42 | EitherAssert.assertThat(actual).containsOnLeft(
43 | expectedValue,
44 | )
45 | }
46 | .isInstanceOf(AssertionError::class.java)
47 | .hasMessage(shouldContainOnLeft(actual, expectedValue).create())
48 | }
49 |
50 | @Test
51 | internal fun `should fail with informative error message if null is contained on left side and a value was expected`() {
52 | val actual: Either = null.left()
53 | val expectedValue = "something"
54 | Assertions.assertThatThrownBy {
55 | EitherAssert.assertThat(actual).containsOnLeft(
56 | expectedValue,
57 | )
58 | }
59 | .isInstanceOf(AssertionError::class.java)
60 | .hasMessage(shouldContainOnLeft(actual, expectedValue).create())
61 | }
62 |
63 | @Test
64 | internal fun `should fail if either is right`() {
65 | val actual: Either = "nothing".right()
66 | val expectedValue = "something"
67 | Assertions.assertThatThrownBy {
68 | EitherAssert.assertThat(actual).containsOnLeft(
69 | expectedValue,
70 | )
71 | }
72 | .isInstanceOf(AssertionError::class.java)
73 | .hasMessage(shouldBeLeft(actual).create())
74 | }
75 |
76 | @Test
77 | internal fun `should fail if either right-sided value is null`() {
78 | val actual: Either = null.right()
79 | val expectedValue = "something"
80 | Assertions.assertThatThrownBy {
81 | EitherAssert.assertThat(actual).containsOnLeft(
82 | expectedValue,
83 | )
84 | }
85 | .isInstanceOf(AssertionError::class.java)
86 | .hasMessage(shouldBeLeft(actual).create())
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_containsOnRightInstanceOf_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.EitherAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
8 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContainInstanceOf.Companion.shouldContainOnRightInstanceOf
9 | import org.assertj.core.api.Assertions
10 | import org.assertj.core.util.FailureMessages
11 | import org.junit.jupiter.api.Test
12 |
13 | internal class EitherAssert_containsOnRightInstanceOf_Test {
14 |
15 | @Test
16 | internal fun `should fail if either is null`() {
17 | val actual: Either? = null
18 | Assertions.assertThatThrownBy {
19 | assertThat(actual).containsRightInstanceOf(Any::class.java)
20 | }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(FailureMessages.actualIsNull())
23 | }
24 |
25 | @Test
26 | internal fun `should fail if either is left`() {
27 | val actual: Either = "some".left()
28 | Assertions.assertThatThrownBy {
29 | assertThat(actual).containsRightInstanceOf(Any::class.java)
30 | }
31 | .isInstanceOf(AssertionError::class.java)
32 | .hasMessage(shouldBeRight(actual).create())
33 | }
34 |
35 | @Test
36 | internal fun should_fail_if_either_contains_other_type_on_right_than_required() {
37 | val actual: Either = 42.right()
38 | Assertions.assertThatThrownBy {
39 | assertThat(actual).containsRightInstanceOf(String::class.java)
40 | }
41 | .isInstanceOf(AssertionError::class.java)
42 | .hasMessage(
43 | shouldContainOnRightInstanceOf(
44 | actual,
45 | String::class.java,
46 | )
47 | .create(),
48 | )
49 | }
50 |
51 | @Test
52 | internal fun `should fail if either contains a left-sided null`() {
53 | val actual: Either = null.left()
54 | Assertions.assertThatThrownBy {
55 | assertThat(actual).containsRightInstanceOf(
56 | Any::class.java,
57 | )
58 | }
59 | .isInstanceOf(AssertionError::class.java)
60 | .hasMessage(shouldBeRight(actual).create())
61 | }
62 |
63 | @Test
64 | internal fun `should fail if either contains null value for type on right`() {
65 | val actual: Either = null.right()
66 | Assertions.assertThatThrownBy {
67 | assertThat(actual)
68 | .containsRightInstanceOf(String::class.java)
69 | }
70 | .isInstanceOf(AssertionError::class.java)
71 | .hasMessage(
72 | shouldContainOnRightInstanceOf(
73 | actual,
74 | String::class.java
75 | ).create()
76 | )
77 | }
78 |
79 | @Test
80 | internal fun `should pass if either contains required type subclass on right`() {
81 | val actual = Child().right()
82 | assertThat(actual).containsRightInstanceOf(Parent::class.java)
83 | }
84 |
85 | @Test
86 | internal fun `should pass if either contains required type on right`() {
87 | val actual: Either = "something".right()
88 | assertThat(actual).containsRightInstanceOf(String::class.java)
89 | }
90 |
91 | private open class Parent
92 |
93 | private class Child : Parent()
94 | }
95 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_containsOnRight_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
7 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldContain.Companion.shouldContainOnRight
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages.actualIsNull
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class EitherAssert_containsOnRight_Test {
13 | @Test
14 | internal fun `should fail when either itself is null`() {
15 | val rightValue: Either? = null
16 | Assertions.assertThatThrownBy {
17 | EitherAssert.assertThat(rightValue).containsOnRight(
18 | "something",
19 | )
20 | }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(actualIsNull())
23 | }
24 |
25 | @Test
26 | internal fun `should pass if either contains expected value on right side`() {
27 | val rightValue = "something".right()
28 | EitherAssert.assertThat(rightValue).containsOnRight("something")
29 | }
30 |
31 | @Test
32 | internal fun `should pass if either contains a null on right side`() {
33 | val rightValue = null.right()
34 | EitherAssert.assertThat(rightValue).containsOnRight(null)
35 | }
36 |
37 | @Test
38 | internal fun should_fail_if_either_is_left() {
39 | val actual: Either = "nothing".left()
40 | val expectedValue = "something"
41 | Assertions.assertThatThrownBy {
42 | EitherAssert.assertThat(actual).containsOnRight(expectedValue)
43 | }
44 | .isInstanceOf(AssertionError::class.java)
45 | .hasMessage(shouldBeRight(actual).create())
46 | }
47 |
48 | @Test
49 | internal fun `should fail if either contains a left sided null`() {
50 | val actual: Either = null.left()
51 | val expectedValue = "something"
52 | Assertions.assertThatThrownBy {
53 | EitherAssert.assertThat(actual).containsOnRight(expectedValue)
54 | }
55 | .isInstanceOf(AssertionError::class.java)
56 | .hasMessage(shouldBeRight(actual).create())
57 | }
58 |
59 | @Test
60 | internal fun `should fail if either does not contain expected value on right side`() {
61 | val actual: Either = "something".right()
62 | val expectedValue = "nothing"
63 | Assertions.assertThatThrownBy {
64 | EitherAssert.assertThat(actual).containsOnRight(expectedValue)
65 | }
66 | .isInstanceOf(AssertionError::class.java)
67 | .hasMessage(shouldContainOnRight(actual, expectedValue).create())
68 | }
69 |
70 | @Test
71 | internal fun `should fail with informative error message if either contains null on right but a value was expected`() {
72 | val actual: Either = null.right()
73 | val expectedValue = "nothing"
74 | Assertions.assertThatThrownBy {
75 | EitherAssert.assertThat(actual).containsOnRight(expectedValue)
76 | }
77 | .isInstanceOf(AssertionError::class.java)
78 | .hasMessage(shouldContainOnRight(actual, expectedValue).create())
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_hasLeftValueSatisfying_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.right
5 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeLeft
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.api.Assertions.assertThat
8 | import org.assertj.core.util.FailureMessages.actualIsNull
9 | import org.junit.jupiter.api.Test
10 |
11 |
12 | internal class EitherAssert_hasLeftValueSatisfying_Test {
13 |
14 | @Test
15 | internal fun `should fail when either is null`() {
16 | val actual: Either? = null
17 | Assertions.assertThatThrownBy { EitherAssert.assertThat(actual).hasLeftValueSatisfying { } }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(actualIsNull())
20 | }
21 |
22 | @Test
23 | internal fun `should fail if either is right`() {
24 | val actual: Either = Either.Right("something")
25 | Assertions.assertThatThrownBy { EitherAssert.assertThat(actual).hasLeftValueSatisfying { } }
26 | .isInstanceOf(AssertionError::class.java)
27 | .hasMessage(EitherShouldBeLeft.shouldBeLeft(actual).create())
28 | }
29 |
30 | @Test
31 | internal fun `should fail if either is right and null`() {
32 | val actual: Either = null.right()
33 | Assertions.assertThatThrownBy { EitherAssert.assertThat(actual).hasLeftValueSatisfying { } }
34 | .isInstanceOf(AssertionError::class.java)
35 | .hasMessage(EitherShouldBeLeft.shouldBeLeft(actual).create())
36 | }
37 |
38 | @Test
39 | internal fun `should fail if consumer fails`() {
40 | val actual: Either = Either.Left(42)
41 | Assertions.assertThatThrownBy { EitherAssert.assertThat(actual).hasLeftValueSatisfying { assertThat(it).isEqualTo(24) } }
42 | .isInstanceOf(AssertionError::class.java)
43 | .hasMessage(("${System.lineSeparator()}expected: 24${System.lineSeparator()} but was: 42"))
44 | }
45 |
46 | @Test
47 | internal fun `should pass if consumer passes`() {
48 | val actual: Either = Either.Left(42)
49 | EitherAssert.assertThat(actual).hasLeftValueSatisfying { assertThat(it).isEqualTo(42) }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_hasRightValueSatisfying_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
6 | import org.assertj.core.api.Assertions.assertThat
7 | import org.assertj.core.api.Assertions.assertThatThrownBy
8 | import org.assertj.core.util.FailureMessages.actualIsNull
9 | import org.junit.jupiter.api.Test
10 |
11 |
12 | internal class EitherAssert_hasRightValueSatisfying_Test {
13 |
14 | @Test
15 | internal fun `should fail when either is null`() {
16 | val actual: Either? = null
17 | assertThatThrownBy { EitherAssert.assertThat(actual).hasRightValueSatisfying { } }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(actualIsNull())
20 | }
21 |
22 | @Test
23 | internal fun `should fail if either is left`() {
24 | val actual: Either = Either.Left(42)
25 | assertThatThrownBy { EitherAssert.assertThat(actual).hasRightValueSatisfying { } }
26 | .isInstanceOf(AssertionError::class.java)
27 | .hasMessage(shouldBeRight(actual).create())
28 | }
29 |
30 | @Test
31 | internal fun `should fail if either is left and contains a null value`() {
32 | val actual: Either = null.left()
33 | assertThatThrownBy { EitherAssert.assertThat(actual).hasRightValueSatisfying { } }
34 | .isInstanceOf(AssertionError::class.java)
35 | .hasMessage(shouldBeRight(actual).create())
36 | }
37 |
38 | @Test
39 | internal fun `should fail if consumer fails`() {
40 | val actual: Either = Either.Right("something")
41 | assertThatThrownBy { EitherAssert.assertThat(actual).hasRightValueSatisfying { assertThat(it).isEqualTo("something else") } }
42 | .isInstanceOf(AssertionError::class.java)
43 | .hasMessage(("${System.lineSeparator()}expected: \"something else\"${System.lineSeparator()} but was: \"something\""))
44 | }
45 |
46 | @Test
47 | internal fun `should pass if consumer passes`() {
48 | val actual: Either = Either.Right("something")
49 | EitherAssert.assertThat(actual).hasRightValueSatisfying { assertThat(it).isEqualTo("something") }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_isLeft_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeLeft.Companion.shouldBeLeft
7 | import org.assertj.core.api.Assertions
8 | import org.assertj.core.util.FailureMessages
9 | import org.junit.jupiter.api.Test
10 |
11 | internal class EitherAssert_isLeft_Test {
12 |
13 | @Test
14 | internal fun `should fail if either is null`() {
15 | // GIVEN
16 | val leftValue: Either? = null
17 | // WHEN/THEN
18 | Assertions.assertThatThrownBy { EitherAssert.assertThat(leftValue).isLeft() }
19 | .isInstanceOf(AssertionError::class.java)
20 | .hasMessage(FailureMessages.actualIsNull())
21 | }
22 |
23 | @Test
24 | internal fun `should pass if either is left`() {
25 | // GIVEN
26 | val leftValue = "Error".left()
27 | // WHEN/THEN
28 | EitherAssert.assertThat(leftValue).isLeft()
29 | }
30 |
31 | @Test
32 | internal fun `should pass if either is left-sided null`() {
33 | // GIVEN
34 | val leftValue = null.left()
35 | // WHEN/THEN
36 | EitherAssert.assertThat(leftValue).isLeft()
37 | }
38 |
39 | @Test
40 | internal fun `should fail if either is right`() {
41 | // GIVEN
42 | val rightValue = 42.right()
43 | // WHEN/THEN
44 | Assertions.assertThatThrownBy { EitherAssert.assertThat(rightValue).isLeft() }
45 | .isInstanceOf(AssertionError::class.java)
46 | .hasMessage(shouldBeLeft(rightValue).create())
47 | }
48 |
49 | @Test
50 | internal fun `should fail if either is right and null`() {
51 | // GIVEN
52 | val rightValue = null.right()
53 | // WHEN/THEN
54 | Assertions.assertThatThrownBy { EitherAssert.assertThat(rightValue).isLeft() }
55 | .isInstanceOf(AssertionError::class.java)
56 | .hasMessage(shouldBeLeft(rightValue).create())
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_isRight_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Either
4 | import arrow.core.left
5 | import arrow.core.right
6 | import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
7 | import org.assertj.core.api.Assertions
8 | import org.assertj.core.util.FailureMessages.actualIsNull
9 | import org.junit.jupiter.api.Test
10 |
11 | internal class EitherAssert_isRight_Test {
12 |
13 | @Test
14 | internal fun `should fail if either is null`() {
15 | // GIVEN
16 | val rightValue: Either? = null
17 | // WHEN/THEN
18 | Assertions.assertThatThrownBy { EitherAssert.assertThat(rightValue).isRight() }
19 | .isInstanceOf(AssertionError::class.java)
20 | .hasMessage(actualIsNull())
21 | }
22 |
23 | @Test
24 | internal fun `should pass if either is right`() {
25 | // GIVEN
26 | val rightValue = 42.right()
27 | // WHEN/THEN
28 | EitherAssert.assertThat(rightValue).isRight()
29 | }
30 |
31 | @Test
32 | internal fun `should pass if either is right-sided null`() {
33 | // GIVEN
34 | val rightValue = null.right()
35 | // WHEN/THEN
36 | EitherAssert.assertThat(rightValue).isRight()
37 | }
38 |
39 | @Test
40 | internal fun `should fail if either is left`() {
41 | // GIVEN
42 | val leftValue = "42".left()
43 | // WHEN/THEN
44 | Assertions.assertThatThrownBy { EitherAssert.assertThat(leftValue).isRight() }
45 | .isInstanceOf(AssertionError::class.java)
46 | .hasMessage(shouldBeRight(leftValue).create())
47 | }
48 |
49 | @Test
50 | internal fun `should fail if either is left-sided null`() {
51 | // GIVEN
52 | val leftValue = null.left()
53 | // WHEN/THEN
54 | Assertions.assertThatThrownBy { EitherAssert.assertThat(leftValue).isRight() }
55 | .isInstanceOf(AssertionError::class.java)
56 | .hasMessage(shouldBeRight(leftValue).create())
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldBeSingleElement_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldBeSingleElement.Companion.shouldBeSingleElement
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldBeSingleElement_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list has more than one element`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 2)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldBeSingleElement(1) }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldBeSingleElement(list, 1).create())
20 | }
21 |
22 | @Test
23 | internal fun `should fail if non empty list has one element but it's not equal to expected value`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(41)
26 | // WHEN/THEN
27 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldBeSingleElement(42) }
28 | .isInstanceOf(AssertionError::class.java)
29 | .hasMessage(shouldBeSingleElement(list, 42).create())
30 | }
31 |
32 | @Test
33 | internal fun `should pass if empty list contains element`() {
34 | // GIVEN
35 | val list: NonEmptyList = nonEmptyListOf(42)
36 | // WHEN/THEN
37 | NonEmptyListAssert.assertThat(list).shouldBeSingleElement(42)
38 | }
39 |
40 | @Test
41 | internal fun `should fail if list is null`() {
42 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldBeSingleElement(1) }
43 | .isInstanceOf(AssertionError::class.java)
44 | .hasMessage(actualIsNull())
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldBeSorted_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldBeSorted.Companion.shouldBeSorted
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldBeSorted_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list is not sorted`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 3, 4, 2)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldBeSorted() }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldBeSorted(list).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if non empty list is sorted`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3, 4)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldBeSorted()
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldBeSorted() }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldContainAll_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldContain.Companion.shouldContain
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldContainAll_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list does not contain all elements`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldContainAll(4, 5, 6) }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldContain(list, arrayOf(4, 5, 6)).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if empty list contains element`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldContainAll(1, 2, 3)
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldContainAll(1) }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldContainNoNulls_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldNotContain.Companion.shouldNotContain
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldContainNoNulls_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list contains a null`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 2, null)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldContainNoNulls() }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldNotContain(list, null).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if empty list contain no nulls`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldContainNoNulls()
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldContainNoNulls() }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldContainNull_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldContain.Companion.shouldContain
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldContainNull_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list does not contain a null`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldContainNull() }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldContain(list, null).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if empty list contains null`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(1, null, 2)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldContainNull()
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldContainNull() }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldContainOnlyNulls_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldContainOnly.Companion.shouldContainOnly
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldContainOnlyNulls_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list contains a non-null`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(null, null, 42)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldContainOnlyNulls() }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldContainOnly(list, null).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if empty list contains only null`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(null, null, null)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldContainOnlyNulls()
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldContainOnlyNulls() }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldContain_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldContain.Companion.shouldContain
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldContain_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list does not contain element`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 2, 4)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldContain(3) }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldContain(list, 3).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if empty list contains element`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldContain(3)
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldContain(1) }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/NonEmptyListAssert_shouldHaveDuplicates_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.NonEmptyList
4 | import arrow.core.nonEmptyListOf
5 | import `in`.rcard.assertj.arrowcore.errors.NonEmptyListShouldHaveDuplicates.Companion.shouldHaveDuplicates
6 | import org.assertj.core.api.Assertions
7 | import org.assertj.core.util.FailureMessages.actualIsNull
8 | import org.junit.jupiter.api.Test
9 |
10 | internal class NonEmptyListAssert_shouldHaveDuplicates_Test {
11 |
12 | @Test
13 | internal fun `should fail if non empty list has no duplicates`() {
14 | // GIVEN
15 | val list: NonEmptyList = nonEmptyListOf(1, 2, 3, 4)
16 | // WHEN/THEN
17 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(list).shouldHaveDuplicates() }
18 | .isInstanceOf(AssertionError::class.java)
19 | .hasMessage(shouldHaveDuplicates(list).create())
20 | }
21 |
22 | @Test
23 | internal fun `should pass if non empty list has at least one duplicate`() {
24 | // GIVEN
25 | val list: NonEmptyList = nonEmptyListOf(1, 2, 2, 3)
26 | // WHEN/THEN
27 | NonEmptyListAssert.assertThat(list).shouldHaveDuplicates()
28 | }
29 |
30 | @Test
31 | internal fun `should fail if list is null`() {
32 | Assertions.assertThatThrownBy { NonEmptyListAssert.assertThat(null).shouldHaveDuplicates() }
33 | .isInstanceOf(AssertionError::class.java)
34 | .hasMessage(actualIsNull())
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_assertThat_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.Option
4 | import arrow.core.some
5 | import org.assertj.core.api.BDDAssertions.then
6 | import org.junit.jupiter.api.Test
7 |
8 | internal class OptionAssert_assertThat_Test {
9 | @Test
10 | internal fun `should create an assertion instance when given object is not null`() {
11 | // GIVEN
12 | val someValue = 42.some()
13 | // WHEN
14 | val assertion = OptionAssert.assertThat(someValue)
15 | // THEN
16 | then(assertion).isNotNull.isInstanceOf(OptionAssert::class.java)
17 | }
18 |
19 | @Test
20 | internal fun `should create an assertion instance when given object is null`() {
21 | // GIVEN
22 | val someNullValue: Option? = null
23 | // WHEN
24 | val assertion = OptionAssert.assertThat(someNullValue)
25 | // THEN
26 | then(assertion).isNotNull.isInstanceOf(OptionAssert::class.java)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_containsInstanceOf_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.None
4 | import arrow.core.Option
5 | import arrow.core.some
6 | import `in`.rcard.assertj.arrowcore.OptionAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBePresent.Companion.shouldBePresent
8 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldContainInstanceOf.Companion.shouldContainInstanceOf
9 | import org.assertj.core.api.Assertions
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class OptionAssert_containsInstanceOf_Test {
13 |
14 | @Test
15 | internal fun `should fail if option is empty`() {
16 | val actual: Option = None
17 | Assertions.assertThatThrownBy {
18 | assertThat(actual).containsInstanceOf(
19 | Any::class.java,
20 | )
21 | }
22 | .isInstanceOf(AssertionError::class.java)
23 | .hasMessage(shouldBePresent().create())
24 | }
25 |
26 | @Test
27 | internal fun `should pass if option contains required type`() {
28 | val optionValue = "something".some()
29 | assertThat(optionValue).containsInstanceOf(String::class.java)
30 | }
31 |
32 | @Test
33 | internal fun `should pass if option contains required type subclass`() {
34 | val optionValue = Child().some()
35 | assertThat(optionValue).containsInstanceOf(
36 | Parent::class.java,
37 | )
38 | }
39 |
40 | @Test
41 | internal fun `should fail if option contains other type than required`() {
42 | val actual = 42.some()
43 | Assertions.assertThatThrownBy {
44 | assertThat(actual).containsInstanceOf(String::class.java)
45 | }
46 | .isInstanceOf(AssertionError::class.java)
47 | .hasMessage(
48 | shouldContainInstanceOf(
49 | actual,
50 | String::class.java,
51 | ).create(),
52 | )
53 | }
54 |
55 | private open class Parent
56 |
57 | private class Child : Parent()
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_contains_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.None
4 | import arrow.core.Option
5 | import arrow.core.some
6 | import `in`.rcard.assertj.arrowcore.OptionAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldContain.Companion.shouldContain
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class OptionAssert_contains_Test {
13 |
14 | @Test
15 | internal fun `should fail when option is null`() {
16 | Assertions.assertThatThrownBy {
17 | val nullOption: Option? = null
18 | assertThat(nullOption).contains("something")
19 | }
20 | .isInstanceOf(AssertionError::class.java)
21 | .hasMessage(FailureMessages.actualIsNull())
22 | }
23 |
24 | @Test
25 | internal fun `should pass if option contains expected value`() {
26 | assertThat("something".some()).contains("something")
27 | }
28 |
29 | @Test
30 | internal fun `should fail if option does not contain expected value`() {
31 | val actual: Option = "not-expected".some()
32 | val expectedValue = "something"
33 | Assertions.assertThatThrownBy { assertThat(actual).contains(expectedValue) }
34 | .isInstanceOf(AssertionError::class.java)
35 | .hasMessage(shouldContain(actual, expectedValue).create())
36 | }
37 |
38 | @Test
39 | internal fun `should fail if option is empty`() {
40 | val expectedValue = "something"
41 | val emptyOption: Option = None
42 | Assertions.assertThatThrownBy {
43 | assertThat(emptyOption).contains(expectedValue)
44 | }
45 | .isInstanceOf(AssertionError::class.java)
46 | .hasMessage(shouldContain(emptyOption, expectedValue).create())
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_get_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.None
4 | import arrow.core.Option
5 | import arrow.core.some
6 | import `in`.rcard.assertj.arrowcore.OptionAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBePresent.Companion.shouldBePresent
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class OptionAssert_get_Test {
13 |
14 | @Test
15 | internal fun `should return a valid Object assert if the Option is not empty`() {
16 | val some: Option = "42".some()
17 | assertThat(some).get().isEqualTo("42")
18 | }
19 |
20 | @Test
21 | internal fun `should fail if the Option is empty`() {
22 | val none: Option = None
23 | Assertions.assertThatThrownBy { assertThat(none).get() }
24 | .isInstanceOf(AssertionError::class.java)
25 | .hasMessage(shouldBePresent().create())
26 | }
27 |
28 | @Test
29 | internal fun `should fail if the Option is null`() {
30 | val nullOption: Option? = null
31 | Assertions.assertThatThrownBy { assertThat(nullOption).get() }
32 | .isInstanceOf(AssertionError::class.java)
33 | .hasMessage(FailureMessages.actualIsNull())
34 | }
35 | }
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_hasValueSatisfying_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.None
4 | import arrow.core.Option
5 | import `in`.rcard.assertj.arrowcore.OptionAssert.Companion.assertThat
6 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBePresent.Companion.shouldBePresent
7 | import org.assertj.core.api.Assertions.assertThat
8 | import org.assertj.core.api.Assertions.assertThatThrownBy
9 | import org.assertj.core.util.FailureMessages.actualIsNull
10 | import org.junit.jupiter.api.Test
11 |
12 |
13 | internal class OptionAssert_hasValueSatisfying_Test {
14 |
15 | @Test
16 | internal fun `should fail when option is null`() {
17 | assertThatThrownBy {
18 | val nullOption: Option? = null
19 | assertThat(nullOption).hasValueSatisfying { }
20 | }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(actualIsNull())
23 | }
24 |
25 | @Test
26 | internal fun `should fail when option is none`() {
27 | assertThatThrownBy {
28 | assertThat(None).hasValueSatisfying { }
29 | }
30 | .isInstanceOf(AssertionError::class.java)
31 | .hasMessage(shouldBePresent().create())
32 | }
33 |
34 |
35 | @Test
36 | internal fun `should pass when consumer passes`() {
37 | assertThat(Option("something")).hasValueSatisfying {
38 | assertThat(it).isEqualTo("something")
39 | .startsWith("some")
40 | .endsWith("thing")
41 | }
42 | assertThat(Option(10)).hasValueSatisfying {
43 | assertThat(it).isGreaterThan(9)
44 | }
45 | }
46 |
47 | @Test
48 | internal fun `should fail from consumer`() {
49 | assertThatThrownBy {
50 | assertThat(Option("something"))
51 | .hasValueSatisfying { assertThat(it).isEqualTo("something else") }
52 | }
53 | .isInstanceOf(AssertionError::class.java)
54 | .hasMessage("${System.lineSeparator()}expected: \"something else\"${System.lineSeparator()} but was: \"something\"")
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_isDefined_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.None
4 | import arrow.core.Option
5 | import arrow.core.some
6 | import `in`.rcard.assertj.arrowcore.OptionAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBePresent.Companion.shouldBePresent
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages.actualIsNull
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class OptionAssert_isDefined_Test {
13 | @Test
14 | internal fun `should pass when Option is present`() {
15 | assertThat("present".some()).isDefined()
16 | }
17 |
18 | @Test
19 | internal fun `should fail when Option is empty`() {
20 | Assertions.assertThatThrownBy { assertThat(None).isDefined() }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(shouldBePresent().create())
23 | }
24 |
25 | @Test
26 | internal fun `should fail when Option is null`() {
27 | val nullOption: Option? = null
28 | Assertions.assertThatThrownBy { assertThat(nullOption).isDefined() }
29 | .isInstanceOf(AssertionError::class.java)
30 | .hasMessage(actualIsNull())
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/OptionAssert_isEmpty_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import arrow.core.None
4 | import arrow.core.Option
5 | import arrow.core.some
6 | import `in`.rcard.assertj.arrowcore.OptionAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.OptionShouldBeEmpty.Companion.shouldBeEmpty
8 | import org.assertj.core.api.Assertions
9 | import org.assertj.core.util.FailureMessages
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class OptionAssert_isEmpty_Test {
13 |
14 | @Test
15 | internal fun `should pass if Option is empty`() {
16 | assertThat(None).isEmpty()
17 | }
18 |
19 | @Test
20 | internal fun `should fail when Option is null`() {
21 | val nullOption: Option? = null
22 | Assertions.assertThatThrownBy { assertThat(nullOption).isEmpty() }
23 | .isInstanceOf(AssertionError::class.java)
24 | .hasMessage(FailureMessages.actualIsNull())
25 | }
26 |
27 | @Test
28 | internal fun `should fail if Option is present`() {
29 | val actual: Option = "not-empty".some()
30 | Assertions.assertThatThrownBy { assertThat(actual).isEmpty() }
31 | .isInstanceOf(AssertionError::class.java)
32 | .hasMessage(shouldBeEmpty(actual).create())
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_assertThatRaisedBy_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.Dummy.aSuspendFunctionThatRaisesAnError
7 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThatRaisedBy
8 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailButSucceedsWith
9 | import kotlinx.coroutines.test.runTest
10 | import org.assertj.core.api.Assertions
11 | import org.junit.jupiter.api.Test
12 |
13 | class RaiseAssert_assertThatRaisedBy_Test {
14 | @Test
15 | internal fun `should return a valid Object Assert if the Raise raises an error`() {
16 | assertThatRaisedBy { aFunctionThatRaisesAnError() }.isEqualTo("LOGICAL ERROR")
17 | }
18 |
19 | @Test
20 | fun `should work with suspended functions`() =
21 | runTest {
22 | assertThatRaisedBy { aSuspendFunctionThatRaisesAnError() }.isEqualTo("LOGICAL ERROR")
23 | }
24 |
25 | @Test
26 | internal fun `should fails if the Raise returns a value`() {
27 | Assertions
28 | .assertThatThrownBy { assertThatRaisedBy { aFunctionWithContext(42) } }
29 | .isInstanceOf(AssertionError::class.java)
30 | .hasMessage(shouldFailButSucceedsWith(42).create())
31 | }
32 |
33 | @Test
34 | internal fun `should rethrow the inner exception`() {
35 | Assertions
36 | .assertThatThrownBy { assertThatRaisedBy { aFunctionThatThrowsAnException() } }
37 | .isInstanceOf(RuntimeException::class.java)
38 | .hasMessage("AN EXCEPTION")
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_assertThatThrownBy_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.Dummy.aSuspendFunctionThatThrowsAnException
7 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThatThrownBy
8 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldThrowAnException.Companion.shouldThrowAnException
9 | import kotlinx.coroutines.test.runTest
10 | import org.assertj.core.api.Assertions
11 | import org.junit.jupiter.api.Test
12 |
13 | internal class RaiseAssert_assertThatThrownBy_Test {
14 | @Test
15 | internal fun `should succeed if the lambda throws an exception`() {
16 | assertThatThrownBy { aFunctionThatThrowsAnException() }
17 | .isInstanceOf(RuntimeException::class.java)
18 | .hasMessage("AN EXCEPTION")
19 | }
20 |
21 | @Test
22 | internal fun `should succeed if the suspending lambda throws an exception`() =
23 | runTest {
24 | assertThatThrownBy { aSuspendFunctionThatThrowsAnException() }
25 | .isInstanceOf(RuntimeException::class.java)
26 | .hasMessage("AN EXCEPTION")
27 | }
28 |
29 | @Test
30 | internal fun `should fail if the lambda succeeds with a value`() {
31 | Assertions
32 | .assertThatThrownBy {
33 | assertThatThrownBy { aFunctionWithContext(42) }
34 | }.isInstanceOf(AssertionError::class.java)
35 | .hasMessage(
36 | shouldThrowAnException().create(),
37 | )
38 | }
39 |
40 | @Test
41 | internal fun `should fail if the lambda raises an error`() {
42 | Assertions
43 | .assertThatThrownBy {
44 | assertThatThrownBy { aFunctionThatRaisesAnError() }
45 | }.isInstanceOf(AssertionError::class.java)
46 | .hasMessage(
47 | shouldThrowAnException().create(),
48 | )
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_assertThat_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
4 | import `in`.rcard.assertj.arrowcore.Dummy.aSuspendFunctionWithContext
5 | import kotlinx.coroutines.test.runTest
6 | import org.assertj.core.api.BDDAssertions.then
7 | import org.junit.jupiter.api.Test
8 |
9 | internal class RaiseAssert_assertThat_Test {
10 | @Test
11 | internal fun `should create an assertion instance when given lambda is not null`() {
12 | val assertion = RaiseAssert.assertThat { aFunctionWithContext(42) }
13 | then(assertion).isNotNull.isInstanceOf(RaiseAssert::class.java)
14 | }
15 |
16 | @Test
17 | internal fun `should create an assertion instance for suspending lambdas`() =
18 | runTest {
19 | val assertion = RaiseAssert.assertThat { aSuspendFunctionWithContext(42) }
20 | then(assertion).isNotNull.isInstanceOf(RaiseAssert::class.java)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_error_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailButSucceedsWith
8 | import org.assertj.core.api.Assertions
9 | import org.junit.jupiter.api.Test
10 |
11 | internal class RaiseAssert_error_Test {
12 | @Test
13 | internal fun `should return a valid Object Assert if the Raise raises an error`() {
14 | assertThat { aFunctionThatRaisesAnError() }.error().isEqualTo("LOGICAL ERROR")
15 | }
16 |
17 | @Test
18 | internal fun `should fails if the Raise returns a value`() {
19 | Assertions
20 | .assertThatThrownBy { assertThat { aFunctionWithContext(42) }.error() }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(shouldFailButSucceedsWith(42).create())
23 | }
24 |
25 | @Test
26 | internal fun `should rethrow the inner exception`() {
27 | Assertions
28 | .assertThatThrownBy { assertThat { aFunctionThatThrowsAnException() }.error() }
29 | .isInstanceOf(RuntimeException::class.java)
30 | .hasMessage("AN EXCEPTION")
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_fails_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailButSucceedsWith
8 | import org.assertj.core.api.Assertions
9 | import org.junit.jupiter.api.Test
10 |
11 | @Suppress("ktlint:standard:class-naming")
12 | internal class RaiseAssert_fails_Test {
13 | @Test
14 | internal fun `should pass if lambda raises a logical error`() {
15 | assertThat { aFunctionThatRaisesAnError() }.fails()
16 | }
17 |
18 | @Test
19 | internal fun `should fail if lambda succeeds with a value instead of failing`() {
20 | Assertions
21 | .assertThatThrownBy {
22 | assertThat { aFunctionWithContext(42) }.fails()
23 | }.isInstanceOf(AssertionError::class.java)
24 | .hasMessage(
25 | shouldFailButSucceedsWith(42).create(),
26 | )
27 | }
28 |
29 | @Test
30 | internal fun `should fail if lambda throws an exception`() {
31 | Assertions
32 | .assertThatThrownBy {
33 | assertThat { aFunctionThatThrowsAnException() }.fails()
34 | }.isInstanceOf(RuntimeException::class.java)
35 | .hasMessage("AN EXCEPTION")
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_raises_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailWithButSucceedsWith
8 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailWith.Companion.shouldFailWith
9 | import org.assertj.core.api.Assertions
10 | import org.junit.jupiter.api.Test
11 |
12 | internal class RaiseAssert_raises_Test {
13 | @Test
14 | internal fun `should pass if lambda raises a logical error`() {
15 | assertThat { aFunctionThatRaisesAnError() }.raises("LOGICAL ERROR")
16 | }
17 |
18 | @Test
19 | internal fun `should fail if lambda raises a logical error different from the expected`() {
20 | Assertions
21 | .assertThatThrownBy {
22 | assertThat { aFunctionThatRaisesAnError() }.raises("ANOTHER LOGICAL ERROR")
23 | }.isInstanceOf(AssertionError::class.java)
24 | .hasMessage(shouldFailWith("ANOTHER LOGICAL ERROR", "LOGICAL ERROR").create())
25 | }
26 |
27 | @Test
28 | internal fun `should fail if lambda succeeds with a value instead of failing`() {
29 | Assertions
30 | .assertThatThrownBy {
31 | assertThat { aFunctionWithContext(42) }.raises("LOGICAL ERROR")
32 | }.isInstanceOf(AssertionError::class.java)
33 | .hasMessage(
34 | shouldFailWithButSucceedsWith("LOGICAL ERROR", 42).create(),
35 | )
36 | }
37 |
38 | @Test
39 | internal fun `should fail if lambda throws an exception`() {
40 | Assertions
41 | .assertThatThrownBy {
42 | assertThat { aFunctionThatThrowsAnException() }.raises("LOGICAL ERROR")
43 | }.isInstanceOf(RuntimeException::class.java)
44 | .hasMessage("AN EXCEPTION")
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_result_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedButFailed.Companion.shouldSucceedButFailed
8 | import org.assertj.core.api.Assertions
9 | import org.junit.jupiter.api.Test
10 |
11 | internal class RaiseAssert_result_Test {
12 | @Test
13 | internal fun `should return a valid Object Assert if the Raise returns a result`() {
14 | assertThat { aFunctionWithContext(42) }.result().isEqualTo(42)
15 | }
16 |
17 | @Test
18 | internal fun `should fails if the Raise raised an error`() {
19 | Assertions
20 | .assertThatThrownBy { assertThat { aFunctionThatRaisesAnError() }.result() }
21 | .isInstanceOf(AssertionError::class.java)
22 | .hasMessage(shouldSucceedButFailed("LOGICAL ERROR").create())
23 | }
24 |
25 | @Test
26 | internal fun `should rethrow the inner exception`() {
27 | Assertions
28 | .assertThatThrownBy { assertThat { aFunctionThatThrowsAnException() }.result() }
29 | .isInstanceOf(RuntimeException::class.java)
30 | .hasMessage("AN EXCEPTION")
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_succeedsWith_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedWith
8 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedWithButFailed.Companion.shouldSucceedWithButFailed
9 | import org.assertj.core.api.Assertions
10 | import org.junit.jupiter.api.Test
11 |
12 | @Suppress("ktlint:standard:class-naming")
13 | internal class RaiseAssert_succeedsWith_Test {
14 | @Test
15 | internal fun `should pass if lambda succeeds with the given value`() {
16 | assertThat { aFunctionWithContext(42) }.succeedsWith(42)
17 | }
18 |
19 | @Test
20 | internal fun `should fail if lambda succeeds with a value different than the given one`() {
21 | Assertions
22 | .assertThatThrownBy {
23 | assertThat { aFunctionWithContext(42) }.succeedsWith(41)
24 | }.isInstanceOf(AssertionError::class.java)
25 | .hasMessage(RaiseShouldSucceedWith.shouldSucceedWith(41, 42).create())
26 | }
27 |
28 | @Test
29 | internal fun `should fail if lambda raises an error instead of succeeding`() {
30 | Assertions
31 | .assertThatThrownBy {
32 | assertThat { aFunctionThatRaisesAnError() }.succeedsWith(42)
33 | }.isInstanceOf(AssertionError::class.java)
34 | .hasMessage(
35 | shouldSucceedWithButFailed(42, "LOGICAL ERROR").create(),
36 | )
37 | }
38 |
39 | @Test
40 | internal fun `should fail if lambda throws an exception`() {
41 | Assertions
42 | .assertThatThrownBy {
43 | assertThat { aFunctionThatThrowsAnException() }.succeedsWith(42)
44 | }.isInstanceOf(RuntimeException::class.java)
45 | .hasMessage("AN EXCEPTION")
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/kotlin/in/rcard/assertj/arrowcore/RaiseAssert_suceeded_Test.kt:
--------------------------------------------------------------------------------
1 | package `in`.rcard.assertj.arrowcore
2 |
3 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5 | import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6 | import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7 | import `in`.rcard.assertj.arrowcore.errors.RaiseShouldSucceedButFailed.Companion.shouldSucceedButFailed
8 | import org.assertj.core.api.Assertions
9 | import org.junit.jupiter.api.Test
10 |
11 | @Suppress("ktlint:standard:class-naming")
12 | internal class RaiseAssert_suceeded_Test {
13 | @Test
14 | internal fun `should pass if lambda succeeds`() {
15 | assertThat { aFunctionWithContext(42) }.succeeds()
16 | }
17 |
18 | @Test
19 | internal fun `should fail if lambda raises an error instead of succeeding`() {
20 | Assertions
21 | .assertThatThrownBy {
22 | assertThat { aFunctionThatRaisesAnError() }.succeeds()
23 | }.isInstanceOf(AssertionError::class.java)
24 | .hasMessage(
25 | shouldSucceedButFailed("LOGICAL ERROR").create(),
26 | )
27 | }
28 |
29 | @Test
30 | internal fun `should fail if lambda throws an exception`() {
31 | Assertions
32 | .assertThatThrownBy {
33 | assertThat { aFunctionThatThrowsAnException() }.succeedsWith(42)
34 | }.isInstanceOf(RuntimeException::class.java)
35 | .hasMessage("AN EXCEPTION")
36 | }
37 | }
38 |
--------------------------------------------------------------------------------