0
Ich habe einen einfachen Controller-Test.Test Play Controller mit Sitzungsdaten
route(fakeRequest(routes.Accounts.accounts()).session("sessionref","fakeSession"));
Secured Autheticator sieht wie folgt aus:
public class Secured extends play.mvc.Security.Authenticator {
@Inject
AuthServices authService;
public String getUsername(Http.Context context) {
return authService.checkSession(context);
}
@Override
public Result onUnauthorized(Http.Context context) {
return ok(index.render(formFactory.form(forms.LoginForm.class)));
}
}
Wie kann ich authService
verspotten? Ich habe versucht, mit guice binden zu verspotten, aber diese Methode nicht funktioniert
@Before
public void setup() {
startPlay();
MockitoAnnotations.initMocks(this);
Module testModule = new AbstractModule() {
@Override
public void configure() {
bind(AuthServices.class)
.toInstance(authServices);
}
};
GuiceApplicationBuilder builder = new GuiceApplicationLoader()
.builder(new play.ApplicationLoader.Context(Environment.simple()))
.in(Mode.TEST)
.overrides(testModule);
Guice.createInjector(builder.applicationModule()).injectMembers(this);
}