Skip to content

UnsupportedOpperationException in toJava(future).toCompletableFuture is unnecessarily hostile (was: "Testing") #43

Closed
@jroper

Description

@jroper

Most testing frameworks, in particular, the most popular Java Framework, junit, are synchronous, requiring that the test finish synchronously. When testing code that returns a CompletionStage, the only way to test this from junit is to block on it. And the idiomatic way, and simplest way, to do this is to call toCompletableFuture().get(). Since FutureConverters.toJava doesn't implement toCompletableFuture, this is going to make life difficult for Java developers when they want to test their code, especially given the unpredictable nature, when sometimes code might return a CompletableFuture, and so it would work, and other times, it might return a converted Scala Future, and then it won't work. To the end user, this will be confusing.

The spec for CompletionStage does not require that completing the return value of toCompletableFuture completes the original CompletionStage:

invocation of this method may be equivalent in effect to thenApply(x -> x), but returning an instance of type CompletableFuture.

It is therefore perfectly acceptable to return a new CompletableFuture that doesn't redeem the original CompletionStage, and for the sake of allowing Java developers to easily test APIs that return CompletionStage created by this library, I think this is very important.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions