|
7 | 7 |
|
8 | 8 | # assertj-arrow-core |
9 | 9 |
|
10 | | -This project provides a set of [AssertJ](https://assertj.github.io/doc/) assertions for the [Arrow](https://arrow-kt.io/) library. In detail, the project provides assertions for the following Arrow types: |
| 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: |
11 | 12 |
|
12 | 13 | - [x] `Either<E, A>` |
13 | 14 | - [x] `Option<A>` |
14 | 15 | - [x] `Raise<E>.() -> A` |
15 | 16 |
|
16 | | -Maybe you're asking yourself: "Why do we need AssertJ assertions for Arrow types?". The answer is simple: We often use Kotlin and Arrow Kt inside a Java project using Spring Boot. In this case, we already have AssertJ in the classpath as an assertion library. So, why not use it to assert Arrow types? |
| 17 | +Maybe you're asking yourself: "Why do we need AssertJ assertions for Arrow types?". The answer is simple: We often use |
| 18 | +Kotlin and Arrow Kt inside a Java project using Spring Boot. In this case, we already have AssertJ in the classpath as |
| 19 | +an assertion library. So, why not use it to assert Arrow types? |
17 | 20 |
|
18 | 21 | ## Usage |
19 | 22 |
|
20 | 23 | The library is available on Maven Central. To use it, add the following dependency to your `pom.xml` file: |
21 | 24 |
|
22 | 25 | ```xml |
| 26 | + |
23 | 27 | <dependency> |
24 | | - <groupId>in.rcard</groupId> |
25 | | - <artifactId>assertj-arrow-core</artifactId> |
26 | | - <version>1.1.0</version> |
27 | | - <scope>test</scope> |
| 28 | + <groupId>in.rcard</groupId> |
| 29 | + <artifactId>assertj-arrow-core</artifactId> |
| 30 | + <version>1.1.0</version> |
| 31 | + <scope>test</scope> |
28 | 32 | </dependency> |
29 | 33 | ``` |
| 34 | + |
| 35 | +Otherwise, if you're using Gradle, add the following dependency to your `build.gradle.kts` file: |
| 36 | + |
| 37 | +```kotlin |
| 38 | +testImplementation("in.rcard:assertj-arrow-core:1.1.0") |
| 39 | +``` |
| 40 | + |
| 41 | +## Assertions Guide |
| 42 | + |
| 43 | +This section describes the assertions provided by the `assertj-arrow-core` library. |
| 44 | + |
| 45 | +### `Option<A>` |
| 46 | + |
| 47 | +Use the `in.rcard.assertj.arrowcore.OptionAssert` class as an entry point to assert `Option<A>` instances. |
| 48 | + |
| 49 | +| Assertions | Description | |
| 50 | +|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 51 | +| `isEmpty` | Verifies that the actual `Option` is empty. | |
| 52 | +| `contains` | Verifies that the actual `Option` contains the given value. | |
| 53 | +| `containsInstanceOf` | Verifies that the actual `Option` contains a value that is an instance of the argument. | |
| 54 | +| `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. | |
| 55 | +| `isDefined` | Verifies that there is a value present in the actual `Option`. | |
| 56 | + |
| 57 | +### `Either<E, A>` |
| 58 | + |
| 59 | +Use the `in.rcard.assertj.arrowcore.EitherAssert` class as an entry point to assert `Either<E, A>` instances. |
| 60 | + |
| 61 | +| Assertions | Description | |
| 62 | +|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 63 | +| `isRight` | Verifies that the actual `Either` is right. | |
| 64 | +| `isLeft` | Verifies that the actual `Either` is left. | |
| 65 | +| `containsOnRight` | Verifies that the actual `Either` is `Either.Right` and contains the given value. | |
| 66 | +| `containsRightInstanceOf` | Verifies that the actual right-sided `Either` contains a value that is an instance of the argument. | |
| 67 | +| `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. | |
| 68 | +| `containsOnLeft` | Verifies that the actual `Either` is `Either.Left` and contains the given value. | |
| 69 | +| `containsLeftInstanceOf` | Verifies that the actual left-sided `Either` contains a value that is an instance of the argument. | |
| 70 | +| `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. | |
| 71 | + |
| 72 | +### `Raise<E>.() -> A` |
| 73 | + |
| 74 | +Use the `in.rcard.assertj.arrowcore.RaiseAssert` class as an entry point to assert `Raise<E>.() -> A` instances. There |
| 75 | +are many different entry points, all of them available boh for regular and `suspend` functions: |
| 76 | + |
| 77 | +| Entry Point | Description | |
| 78 | +|----------------------|-----------------------------------------------------------------------------------------------------------------------------| |
| 79 | +| `assertThat` | Entry point to assert a `Raise<E>.() -> A` instance. | |
| 80 | +| `assertThatThrownBy` | Verifies that the function in the `Raise` context throws an exception and let chaining assertion on the thrown exception | |
| 81 | +| `assertThatRaisedBy` | Verifies that the function in the `Raise` context raises a logic-typed error and let chaining assertion on the raised error | |
| 82 | + |
| 83 | +The available assertions are: |
| 84 | + |
| 85 | +| Assertions | Description | |
| 86 | +|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 87 | +| `succeedsWith` | Verifies that the function in the `Raise` context succeeds with the given value. | |
| 88 | +| `succeeds` | Verifies that the function in the `Raise` context succeeded. No check on the value returned by the function is performed. | |
| 89 | +| `raises` | Verifies that the function in the Raise context fails with the given error. | |
| 90 | +| `fails` | Verifies that the function in the Raise context fails, no matter the type of the logical error. | |
| 91 | +| `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. | |
| 92 | +| `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. | |
0 commit comments