@@ -790,6 +790,35 @@ public void untilAsserted(final ThrowingRunnable assertion) {
790790 until (new AssertionCondition (assertion , generateConditionSettings ()));
791791 }
792792
793+ /**
794+ * Await until a callable returns a value that when passed to a {@link java.util.function.Consumer} ends without throwing an exception. E.g. with Java 8:
795+ * <p> </p>
796+ * <pre>
797+ * public class MyBean {
798+ *
799+ * public String myFunction() {
800+ * // Imagine stuff being executed in asynchrinously here and the result of this
801+ * // operation is a string called "my value"
802+ * return "my value"
803+ * }
804+ * }
805+ *
806+ * // Then in your test you can wait for the "myFunction" to return "my value"
807+ * await().untilAsserted(myBean::myFunction, value -> Assertions.assertThat(value).isEqualTo("my value"));
808+ * </pre>
809+ *
810+ * @param supplier the supplier that is responsible for executing the assertion and throwing AssertionError on failure.
811+ * @param assertConsumer The consumer that will assert that the supplied value is correct, or throw an exception.
812+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
813+ * @since 4.3.2
814+ */
815+ public <T > void untilAsserted (final Callable <T > supplier , final Consumer <? super T > assertConsumer ) {
816+ untilAsserted (() -> {
817+ T value = supplier .call ();
818+ assertConsumer .accept (value );
819+ });
820+ }
821+
793822 /**
794823 * Await until a Atomic variable has a value matching the specified
795824 * {@link org.hamcrest.Matcher}. E.g.
@@ -805,7 +834,23 @@ public void untilAsserted(final ThrowingRunnable assertion) {
805834 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
806835 */
807836 public Integer untilAtomic (final AtomicInteger atomic , final Matcher <? super Integer > matcher ) {
808- return until (new CallableHamcrestCondition <>(() -> (Integer ) atomic .get (), matcher , generateConditionSettings ()));
837+ return until (new CallableHamcrestCondition <>(atomic ::get , matcher , generateConditionSettings ()));
838+ }
839+
840+ /**
841+ * Await until a Atomic integer is asserted by the {@code matcher} consumer
842+ * E.g.
843+ * <p> </p>
844+ * <pre>
845+ * await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123));
846+ * </pre>
847+ *
848+ * @param atomic the atomic variable
849+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
850+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
851+ */
852+ public void untilAtomic (final AtomicInteger atomic , final Consumer <? super Integer > matcher ) {
853+ untilAsserted (atomic ::get , matcher );
809854 }
810855
811856 /**
@@ -823,7 +868,23 @@ public Integer untilAtomic(final AtomicInteger atomic, final Matcher<? super Int
823868 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
824869 */
825870 public Long untilAtomic (final AtomicLong atomic , final Matcher <? super Long > matcher ) {
826- return until (new CallableHamcrestCondition <>(() -> (Long ) atomic .get (), matcher , generateConditionSettings ()));
871+ return until (new CallableHamcrestCondition <>(atomic ::get , matcher , generateConditionSettings ()));
872+ }
873+
874+ /**
875+ * Await until a Atomic long is asserted by the {@code matcher} consumer
876+ * E.g.
877+ * <p> </p>
878+ * <pre>
879+ * await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123L));
880+ * </pre>
881+ *
882+ * @param atomic the atomic variable
883+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
884+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
885+ */
886+ public void untilAtomic (final AtomicLong atomic , final Consumer <? super Long > matcher ) {
887+ untilAsserted (atomic ::get , matcher );
827888 }
828889
829890 /**
@@ -840,7 +901,23 @@ public Long untilAtomic(final AtomicLong atomic, final Matcher<? super Long> mat
840901 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
841902 */
842903 public void untilAtomic (final AtomicBoolean atomic , final Matcher <? super Boolean > matcher ) {
843- until (new CallableHamcrestCondition <>(() -> (Boolean ) atomic .get (), matcher , generateConditionSettings ()));
904+ until (new CallableHamcrestCondition <>(atomic ::get , matcher , generateConditionSettings ()));
905+ }
906+
907+ /**
908+ * Await until a AtomicBoolean is asserted by the {@code matcher} consumer
909+ * E.g.
910+ * <p> </p>
911+ * <pre>
912+ * await().untilAtomic(myAtomicBoolean, value -> Assertions.assertThat(value).isTrue());
913+ * </pre>
914+ *
915+ * @param atomic the atomic variable
916+ * @param matcher the matcher The consumer that validates that the atomic boolean value is correct, or throws an exception
917+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
918+ */
919+ public void untilAtomic (final AtomicBoolean atomic , final Consumer <? super Boolean > matcher ) {
920+ untilAsserted (atomic ::get , matcher );
844921 }
845922
846923 /**
@@ -875,7 +952,23 @@ public void untilFalse(final AtomicBoolean atomic) {
875952 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
876953 */
877954 public void untilAdder (final LongAdder adder , final Matcher <? super Long > matcher ) {
878- until (new CallableHamcrestCondition <>(() -> (Long ) adder .longValue (), matcher , generateConditionSettings ()));
955+ until (new CallableHamcrestCondition <>(adder ::longValue , matcher , generateConditionSettings ()));
956+ }
957+
958+ /**
959+ * Await until a LongAdder is asserted by the {@code matcher} consumer
960+ * E.g.
961+ * <p> </p>
962+ * <pre>
963+ * await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
964+ * </pre>
965+ *
966+ * @param adder the atomic variable
967+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
968+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
969+ */
970+ public void untilAdder (final LongAdder adder , final Consumer <? super Long > matcher ) {
971+ untilAsserted (adder ::longValue , matcher );
879972 }
880973
881974 /**
@@ -890,7 +983,23 @@ public void untilAdder(final LongAdder adder, final Matcher<? super Long> matche
890983 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
891984 */
892985 public void untilAdder (final DoubleAdder adder , final Matcher <? super Double > matcher ) {
893- until (new CallableHamcrestCondition <>(() -> (Double ) adder .doubleValue (), matcher , generateConditionSettings ()));
986+ until (new CallableHamcrestCondition <>(adder ::doubleValue , matcher , generateConditionSettings ()));
987+ }
988+
989+ /**
990+ * Await until a DoubleAdder is asserted by the {@code matcher} consumer
991+ * E.g.
992+ * <p> </p>
993+ * <pre>
994+ * await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
995+ * </pre>
996+ *
997+ * @param adder the atomic variable
998+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
999+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
1000+ */
1001+ public void untilAdder (final DoubleAdder adder , final Consumer <? super Double > matcher ) {
1002+ untilAsserted (adder ::doubleValue , matcher );
8941003 }
8951004
8961005 /**
@@ -905,7 +1014,23 @@ public void untilAdder(final DoubleAdder adder, final Matcher<? super Double> ma
9051014 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
9061015 */
9071016 public void untilAccumulator (final LongAccumulator accumulator , final Matcher <? super Long > matcher ) {
908- until (new CallableHamcrestCondition <>(() -> (Long ) accumulator .longValue (), matcher , generateConditionSettings ()));
1017+ until (new CallableHamcrestCondition <>(accumulator ::longValue , matcher , generateConditionSettings ()));
1018+ }
1019+
1020+ /**
1021+ * Await until a LongAccumulator is asserted by the {@code matcher} consumer
1022+ * E.g.
1023+ * <p> </p>
1024+ * <pre>
1025+ * await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
1026+ * </pre>
1027+ *
1028+ * @param accumulator the atomic variable
1029+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
1030+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
1031+ */
1032+ public void untilAccumulator (final LongAccumulator accumulator , final Consumer <? super Long > matcher ) {
1033+ untilAsserted (accumulator ::longValue , matcher );
9091034 }
9101035
9111036 /**
@@ -920,7 +1045,23 @@ public void untilAccumulator(final LongAccumulator accumulator, final Matcher<?
9201045 * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
9211046 */
9221047 public void untilAccumulator (final DoubleAccumulator accumulator , final Matcher <? super Double > matcher ) {
923- until (new CallableHamcrestCondition <>(() -> (Double ) accumulator .doubleValue (), matcher , generateConditionSettings ()));
1048+ until (new CallableHamcrestCondition <>(accumulator ::doubleValue , matcher , generateConditionSettings ()));
1049+ }
1050+
1051+ /**
1052+ * Await until a DoubleAccumulator is asserted by the {@code matcher} consumer
1053+ * E.g.
1054+ * <p> </p>
1055+ * <pre>
1056+ * await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
1057+ * </pre>
1058+ *
1059+ * @param accumulator the atomic variable
1060+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
1061+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
1062+ */
1063+ public void untilAccumulator (final DoubleAccumulator accumulator , final Consumer <? super Double > matcher ) {
1064+ untilAsserted (accumulator ::doubleValue , matcher );
9241065 }
9251066
9261067 /**
@@ -942,6 +1083,23 @@ public <V> V untilAtomic(final AtomicReference<V> atomic, final Matcher<? super
9421083 return until (new CallableHamcrestCondition <>(atomic ::get , matcher , generateConditionSettings ()));
9431084 }
9441085
1086+ /**
1087+ * Await until a Atomic variable is asserted by the {@code matcher} consumer
1088+ * E.g.
1089+ * <p> </p>
1090+ * <pre>
1091+ * await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo("something"));
1092+ * </pre>
1093+ *
1094+ * @param atomic the atomic variable
1095+ * @param matcher the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
1096+ * @param <V> a V object.
1097+ * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period.
1098+ */
1099+ public <V > void untilAtomic (final AtomicReference <V > atomic , final Consumer <? super V > matcher ) {
1100+ untilAsserted (atomic ::get , matcher );
1101+ }
1102+
9451103 /**
9461104 * Await until a {@link java.util.concurrent.Callable} returns <code>true</code>. This is method
9471105 * is not as generic as the other variants of "until" but it allows for a
@@ -1026,5 +1184,4 @@ private Duration definePollDelay(Duration pollDelay, PollInterval pollInterval)
10261184 }
10271185 return pollDelayToUse ;
10281186 }
1029-
1030- }
1187+ }
0 commit comments