22
33import org .junit .Test ;
44
5+ import java .util .Arrays ;
56import java .util .Collections ;
67import java .util .List ;
78import java .util .concurrent .CompletableFuture ;
9+ import java .util .concurrent .CompletionStage ;
810import java .util .concurrent .atomic .AtomicBoolean ;
911
1012import static java .util .Arrays .asList ;
1315import static org .hamcrest .Matchers .equalTo ;
1416import static org .hamcrest .Matchers .instanceOf ;
1517import static org .hamcrest .Matchers .is ;
18+ import static org .hamcrest .Matchers .notNullValue ;
1619import static org .hamcrest .Matchers .nullValue ;
1720import static org .junit .Assert .assertThat ;
1821
@@ -178,5 +181,35 @@ public void exceptions_are_captured_and_reported() throws Exception {
178181
179182 assertThat (promisedValues .toList (), equalTo (asList (1 , null )));
180183 assertThat (result , equalTo (asList (1 , null )));
181- }
184+ }
185+
186+ @ Test
187+ public void type_generics_compile_as_expected () throws Exception {
188+
189+ PromisedValues <String > pvList = PromisedValues .allOf (Collections .singletonList (new CompletableFuture <String >()));
190+ PromisedValues <String > pvList2 = PromisedValues .allOf (Collections .<CompletionStage <String >>singletonList (new CompletableFuture <>()));
191+
192+ assertThat (pvList , notNullValue ());
193+ assertThat (pvList2 , notNullValue ());
194+
195+ PromisedValues <String > pv2args = PromisedValues .allOf (new CompletableFuture <>(), new CompletableFuture <>());
196+ PromisedValues <String > pv3args = PromisedValues .allOf (new CompletableFuture <>(), new CompletableFuture <>(), new CompletableFuture <>());
197+ PromisedValues <String > pv4args = PromisedValues .allOf (new CompletableFuture <>(), new CompletableFuture <>(), new CompletableFuture <>(), new CompletableFuture <>());
198+
199+ assertThat (pv2args , notNullValue ());
200+ assertThat (pv3args , notNullValue ());
201+ assertThat (pv4args , notNullValue ());
202+
203+ PromisedValues <String > pvListOfPVs = PromisedValues .allPromisedValues (Arrays .asList (pv2args , pv3args ));
204+
205+ assertThat (pvListOfPVs , notNullValue ());
206+
207+ PromisedValues <String > pv2ArgsOfPVs = PromisedValues .allPromisedValues (pv2args , pv3args );
208+ PromisedValues <String > pv3ArgsOfPVs = PromisedValues .allPromisedValues (pv2args , pv3args , pv4args );
209+ PromisedValues <String > pv4ArgsOfPVs = PromisedValues .allPromisedValues (pv2args , pv3args , pv4args , pv2args );
210+
211+ assertThat (pv2ArgsOfPVs , notNullValue ());
212+ assertThat (pv3ArgsOfPVs , notNullValue ());
213+ assertThat (pv4ArgsOfPVs , notNullValue ());
214+ }
182215}
0 commit comments