diff --git a/build.gradle.kts b/build.gradle.kts index b5f7b46..163357a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,8 @@ plugins { id("nebula.maven-scm") version "18.4.0" id("nebula.contacts") version "6.0.0" id("nebula.info-scm") version "11.3.3" + id("nebula.source-jar") version "18.4.0" + id("nebula.javadoc-jar") version "18.4.0" id("tylerthrailkill.nebula-mit-license") version "0.0.3" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" diff --git a/src/main/java/com/webfleet/assertj/AsyncAssert.java b/src/main/java/com/webfleet/assertj/AsyncAssert.java index c180a25..a38688b 100644 --- a/src/main/java/com/webfleet/assertj/AsyncAssert.java +++ b/src/main/java/com/webfleet/assertj/AsyncAssert.java @@ -15,27 +15,54 @@ public interface AsyncAssert { /** - * Awaits until all assertions are passed or timeout is exceeded. + * Awaits, until all configured assertions are passed or timeout is exceeded. + *

* Assertions are configured in lambda consumer of {@link SoftAssertions} object on each check. * The checks are executed periodically with check interval delay configured with {@link AsyncAssert#withCheckInterval} method. * After exceeding timeout {@link AssertionError} will be thrown with failures from last assertion check. - * - *


+     * 

+ * Example usage: + *

{@code
      * awaitAtMostOneSecond().untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      *     async.assertThat(isDone()).isTrue();
      * });
-     * 
+ * }
* * @param assertionsConfigurer lambda consumer configuring {@link SoftAssertions} object */ void untilAssertions(Consumer assertionsConfigurer); /** - * Configures assertion to use give mutex object for check interval wait logic. - * + * Configures assertion to use given mutex object for check interval wait logic. + *

* In multi-thread applications, the mutex object can be used to notify the other thread about state change. * For asynchronous assertion, the mutex object can be used to reduce the wait time between checks with {@link Object#notifyAll()} call. + *

+ * Example usage: + *

{@code
+     * // given
+     * var condition = new AtomicBoolean();
+     * var waitMutex = new Object();
+     * var executor = Executors.newSingleThreadExecutor();
+     *
+     * // when
+     * executor.execute(() -> {
+     *     // ... asynchronous logic
+     *     condition.set(true);
+     *     // notify after done
+     *     synchronized (waitMutex) {
+     *         waitMutex.notifyAll();
+     *     }
+     * });
+     *
+     * // then
+     * awaitAtMostOneSecond()
+     *     .usingWaitMutex(waitMutex)
+     *     .untilAssertions(async -> {
+     *         async.assertThat(condition).isTrue();
+     *     });
+     * }
* * @param waitMutex mutex object * @return new {@link AsyncAssert} using given wait mutex @@ -45,6 +72,15 @@ public interface AsyncAssert /** * Configures the interval to be waited between assertions checks. * The interval must be greater than zero and lower than timeout. + *

+ * Example usage: + *

{@code
+     * awaitAtMostOneSecond()
+     *     .withCheckInterval(Duration.ofMillis(500))
+     *     .untilAssertions(async -> {
+     *         async.assertThat(condition).isTrue();
+     *     });
+     * }
* * @param checkInterval check interval * @return new {@link AsyncAssert} with set check interval @@ -54,6 +90,15 @@ public interface AsyncAssert /** * Configures the interval to be waited between assertions checks. * The interval must be greater than zero and lower than timeout. + *

+ * Example usage: + *

{@code
+     * awaitAtMostOneSecond()
+     *     .withCheckInterval(500, TimeUnit.MILLISECONDS)
+     *     .untilAssertions(async -> {
+     *         async.assertThat(condition).isTrue();
+     *     });
+     * }
* * @param checkInterval check interval * @param timeUnit the time unit of the check interval diff --git a/src/main/java/com/webfleet/assertj/AsyncAssertions.java b/src/main/java/com/webfleet/assertj/AsyncAssertions.java index b40754d..1b70dc8 100644 --- a/src/main/java/com/webfleet/assertj/AsyncAssertions.java +++ b/src/main/java/com/webfleet/assertj/AsyncAssertions.java @@ -9,20 +9,21 @@ /** - * Entry point for asynchronous assertions. + * Entry point for building asynchronous assertions. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class AsyncAssertions { /** - * Returns evaluator of asynchronous assertions with given timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with given timeout.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMost(Duration.ofSeconds(5)).untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * * @param timeout timeout for the assertions * @return {@link AsyncAssert} @@ -33,16 +34,17 @@ public static AsyncAssert awaitAtMost(@NonNull final Duration timeout) } /** - * Returns evaluator of asynchronous assertions with given timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with given timeout value and time unit.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMost(5, SECONDS).untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * - * @param timeout timeout value for the assertions + * @param timeout timeout value for the assertion * @param timeUnit timeout unit * @return {@link AsyncAssert} */ @@ -52,14 +54,15 @@ public static AsyncAssert awaitAtMost(final long timeout, @NonNull final TimeUni } /** - * Returns evaluator of asynchronous assertions with 1 second timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with 1 second timeout.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMostOneSecond().untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * * @return {@link AsyncAssert} */ @@ -69,14 +72,15 @@ public static AsyncAssert awaitAtMostOneSecond() } /** - * Returns evaluator of asynchronous assertions with 2 seconds timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with 2 seconds timeout.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMostTwoSeconds().untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * * @return {@link AsyncAssert} */ @@ -86,14 +90,15 @@ public static AsyncAssert awaitAtMostTwoSeconds() } /** - * Returns evaluator of asynchronous assertions with 5 seconds timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with 5 seconds timeout.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMostFiveSeconds().untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * * @return {@link AsyncAssert} */ @@ -103,14 +108,15 @@ public static AsyncAssert awaitAtMostFiveSeconds() } /** - * Returns evaluator of asynchronous assertions with 15 seconds timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with 15 seconds timeout.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMostFifteenSeconds().untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * * @return {@link AsyncAssert} */ @@ -120,14 +126,15 @@ public static AsyncAssert awaitAtMostFifteenSeconds() } /** - * Returns evaluator of asynchronous assertions with 30 seconds timeout. - * See {@link AsyncAssert} for more details. - * - *

+     * Builds asynchronous assertion with 30 seconds timeout.
+     * 

+ * Example usage: + *

{@code
      * awaitAtMostThirtySeconds().untilAssertions(async -> {
      *     async.assertThat(getValue()).isEqualTo(expected);
      * });
-     * 
+ * }
+ * See {@link AsyncAssert} for more details. * * @return {@link AsyncAssert} */