Fluent Assertions for Result Objects

Result-AssertJ provides assertions to test Result objects

Result Assertions

This library provides fluent assertions to test Result objects.

Fluent assertions enhance the readability and expressiveness of your unit tests. These assertions are based on AssertJ, an open-source Java library that offers a fluent API for writing assertions in test cases.

AssertJ features a comprehensive and intuitive set of strongly-typed assertions for unit testing. It is a popular choice among Java developers due to its effective features and compatibility with various testing frameworks like JUnit and TestNG.

Adding Assertions to Your Build

Artifact coordinates:

Maven Central Repository provides snippets for different build tools to declare this dependency.

Asserting Result objects

You can use ResultAssertions::assertThat in your tests to create fluent assertions for result objects.

/** Import result assertions */
import static com.leakyabstractions.result.assertj.ResultAssertions.assertThat;

/* Use result assertions */
@Test
void testAssertThat() {
  // Given
  final int zero = 0;
  // When
  final Result<Integer, String> result = success(zero);
  // Then
  assertThat(zero).isZero();
  assertThat(result).hasSuccess(zero);
} // End

If, for any reason, you cannot statically import assertThat, you can use ResultAssert::assertThatResult instead.

/** Import result assertions */
import static com.leakyabstractions.result.assertj.ResultAssert.assertThatResult;
import static org.assertj.core.api.Assertions.assertThat;

/* Use result assertions */
@Test
void testAssertThatResult() {
  // Given
  final int zero = 0;
  // When
  final Result<Integer, String> result = success(zero);
  // Then
  assertThat(zero).isZero();
  assertThatResult(result).hasSuccess(zero);
} // End

The full source code for the examples is available on GitHub.

Additional Info

Releases

This library adheres to Pragmatic Versioning.

Artifacts are available in Maven Central.

Javadoc

Here you can find the full Javadoc documentation.

Looking for Support?

We’d love to help. Check out the support guidelines.

Contributions Welcome

If you’d like to contribute to this project, please start here.

Code of Conduct

This project is governed by the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.

Author

Copyright 2025 Guillermo Calvo.

License

This library is licensed under the Apache License, Version 2.0 (the “License”); you may not use it except in compliance with the License.

You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Permitted:

Required:

Forbidden: