Result-AssertJ provides assertions to test Result objects
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.
Artifact coordinates:
com.leakyabstractions
result-assertj
1.0.1.1
Maven Central Repository provides snippets for different build tools to declare this dependency.
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.
This library adheres to Pragmatic Versioning.
Artifacts are available in Maven Central.
Here you can find the full Javadoc documentation.
We’d love to help. Check out the support guidelines.
If you’d like to contribute to this project, please start here.
This project is governed by the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
Copyright 2025 Guillermo Calvo.
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: