375 |
|
|
376 |
|
/** |
377 |
|
* exceptionally action completes with function value on source |
378 |
< |
* exception; otherwise with source value |
378 |
> |
* exception; otherwise with source value |
379 |
|
*/ |
380 |
|
public void testExceptionally() { |
381 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
2931 |
|
ThreadExecutor exec = new ThreadExecutor(); |
2932 |
|
|
2933 |
|
Runnable[] throwingActions = { |
2934 |
< |
() -> { CompletableFuture.supplyAsync(null); }, |
2935 |
< |
() -> { CompletableFuture.supplyAsync(null, exec); }, |
2936 |
< |
() -> { CompletableFuture.supplyAsync(supplyOne, null); }, |
2937 |
< |
|
2938 |
< |
() -> { CompletableFuture.runAsync(null); }, |
2939 |
< |
() -> { CompletableFuture.runAsync(null, exec); }, |
2940 |
< |
() -> { CompletableFuture.runAsync(() -> {}, null); }, |
2941 |
< |
|
2942 |
< |
() -> { f.completeExceptionally(null); }, |
2943 |
< |
|
2944 |
< |
() -> { f.thenApply(null); }, |
2945 |
< |
() -> { f.thenApplyAsync(null); }, |
2946 |
< |
() -> { f.thenApplyAsync((x) -> x, null); }, |
2947 |
< |
() -> { f.thenApplyAsync(null, exec); }, |
2948 |
< |
|
2949 |
< |
() -> { f.thenAccept(null); }, |
2950 |
< |
() -> { f.thenAcceptAsync(null); }, |
2951 |
< |
() -> { f.thenAcceptAsync((x) -> { ; }, null); }, |
2952 |
< |
() -> { f.thenAcceptAsync(null, exec); }, |
2953 |
< |
|
2954 |
< |
() -> { f.thenRun(null); }, |
2955 |
< |
() -> { f.thenRunAsync(null); }, |
2956 |
< |
() -> { f.thenRunAsync(() -> { ; }, null); }, |
2957 |
< |
() -> { f.thenRunAsync(null, exec); }, |
2958 |
< |
|
2959 |
< |
() -> { f.thenCombine(g, null); }, |
2960 |
< |
() -> { f.thenCombineAsync(g, null); }, |
2961 |
< |
() -> { f.thenCombineAsync(g, null, exec); }, |
2962 |
< |
() -> { f.thenCombine(nullFuture, (x, y) -> x); }, |
2963 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x); }, |
2964 |
< |
() -> { f.thenCombineAsync(nullFuture, (x, y) -> x, exec); }, |
2965 |
< |
() -> { f.thenCombineAsync(g, (x, y) -> x, null); }, |
2966 |
< |
|
2967 |
< |
() -> { f.thenAcceptBoth(g, null); }, |
2968 |
< |
() -> { f.thenAcceptBothAsync(g, null); }, |
2969 |
< |
() -> { f.thenAcceptBothAsync(g, null, exec); }, |
2970 |
< |
() -> { f.thenAcceptBoth(nullFuture, (x, y) -> {}); }, |
2971 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}); }, |
2972 |
< |
() -> { f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec); }, |
2973 |
< |
() -> { f.thenAcceptBothAsync(g, (x, y) -> {}, null); }, |
2974 |
< |
|
2975 |
< |
() -> { f.runAfterBoth(g, null); }, |
2976 |
< |
() -> { f.runAfterBothAsync(g, null); }, |
2977 |
< |
() -> { f.runAfterBothAsync(g, null, exec); }, |
2978 |
< |
() -> { f.runAfterBoth(nullFuture, () -> {}); }, |
2979 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}); }, |
2980 |
< |
() -> { f.runAfterBothAsync(nullFuture, () -> {}, exec); }, |
2981 |
< |
() -> { f.runAfterBothAsync(g, () -> {}, null); }, |
2982 |
< |
|
2983 |
< |
() -> { f.applyToEither(g, null); }, |
2984 |
< |
() -> { f.applyToEitherAsync(g, null); }, |
2985 |
< |
() -> { f.applyToEitherAsync(g, null, exec); }, |
2986 |
< |
() -> { f.applyToEither(nullFuture, (x) -> x); }, |
2987 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x); }, |
2988 |
< |
() -> { f.applyToEitherAsync(nullFuture, (x) -> x, exec); }, |
2989 |
< |
() -> { f.applyToEitherAsync(g, (x) -> x, null); }, |
2990 |
< |
|
2991 |
< |
() -> { f.acceptEither(g, null); }, |
2992 |
< |
() -> { f.acceptEitherAsync(g, null); }, |
2993 |
< |
() -> { f.acceptEitherAsync(g, null, exec); }, |
2994 |
< |
() -> { f.acceptEither(nullFuture, (x) -> {}); }, |
2995 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}); }, |
2996 |
< |
() -> { f.acceptEitherAsync(nullFuture, (x) -> {}, exec); }, |
2997 |
< |
() -> { f.acceptEitherAsync(g, (x) -> {}, null); }, |
2998 |
< |
|
2999 |
< |
() -> { f.runAfterEither(g, null); }, |
3000 |
< |
() -> { f.runAfterEitherAsync(g, null); }, |
3001 |
< |
() -> { f.runAfterEitherAsync(g, null, exec); }, |
3002 |
< |
() -> { f.runAfterEither(nullFuture, () -> {}); }, |
3003 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}); }, |
3004 |
< |
() -> { f.runAfterEitherAsync(nullFuture, () -> {}, exec); }, |
3005 |
< |
() -> { f.runAfterEitherAsync(g, () -> {}, null); }, |
3006 |
< |
|
3007 |
< |
() -> { f.thenCompose(null); }, |
3008 |
< |
() -> { f.thenComposeAsync(null); }, |
3009 |
< |
() -> { f.thenComposeAsync(new CompletableFutureInc(), null); }, |
3010 |
< |
() -> { f.thenComposeAsync(null, exec); }, |
3011 |
< |
|
3012 |
< |
() -> { f.exceptionally(null); }, |
3013 |
< |
|
3014 |
< |
() -> { f.handle(null); }, |
3015 |
< |
|
3016 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>)null); }, |
3017 |
< |
() -> { CompletableFuture.allOf((CompletableFuture<?>[])null); }, |
3018 |
< |
() -> { CompletableFuture.allOf(f, null); }, |
3019 |
< |
() -> { CompletableFuture.allOf(null, f); }, |
3020 |
< |
|
3021 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>)null); }, |
3022 |
< |
() -> { CompletableFuture.anyOf((CompletableFuture<?>[])null); }, |
3023 |
< |
() -> { CompletableFuture.anyOf(f, null); }, |
3024 |
< |
() -> { CompletableFuture.anyOf(null, f); }, |
2934 |
> |
() -> CompletableFuture.supplyAsync(null), |
2935 |
> |
() -> CompletableFuture.supplyAsync(null, exec), |
2936 |
> |
() -> CompletableFuture.supplyAsync(supplyOne, null), |
2937 |
> |
|
2938 |
> |
() -> CompletableFuture.runAsync(null), |
2939 |
> |
() -> CompletableFuture.runAsync(null, exec), |
2940 |
> |
() -> CompletableFuture.runAsync(() -> {}, null), |
2941 |
> |
|
2942 |
> |
() -> f.completeExceptionally(null), |
2943 |
> |
|
2944 |
> |
() -> f.thenApply(null), |
2945 |
> |
() -> f.thenApplyAsync(null), |
2946 |
> |
() -> f.thenApplyAsync((x) -> x, null), |
2947 |
> |
() -> f.thenApplyAsync(null, exec), |
2948 |
> |
|
2949 |
> |
() -> f.thenAccept(null), |
2950 |
> |
() -> f.thenAcceptAsync(null), |
2951 |
> |
() -> f.thenAcceptAsync((x) -> {} , null), |
2952 |
> |
() -> f.thenAcceptAsync(null, exec), |
2953 |
> |
|
2954 |
> |
() -> f.thenRun(null), |
2955 |
> |
() -> f.thenRunAsync(null), |
2956 |
> |
() -> f.thenRunAsync(() -> {} , null), |
2957 |
> |
() -> f.thenRunAsync(null, exec), |
2958 |
> |
|
2959 |
> |
() -> f.thenCombine(g, null), |
2960 |
> |
() -> f.thenCombineAsync(g, null), |
2961 |
> |
() -> f.thenCombineAsync(g, null, exec), |
2962 |
> |
() -> f.thenCombine(nullFuture, (x, y) -> x), |
2963 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x), |
2964 |
> |
() -> f.thenCombineAsync(nullFuture, (x, y) -> x, exec), |
2965 |
> |
() -> f.thenCombineAsync(g, (x, y) -> x, null), |
2966 |
> |
|
2967 |
> |
() -> f.thenAcceptBoth(g, null), |
2968 |
> |
() -> f.thenAcceptBothAsync(g, null), |
2969 |
> |
() -> f.thenAcceptBothAsync(g, null, exec), |
2970 |
> |
() -> f.thenAcceptBoth(nullFuture, (x, y) -> {}), |
2971 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}), |
2972 |
> |
() -> f.thenAcceptBothAsync(nullFuture, (x, y) -> {}, exec), |
2973 |
> |
() -> f.thenAcceptBothAsync(g, (x, y) -> {}, null), |
2974 |
> |
|
2975 |
> |
() -> f.runAfterBoth(g, null), |
2976 |
> |
() -> f.runAfterBothAsync(g, null), |
2977 |
> |
() -> f.runAfterBothAsync(g, null, exec), |
2978 |
> |
() -> f.runAfterBoth(nullFuture, () -> {}), |
2979 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}), |
2980 |
> |
() -> f.runAfterBothAsync(nullFuture, () -> {}, exec), |
2981 |
> |
() -> f.runAfterBothAsync(g, () -> {}, null), |
2982 |
> |
|
2983 |
> |
() -> f.applyToEither(g, null), |
2984 |
> |
() -> f.applyToEitherAsync(g, null), |
2985 |
> |
() -> f.applyToEitherAsync(g, null, exec), |
2986 |
> |
() -> f.applyToEither(nullFuture, (x) -> x), |
2987 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x), |
2988 |
> |
() -> f.applyToEitherAsync(nullFuture, (x) -> x, exec), |
2989 |
> |
() -> f.applyToEitherAsync(g, (x) -> x, null), |
2990 |
> |
|
2991 |
> |
() -> f.acceptEither(g, null), |
2992 |
> |
() -> f.acceptEitherAsync(g, null), |
2993 |
> |
() -> f.acceptEitherAsync(g, null, exec), |
2994 |
> |
() -> f.acceptEither(nullFuture, (x) -> {}), |
2995 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}), |
2996 |
> |
() -> f.acceptEitherAsync(nullFuture, (x) -> {}, exec), |
2997 |
> |
() -> f.acceptEitherAsync(g, (x) -> {}, null), |
2998 |
> |
|
2999 |
> |
() -> f.runAfterEither(g, null), |
3000 |
> |
() -> f.runAfterEitherAsync(g, null), |
3001 |
> |
() -> f.runAfterEitherAsync(g, null, exec), |
3002 |
> |
() -> f.runAfterEither(nullFuture, () -> {}), |
3003 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}), |
3004 |
> |
() -> f.runAfterEitherAsync(nullFuture, () -> {}, exec), |
3005 |
> |
() -> f.runAfterEitherAsync(g, () -> {}, null), |
3006 |
> |
|
3007 |
> |
() -> f.thenCompose(null), |
3008 |
> |
() -> f.thenComposeAsync(null), |
3009 |
> |
() -> f.thenComposeAsync(new CompletableFutureInc(), null), |
3010 |
> |
() -> f.thenComposeAsync(null, exec), |
3011 |
> |
|
3012 |
> |
() -> f.exceptionally(null), |
3013 |
> |
|
3014 |
> |
() -> f.handle(null), |
3015 |
> |
|
3016 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>)null), |
3017 |
> |
() -> CompletableFuture.allOf((CompletableFuture<?>[])null), |
3018 |
> |
() -> CompletableFuture.allOf(f, null), |
3019 |
> |
() -> CompletableFuture.allOf(null, f), |
3020 |
> |
|
3021 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>)null), |
3022 |
> |
() -> CompletableFuture.anyOf((CompletableFuture<?>[])null), |
3023 |
> |
() -> CompletableFuture.anyOf(f, null), |
3024 |
> |
() -> CompletableFuture.anyOf(null, f), |
3025 |
|
}; |
3026 |
|
|
3027 |
|
assertThrows(NullPointerException.class, throwingActions); |