diff --git a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java index 43c37fd3..9ae72600 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CompletableFutureUtilsTest.java @@ -1026,56 +1026,6 @@ void test_completableFutureListToArray() { assertArrayEquals(input, CompletableFutureUtils.completableFutureListToArray(Arrays.asList(input))); } - //////////////////////////////////////////////////////////////////////////////// - //# check type parameter declaration, Variance(covariance/contravariance) - //////////////////////////////////////////////////////////////////////////////// - - @Test - @SuppressWarnings({"UnnecessaryLocalVariable", "unused"}) - void checkTypeParameterDeclaration_peek_completeAsync() throws Exception { - final CompletableFuture f = completedFuture(42); - final CompletableFuture fe = f; - final CompletableFuture fs = f; - final CompletableFuture fq = f; - - final BiConsumer c = (v, ex) -> { - }; - CompletableFutureUtils.peek(fe, c).get(); - CompletableFutureUtils.peekAsync(fe, c).get(); - CompletableFutureUtils.peekAsync(fe, c, executorService).get(); - - final Supplier s = () -> 0; - fs.complete(0); - CompletableFutureUtils.completeAsync(fs, s).complete(1); - CompletableFutureUtils.completeAsync(fs, s, executorService).complete(1); - - CompletableFuture ffe = orTimeout(fe, 1, TimeUnit.MILLISECONDS); - CompletableFuture ffs = orTimeout(fs, 1, TimeUnit.MILLISECONDS); - CompletableFuture ffq = orTimeout(fq, 1, TimeUnit.MILLISECONDS); - } - - @Test - @EnabledForJreRange(min = JRE.JAVA_19) - @SuppressWarnings({"UnnecessaryLocalVariable", "unused", "RedundantThrows"}) - void checkTypeParameterDeclaration_resultNow() throws Exception { - final CompletableFuture f = completedFuture(42); - final CompletableFuture fe = f; - final CompletableFuture fs = f; - final CompletableFuture fq = f; - - Integer i = f.resultNow(); - Integer ii = resultNow(f); - - Integer ie = fe.resultNow(); - Integer iie = resultNow(fe); - - Object is = fs.resultNow(); - Object iis = resultNow(fs); - - Object iq = fq.resultNow(); - Object iiq = resultNow(fq); - } - //////////////////////////////////////////////////////////////////////////////// //# test helper fields //////////////////////////////////////////////////////////////////////////////// diff --git a/cffu-kotlin/src/test/java/io/foldright/cffu/generics/TypeParameterDeclarationTest.java b/cffu-kotlin/src/test/java/io/foldright/cffu/generics/TypeParameterDeclarationTest.java new file mode 100644 index 00000000..17d0671f --- /dev/null +++ b/cffu-kotlin/src/test/java/io/foldright/cffu/generics/TypeParameterDeclarationTest.java @@ -0,0 +1,76 @@ +package io.foldright.cffu.generics; + +import io.foldright.cffu.CompletableFutureUtils; +import io.foldright.test_utils.TestThreadPoolManager; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.Supplier; + +import static io.foldright.cffu.CompletableFutureUtils.orTimeout; +import static io.foldright.cffu.CompletableFutureUtils.resultNow; +import static java.util.concurrent.CompletableFuture.completedFuture; + + +/** + * Checks type parameter declaration, Variance(covariance/contravariance) + */ +@SuppressWarnings({"UnnecessaryLocalVariable", "unused", "RedundantThrows"}) +public class TypeParameterDeclarationTest { + + private static final CompletableFuture f = completedFuture(42); + private static final CompletableFuture fe = f; + private static final CompletableFuture fs = f; + private static final CompletableFuture fq = f; + + @Test + void checkTypeParameterDeclaration_peek_completeAsync() throws Exception { + final BiConsumer c = (v, ex) -> { + }; + CompletableFutureUtils.peek(fe, c).get(); + CompletableFutureUtils.peekAsync(fe, c).get(); + CompletableFutureUtils.peekAsync(fe, c, executorService).get(); + + final Supplier s = () -> 0; + fs.complete(0); + CompletableFutureUtils.completeAsync(fs, s).complete(1); + CompletableFutureUtils.completeAsync(fs, s, executorService).complete(1); + + CompletableFuture ffe = orTimeout(fe, 1, TimeUnit.MILLISECONDS); + CompletableFuture ffs = orTimeout(fs, 1, TimeUnit.MILLISECONDS); + CompletableFuture ffq = orTimeout(fq, 1, TimeUnit.MILLISECONDS); + } + + @Test + void checkTypeParameterDeclaration_resultNow() throws Exception { + Integer ii = resultNow(f); + Integer iie = resultNow(fe); + Object iis = resultNow(fs); + Object iiq = resultNow(fq); + } + + @Test + void checkTypeParameterDeclaration_get() throws Exception { + Integer i = f.get(); + Integer ie = fe.get(); + Object is = fs.get(); + Object iq = fq.get(); + } + + private static ExecutorService executorService; + + @BeforeAll + static void beforeAll() { + executorService = TestThreadPoolManager.createThreadPool("TypeParameterDeclarationTest"); + } + + @AfterAll + static void afterAll() { + TestThreadPoolManager.shutdownExecutorService(executorService); + } +}