Skip to content

Commit dd8841f

Browse files
committed
test: update test case for failure mSupply
1 parent eeb7e21 commit dd8841f

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed

cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class CompletableFutureUtilsTest {
4141

4242
////////////////////////////////////////////////////////////
4343
// region## Multi-Actions(M*) Methods(create by actions)
44-
////////////////////////////////////////////////////////////
44+
45+
/// /////////////////////////////////////////////////////////
4546

4647
@Test
4748
void test_mSupply() throws Exception {
@@ -85,13 +86,33 @@ void test_mSupply() throws Exception {
8586

8687
@Test
8788
void test_mSupply__failure() throws Exception {
88-
assertSame(rte, assertThrowsExactly(ExecutionException.class, () ->
89-
// allResultsOf: the ex of first given cf argument win.
90-
// ❗dependent on the implementation behavior of `CF.allOf`️
91-
mSupplyFailFastAsync(() -> 42, () -> {
92-
throw rte;
93-
}).get()
94-
).getCause());
89+
RuntimeException rte1 = new RuntimeException("rte1");
90+
RuntimeException rte2 = new RuntimeException("rte2");
91+
92+
assertSame(rte1, assertThrowsExactly(ExecutionException.class, () -> mSupplyFailFastAsync(
93+
testExecutor,
94+
() -> 42,
95+
supplyLater(rte1, SHORT_WAIT_MS),
96+
supplyLater(rte2, LONG_WAIT_MS)
97+
).get()).getCause());
98+
assertSame(rte2, assertThrowsExactly(ExecutionException.class, () -> mSupplyFailFastAsync(
99+
testExecutor,
100+
() -> 42,
101+
supplyLater(rte1, LONG_WAIT_MS),
102+
supplyLater(rte2, SHORT_WAIT_MS)).get()).getCause());
103+
assertEquals(42, mSupplyAnySuccessAsync(
104+
testExecutor,
105+
() -> 42,
106+
supplyLater(rte1, SHORT_WAIT_MS),
107+
supplyLater(rte2, LONG_WAIT_MS)
108+
).get());
109+
110+
assertEquals(Tuple3.of(42, null, null), mSupplyMostSuccessTupleAsync(
111+
testExecutor, LONG_WAIT_MS, MILLISECONDS,
112+
() -> 42,
113+
supplyLater(rte1, SHORT_WAIT_MS),
114+
supplyLater(rte2, LONG_WAIT_MS)
115+
).get());
95116
}
96117

97118
@Test
@@ -120,7 +141,8 @@ void test_mRun() throws Exception {
120141
// endregion
121142
////////////////////////////////////////////////////////////
122143
// region## Multi-Actions-Tuple(MTuple*) Methods(create by actions)
123-
////////////////////////////////////////////////////////////
144+
145+
/// /////////////////////////////////////////////////////////
124146

125147
@Test
126148
void test_mSupplyMostSuccessTupleAsync() throws Exception {
@@ -233,7 +255,8 @@ void test_mSupplyAllSuccessTupleAsync() throws Exception {
233255
// endregion
234256
////////////////////////////////////////////////////////////
235257
// region## allOf* Methods(including mostSuccessResultsOf)
236-
////////////////////////////////////////////////////////////
258+
259+
/// /////////////////////////////////////////////////////////
237260

238261
@Test
239262
void test_allOf_methods__success__trivial_case() throws Exception {
@@ -591,7 +614,8 @@ void test_mostOf_wontModifyInputCf() throws Exception {
591614
// endregion
592615
////////////////////////////////////////////////////////////
593616
// region## anyOf* Methods
594-
////////////////////////////////////////////////////////////
617+
618+
/// /////////////////////////////////////////////////////////
595619

596620
@Test
597621
void test_anyOf_anySuccessOf__trivial_case() throws Exception {
@@ -817,7 +841,8 @@ void test_anyOf__concurrent() throws Exception {
817841
// endregion
818842
////////////////////////////////////////////////////////////
819843
// region## allTupleOf*/mostSuccessTupleOf Methods
820-
////////////////////////////////////////////////////////////
844+
845+
/// /////////////////////////////////////////////////////////
821846

822847
@Test
823848
void test_allTupleOf() throws Exception {
@@ -966,7 +991,8 @@ void test_mostSuccessTupleOf() throws Exception {
966991
// endregion
967992
////////////////////////////////////////////////////////////
968993
// region## Immediate Value Argument Factory Methods(backport methods)
969-
////////////////////////////////////////////////////////////
994+
995+
/// /////////////////////////////////////////////////////////
970996

971997
@Test
972998
void test_failedFuture() throws Exception {
@@ -978,7 +1004,8 @@ void test_failedFuture() throws Exception {
9781004
// endregion
9791005
////////////////////////////////////////////////////////////
9801006
// region## Delay Execution(backport methods)
981-
////////////////////////////////////////////////////////////
1007+
1008+
/// /////////////////////////////////////////////////////////
9821009

9831010
@Test
9841011
void test_delayedExecutor() throws Exception {
@@ -997,7 +1024,8 @@ void test_delayedExecutor() throws Exception {
9971024

9981025
////////////////////////////////////////////////////////////
9991026
// region## Then-Multi-Actions(thenM*) Methods
1000-
////////////////////////////////////////////////////////////
1027+
1028+
/// /////////////////////////////////////////////////////////
10011029

10021030
@Test
10031031
void test_thenMRun() throws Exception {
@@ -1095,7 +1123,8 @@ void test_thenMApply() throws Exception {
10951123
// endregion
10961124
////////////////////////////////////////////////////////////
10971125
// region## Then-Multi-Actions-Tuple(thenMTuple*) Methods
1098-
////////////////////////////////////////////////////////////
1126+
1127+
/// /////////////////////////////////////////////////////////
10991128

11001129
@Test
11011130
void test_thenTuple_methods() throws Exception {
@@ -1183,7 +1212,8 @@ void test_thenTuple_methods() throws Exception {
11831212
// endregion
11841213
////////////////////////////////////////////////////////////
11851214
// region## thenBoth* Methods(binary input) with fail-fast support
1186-
////////////////////////////////////////////////////////////
1215+
1216+
/// /////////////////////////////////////////////////////////
11871217

11881218
@Test
11891219
void test_both() throws Exception {
@@ -1305,7 +1335,8 @@ void bothFailFast() throws Exception {
13051335
// endregion
13061336
////////////////////////////////////////////////////////////
13071337
// region## thenEither* Methods(binary input) with either(any)-success support
1308-
////////////////////////////////////////////////////////////
1338+
1339+
/// /////////////////////////////////////////////////////////
13091340

13101341
@Test
13111342
void test_either() throws Exception {
@@ -1391,7 +1422,8 @@ void test_either_success() throws Exception {
13911422
// endregion
13921423
////////////////////////////////////////////////////////////
13931424
// region## Error Handling Methods of CompletionStage
1394-
////////////////////////////////////////////////////////////
1425+
1426+
/// /////////////////////////////////////////////////////////
13951427

13961428
@Test
13971429
void test_exceptionallyAsync() throws Exception {
@@ -1453,7 +1485,8 @@ private static void test_catching_failedCf(CompletableFuture<Integer> failed) th
14531485
////////////////////////////////////////////////////////////////////////////////
14541486
//# Backport CF methods
14551487
// compatibility for low Java version
1456-
////////////////////////////////////////////////////////////////////////////////
1488+
1489+
/// /////////////////////////////////////////////////////////////////////////////
14571490

14581491
@Test
14591492
void test_timeout() throws Exception {
@@ -1545,7 +1578,8 @@ void test_safeBehavior_completeOnTimeout() {
15451578
// endregion
15461579
////////////////////////////////////////////////////////////
15471580
// region## Advanced Methods of CompletionStage(compose* and handle-like methods)
1548-
////////////////////////////////////////////////////////////
1581+
1582+
/// /////////////////////////////////////////////////////////
15491583

15501584
@Test
15511585
void test_exceptionallyCompose() throws Exception {
@@ -1630,7 +1664,8 @@ void test_peek() throws Exception {
16301664
// endregion
16311665
////////////////////////////////////////////////////////////
16321666
// region## Read(explicitly)/Write Methods of CompletableFuture(including Future)
1633-
////////////////////////////////////////////////////////////
1667+
1668+
/// /////////////////////////////////////////////////////////
16341669

16351670
@Test
16361671
@SuppressWarnings("ThrowableNotThrown")
@@ -1851,7 +1886,8 @@ void test_write() throws Exception {
18511886
// endregion
18521887
////////////////////////////////////////////////////////////
18531888
// region## Re-Config Methods of CompletableFuture
1854-
////////////////////////////////////////////////////////////
1889+
1890+
/// /////////////////////////////////////////////////////////
18551891

18561892
@Test
18571893
void test_re_config() throws Exception {
@@ -1935,7 +1971,7 @@ void test_unwrapCfException() {
19351971
// endregion
19361972
////////////////////////////////////////////////////////////////////////////////
19371973
// region# Test helper fields
1938-
////////////////////////////////////////////////////////////////////////////////
1974+
/// /////////////////////////////////////////////////////////////////////////////
19391975

19401976
private static final String testName = "CompletableFutureUtilsTest";
19411977
}

0 commit comments

Comments
 (0)