Add test for exceptions in FutureUtils.transformAsync. (#17106) (#17197)

Adds an additional test case to FutureUtilsTest.

Co-authored-by: Gian Merlino <gianmerlino@gmail.com>
This commit is contained in:
Kashif Faraz 2024-09-30 20:36:56 +05:30 committed by GitHub
parent f4ad5d001b
commit 25f2447fb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 0 deletions

View File

@ -243,6 +243,32 @@ public class FutureUtilsTest
);
}
@Test
public void test_transformAsync_exceptionInFunction()
{
final ListenableFuture<Object> f = FutureUtils.transformAsync(
Futures.immediateFuture("x"),
s -> {
throw new ISE("error!");
}
);
final ExecutionException e = Assert.assertThrows(
ExecutionException.class,
f::get
);
MatcherAssert.assertThat(
e,
ThrowableCauseMatcher.hasCause(CoreMatchers.instanceOf(ISE.class))
);
MatcherAssert.assertThat(
e,
ThrowableCauseMatcher.hasCause(ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("error!")))
);
}
@Test
public void test_coalesce_allOk() throws Exception
{