Migration of playframework from 2.5 to 2.7, encountered an error in test module

java.lang.IllegalArgumentException: requirement failed: Your Action (or some of its compositions) returned a null Result

To work around this, ensure what has been laid out in migrations guide is followed promptly.

In my case we had @Secured Annotation over classes which had to be authenticated. Secured Class inherits the Authenticator class.

In fx 2.5, the overridden method had getUsername had the following signature

public String getUsername(Http.Context context) {return ....}

The same overrdiden method in Play 2.7, has the following signature.

public Optional<String> getUsername(Http.Request request) {return ....}

In our tests classes initially while we were on 2.5, we were mocking the username using the following construct

String userName=  "google-oauth2|105029366341165441316";
Mockito.when(securedmock.getUsername(any(Http.Context.class))).thenReturn(userName);

Running these tests, would result in the error java.lang.IllegalArgumentException: requirement failed: Your Action (or some of its compositions) returned a null Result

If we look closely at the signatures of the method, Optional<String> is the return type and the parameter is Http.Request instead of String and Http.Context, changing it to optional like the following resolves the bug.

Optional<String> userName=  Optional.of("google-oauth2|105029366341165441316");
Mockito.when(securedmock.getUsername(any(Http.Context.class))).thenReturn("xyz");