Skip to content

Commit

Permalink
Refactor documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo committed Nov 25, 2023
1 parent dd9d1fe commit 2059ece
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 46 deletions.
3 changes: 3 additions & 0 deletions docs/_config.yml → _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ description: Fluent assertions for Result objects
current_version: 0.9.0.0
show_downloads: true
logo: https://dev.leakyabstractions.com/result/result-banner.png
exclude:
- gradle
- lib-assertj
File renamed without changes.
53 changes: 7 additions & 46 deletions docs/index.md → index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ image: https://dev.leakyabstractions.com/result/result-magic-ball.png

# Result Assertions

This library provides fluent assertions (based on [AssertJ][ASSERTJ]) to test [Result objects][RESULT].
This library provides [fluent assertions][ASSERTJ] to test [Result objects][RESULT].


## Adding Assertions to Your Build
Expand All @@ -17,62 +17,23 @@ Artifact coordinates:
- Artifact ID: `result-assertj`
- Version: `{{ site.current_version }}`

To add the dependency using [**Maven**][MAVEN], use the following:

```xml
<dependency>
<groupId>com.leakyabstractions</groupId>
<artifactId>result-assertj</artifactId>
<version>{{ site.current_version }}</version>
<scope>test</scope>
</dependency>
```

To add the dependency using [**Gradle**][GRADLE]:

```gradle
dependencies {
testImplementation 'com.leakyabstractions:result-assertj:{{ site.current_version }}'
}
```
[Maven Central Repository](https://central.sonatype.com/artifact/com.leakyabstractions/result-lazy/{{ site.current_version }})
provides snippets for different build tools to declare this dependency.


## Asserting Result objects

You can use _Result_ assertions in your tests via [`assertThat`][ASSERT_THAT]:

```java
import static com.leakyabstractions.result.assertj.ResultAssertions.assertThat;

@Test
public void should_pass() {
// Given
final int number = someMethodReturningInt();
// When
final Result<String, Integer> result = someMethodReturningResult(number);
// Then
assertThat(number).isZero();
assertThat(result).hasSuccess("OK");
}
{% include_relative lib-lazy/src/test/java/example/Example1_Test.java %}
```

If, for some reason, you cannot statically import static method [`ResultAssertions.assertThat()`][ASSERT_THAT] you can
use static method [`assertThatResult`][ASSERT_THAT_RESULT] instead:

```java
import static com.leakyabstractions.result.assertj.ResultAssert.assertThatResult;
import static org.assertj.core.api.Assertions.assertThat;

@Test
public void should_pass_too() {
// Given
final int number = anotherMethodReturningInt();
// When
final Result<String, Integer> result = anotherMethodReturningResult(number);
// Then
assertThat(number).isOne();
assertThatResult(result).hasFailure(1);
}
{% include_relative lib-lazy/src/test/java/example/Example2_Test.java %}
```


Expand Down Expand Up @@ -149,8 +110,8 @@ See the License for the specific language governing permissions and limitations

[ARTIFACTS]: https://search.maven.org/artifact/com.leakyabstractions/result-assertj/
[ASSERTJ]: https://assertj.github.io/doc/
[ASSERT_THAT]: https://dev.leakyabstractions.com/result-assertj/javadoc/{{ site.current_version }}/com/leakyabstractions/result/assertj/ResultAssertions.html#assertThat-com.leakyabstractions.result.Result-
[ASSERT_THAT_RESULT]: https://dev.leakyabstractions.com/result-assertj/javadoc/{{ site.current_version }}/com/leakyabstractions/result/assertj/ResultAssert.html#assertThatResult-com.leakyabstractions.result.Result-
[ASSERT_THAT]: https://javadoc.io/static/com.leakyabstractions/result-assertj/{{ site.current_version }}/com/leakyabstractions/result/assertj/ResultAssertions.html#assertThat-com.leakyabstractions.result.api.Result-
[ASSERT_THAT_RESULT]: https://javadoc.io/static/com.leakyabstractions/result-assertj/{{ site.current_version }}/com/leakyabstractions/result/assertj/ResultAssert.html#assertThatResult-com.leakyabstractions.result.api.Result-
[AUTHOR]: https://github.com/guillermocalvo/
[CODE_OF_CONDUCT]: https://dev.leakyabstractions.com/result/CODE_OF_CONDUCT.html
[CONTRIBUTING]: https://dev.leakyabstractions.com/result/CONTRIBUTING.html
Expand Down
1 change: 1 addition & 0 deletions lib-assertj/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ spotless {
googleJavaFormat(googleJavaFormatVersion)
eclipse().configFile rootProject.file('.formatting.xml')
importOrderFile rootProject.file('.importorder')
targetExclude("**/example/*.java")
removeUnusedImports()
}
groovyGradle {
Expand Down
31 changes: 31 additions & 0 deletions lib-assertj/src/test/java/example/Example1_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**{% if false %}*/

package example;

import com.leakyabstractions.result.api.Result;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static com.leakyabstractions.result.core.Results.success;

/** {% elsif true %}Import result assertions */
import static com.leakyabstractions.result.assertj.ResultAssertions.assertThat;

/*{% endif %}{% if false %}*/

@DisplayName("Example1")
class Example1_Test {

/** {% elsif true %} Use result assertions */
@Test
public void should_pass() {
// Given
final int zero = 0;
// When
final Result<Integer, String> result = success(zero);
// Then
assertThat(zero).isZero();
assertThat(result).hasSuccess(zero);
} // End{% endif %}{% if false %}

}
// {% endif %}
32 changes: 32 additions & 0 deletions lib-assertj/src/test/java/example/Example2_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**{% if false %}*/

package example;

import com.leakyabstractions.result.api.Result;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static com.leakyabstractions.result.core.Results.success;

/** {% elsif true %}Import result assertions */
import static com.leakyabstractions.result.assertj.ResultAssert.assertThatResult;
import static org.assertj.core.api.Assertions.assertThat;

/*{% endif %}{% if false %}*/

@DisplayName("Example2")
class Example2_Test {

/** {% elsif true %} Use result assertions */
@Test
public void should_pass_too() {
// Given
final int zero = 0;
// When
final Result<Integer, String> result = success(zero);
// Then
assertThat(zero).isZero();
assertThatResult(result).hasSuccess(zero);
} // End{% endif %}{% if false %}

}
// {% endif %}

0 comments on commit 2059ece

Please sign in to comment.