I’m happy to present you a new release of assertj-vavr. This version, i.e., v0.1.0, uses Vavr v0.10.0 and adds support of more types from this library.

Below you can find the information about what’s new.

Enhancements:

Maps support

One of the missing parts was a possibility to make assertions on instances ofio.vavr.colleciton.Map. The new version provides basic checks.
Among checks of its emptiness, equality, and size, you can run checks for contained entries, keys, and values. Here’s a sample:

final Map<String, String> cars = HashMap.of(
"electric", "Tesla Model 3",
"gasoline", "Audi A4 Quattro",
"diesel", "Peugeot 308SW"
);
final Map<String, String> expected = cars;
assertThat(cars)
.isNotEmpty()
.hasSize(3)
.isEqualTo(expected) // assuming it contains the same values as cars
.contains(
Tuple.of("gasoline", "Audi A4 Quattro"), Tuple.of("diesel", "Peugeot 308SW")
)
.containsEntry("electric", "Tesla Model 3")
.containsAnyOf(
Tuple.of("nuclear", "DeLorean DMC-12"), Tuple.of("diesel", "Peugeot 308SW")
)
.containsAllEntriesOf(
List.of(Tuple.of("gasoline", "Audi A4 Quattro"),
Tuple.of("diesel", "Peugeot 308SW"))
)
.doesNotContain(Tuple.of("nuclear", "DeLorean DMC-12"))
.doesNotContainEntry("nuclear", "DeLorean DMC-12");

Validation support

Another missing part in the library was assertions for io.vavr.control.Validation. Now, you can check the following:

Validation<String, String> valid = Validation.valid(data_is_valid);
Validation<String, String> invalid = Validation.invalid(data_is_invalid);
assertThat(valid)
.isValid()
.containsValid(data_is_valid)
.containsValidInstanceOf(String.class)
.containsValidSame(data_is_valid);
assertThat(invalid)
.isInvalid()
.containsInvalid(data_is_invalid)
.containsInvalidInstanceOf(String.class)
.containsInvalidSame(data_is_invalid);

Lazy support

Another nice-to-have thing is assertions for lazily evaluated values. With the new release, we can check whether a given computation is evaluated or not.

Lazy<Car> newCar = Lazy.of(() -> new Car("Tesla", "Model 3"));
assertThat(newCar).isNotEvaluated();
Car tesla = newCar.get();
assertThat(newCar).isEvaluated();

Try assertions

While io.vavr.control.Try is already supported since the first release, we have added simple checks to see is it a success or a failure.

Try<String> attempt = Try.success("yay!");
assertThat(attempt).isSuccess();
Try<String> failedAttempt = Try.failure(new IllegalStateException());
assertThat(failedAttempt).isFailure();

Bugfixes

NPEs prevention

The recent version of the library fixes a bug of asserting whether value contained by Option/Try/Either is null. While you can use such value in those types, assertj-vavr provided no support for checking this. Now, we have fixed it.

assertThat(Option.some(null)).contains(null);
assertThat(Try.success(null)).contains(null);
assertThat(Either.right(null)).containsOnRight(null);
assertThat(Either.left(null)).containsOnLeft(null);

Wrap up

The work above is the combined effort of a group of people: Kamil Szymański, Alex Dukhno, Grzegorz Piwowarek and my humble person.

If you have any ideas about what we should add in future releases of the library, let us know (comment below, contact me, create a new issue or catch me on JVM Poland Slack). And, of course, your contribution to the project is more than welcome!

Image by kkw0812 from Pixabay

Categories: testing

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.