diff options
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java | 124 |
1 files changed, 61 insertions, 63 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java b/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java index 1372cc48dd..37bc285605 100644 --- a/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java +++ b/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java @@ -15,9 +15,8 @@ import static java.util.concurrent.CompletableFuture.failedFuture; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -// TODO(streams): -//import java.util.stream.Collectors; -//import java.util.stream.Stream; +import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.ArrayList; import java.util.Arrays; @@ -3725,66 +3724,65 @@ public class CompletableFutureTest extends JSR166TestCase { /** * Minimal completion stages throw UOE for all non-CompletionStage methods */ - // TODO(streams): - // public void testMinimalCompletionStage_minimality() { - // if (!testImplementationDetails) return; - // Function<Method, String> toSignature = - // (method) -> method.getName() + Arrays.toString(method.getParameterTypes()); - // Predicate<Method> isNotStatic = - // (method) -> (method.getModifiers() & Modifier.STATIC) == 0; - // List<Method> minimalMethods = - // Stream.of(Object.class, CompletionStage.class) - // .flatMap((klazz) -> Stream.of(klazz.getMethods())) - // .filter(isNotStatic) - // .collect(Collectors.toList()); - // // Methods from CompletableFuture permitted NOT to throw UOE - // String[] signatureWhitelist = { - // "newIncompleteFuture[]", - // "defaultExecutor[]", - // "minimalCompletionStage[]", - // "copy[]", - // }; - // Set<String> permittedMethodSignatures = - // Stream.concat(minimalMethods.stream().map(toSignature), - // Stream.of(signatureWhitelist)) - // .collect(Collectors.toSet()); - // List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods()) - // .filter(isNotStatic) - // .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method))) - // .collect(Collectors.toList()); - - // CompletionStage<Integer> minimalStage = - // new CompletableFuture<Integer>().minimalCompletionStage(); - - // List<Method> bugs = new ArrayList<>(); - // for (Method method : allMethods) { - // Class<?>[] parameterTypes = method.getParameterTypes(); - // Object[] args = new Object[parameterTypes.length]; - // // Manufacture boxed primitives for primitive params - // for (int i = 0; i < args.length; i++) { - // Class<?> type = parameterTypes[i]; - // if (parameterTypes[i] == boolean.class) - // args[i] = false; - // else if (parameterTypes[i] == int.class) - // args[i] = 0; - // else if (parameterTypes[i] == long.class) - // args[i] = 0L; - // } - // try { - // method.invoke(minimalStage, args); - // bugs.add(method); - // } - // catch (java.lang.reflect.InvocationTargetException expected) { - // if (! (expected.getCause() instanceof UnsupportedOperationException)) { - // bugs.add(method); - // // expected.getCause().printStackTrace(); - // } - // } - // catch (ReflectiveOperationException bad) { throw new Error(bad); } - // } - // if (!bugs.isEmpty()) - // throw new Error("Methods did not throw UOE: " + bugs.toString()); - // } + public void testMinimalCompletionStage_minimality() { + if (!testImplementationDetails) return; + Function<Method, String> toSignature = + (method) -> method.getName() + Arrays.toString(method.getParameterTypes()); + Predicate<Method> isNotStatic = + (method) -> (method.getModifiers() & Modifier.STATIC) == 0; + List<Method> minimalMethods = + Stream.of(Object.class, CompletionStage.class) + .flatMap((klazz) -> Stream.of(klazz.getMethods())) + .filter(isNotStatic) + .collect(Collectors.toList()); + // Methods from CompletableFuture permitted NOT to throw UOE + String[] signatureWhitelist = { + "newIncompleteFuture[]", + "defaultExecutor[]", + "minimalCompletionStage[]", + "copy[]", + }; + Set<String> permittedMethodSignatures = + Stream.concat(minimalMethods.stream().map(toSignature), + Stream.of(signatureWhitelist)) + .collect(Collectors.toSet()); + List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods()) + .filter(isNotStatic) + .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method))) + .collect(Collectors.toList()); + + CompletionStage<Integer> minimalStage = + new CompletableFuture<Integer>().minimalCompletionStage(); + + List<Method> bugs = new ArrayList<>(); + for (Method method : allMethods) { + Class<?>[] parameterTypes = method.getParameterTypes(); + Object[] args = new Object[parameterTypes.length]; + // Manufacture boxed primitives for primitive params + for (int i = 0; i < args.length; i++) { + Class<?> type = parameterTypes[i]; + if (parameterTypes[i] == boolean.class) + args[i] = false; + else if (parameterTypes[i] == int.class) + args[i] = 0; + else if (parameterTypes[i] == long.class) + args[i] = 0L; + } + try { + method.invoke(minimalStage, args); + bugs.add(method); + } + catch (java.lang.reflect.InvocationTargetException expected) { + if (! (expected.getCause() instanceof UnsupportedOperationException)) { + bugs.add(method); + // expected.getCause().printStackTrace(); + } + } + catch (ReflectiveOperationException bad) { throw new Error(bad); } + } + if (!bugs.isEmpty()) + throw new Error("Methods did not throw UOE: " + bugs.toString()); + } static class Monad { static class ZeroException extends RuntimeException { |