Skip to content

Response typing

Fluxzero allows you to formalize the expected return type of commands and queries by implementing the Request<R> interface. This lets the framework:

  • Infer the response type at runtime and during testing
  • Validate handler methods at compile-time (e.g., @HandleQuery must return an R)
  • Simplify queryAndWait(...) or sendCommand(...) invocations

Here’s an example for a query:

@Value
public class GetUserProfile implements Request<UserProfile> {
String userId;
@HandleQuery
UserProfile handle() {
return loadProfile(userId);
}
}

Now, when calling this query, the return type is automatically known:

UserProfile profile = Fluxzero.queryAndWait(new GetUserProfile("123"));

When implementing Request<R>, the expected result type (R) is automatically inferred during testing and execution. This enables type-safe tests like:

testFixture.whenQuery(new GetUserProfile("123"))
.expectResult(profile -> profile.getUserId().equals("123"));

If a class implements Request<R>, Fluxzero will use its declared generic type (R) to check that:

  • A compatible handler exists
  • The handler returns the correct result type
  • The correct response is expected during testing

© 2026 Fluxzero