diff --git a/docs/_config.yml b/_config.yml similarity index 85% rename from docs/_config.yml rename to _config.yml index 3b7683f..3fb1301 100644 --- a/docs/_config.yml +++ b/_config.yml @@ -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 diff --git a/docs/badge.json b/badge.json similarity index 100% rename from docs/badge.json rename to badge.json diff --git a/docs/index.md b/index.md similarity index 68% rename from docs/index.md rename to index.md index f14e1d1..9a50140 100644 --- a/docs/index.md +++ b/index.md @@ -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 @@ -17,24 +17,8 @@ Artifact coordinates: - Artifact ID: `result-assertj` - Version: `{{ site.current_version }}` -To add the dependency using [**Maven**][MAVEN], use the following: - -```xml - - com.leakyabstractions - result-assertj - {{ site.current_version }} - test - -``` - -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 @@ -42,37 +26,14 @@ dependencies { 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 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 result = anotherMethodReturningResult(number); - // Then - assertThat(number).isOne(); - assertThatResult(result).hasFailure(1); -} +{% include_relative lib-lazy/src/test/java/example/Example2_Test.java %} ``` @@ -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 diff --git a/lib-assertj/spotless.gradle b/lib-assertj/spotless.gradle index 96d3e68..5e560ee 100644 --- a/lib-assertj/spotless.gradle +++ b/lib-assertj/spotless.gradle @@ -5,6 +5,7 @@ spotless { googleJavaFormat(googleJavaFormatVersion) eclipse().configFile rootProject.file('.formatting.xml') importOrderFile rootProject.file('.importorder') + targetExclude("**/example/*.java") removeUnusedImports() } groovyGradle { diff --git a/lib-assertj/src/test/java/example/Example1_Test.java b/lib-assertj/src/test/java/example/Example1_Test.java new file mode 100644 index 0000000..3288320 --- /dev/null +++ b/lib-assertj/src/test/java/example/Example1_Test.java @@ -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 result = success(zero); + // Then + assertThat(zero).isZero(); + assertThat(result).hasSuccess(zero); +} // End{% endif %}{% if false %} + +} +// {% endif %} \ No newline at end of file diff --git a/lib-assertj/src/test/java/example/Example2_Test.java b/lib-assertj/src/test/java/example/Example2_Test.java new file mode 100644 index 0000000..8154a52 --- /dev/null +++ b/lib-assertj/src/test/java/example/Example2_Test.java @@ -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 result = success(zero); + // Then + assertThat(zero).isZero(); + assertThatResult(result).hasSuccess(zero); +} // End{% endif %}{% if false %} + +} +// {% endif %} \ No newline at end of file