Verify invalid durations in Uni.await().atMost
package io.smallrye.mutiny.operators;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.*;
import static org.awaitility.Awaitility.await;
import java.io.IOException;
@@ -37,8 +36,6 @@ public class UniAwaitTest {
}
}
- // Uni.createFrom().failure before onTimeout
-
@Test(timeOut = 1000)
public void testAwaitingOnAnAsyncUni() {
assertThat(
@@ -123,4 +120,18 @@ public class UniAwaitTest {
Uni.createFrom().nothing().await().asOptional().atMost(Duration.ofMillis(10));
}
+ @Test
+ public void testInvalidDurations() {
+ Uni<Integer> one = Uni.createFrom().item(1);
+
+ // Null duration means infinite
+ assertThat(one.await().atMost(null)).isEqualTo(1);
+
+ assertThatThrownBy(() -> one.await().atMost(Duration.ofMillis(-2000)))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("duration");
+
+ assertThatThrownBy(() -> one.await().atMost(Duration.ofSeconds(0)))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("duration");
+ }
+
}
