gwt - How do I bind named providers in a Jukito module? -
i testing gwtp presenter using jukito, , can't seem named bindings work.
i want able test onreveal()
of login widget, need provide copy of currentuserdto
logged in, , 1 isn't. i'm trying do:
@runwith(jukitorunner.class) public class loginwidgetpresentertest { public static class module extends jukitomodule { @override protected void configuretest() { bind(currentuserdto.class).annotatedwith(names.named("loggedin")).toprovider(loggedinuserprovider.class); bind(currentuserdto.class).annotatedwith(names.named("loggedout")).toprovider(loggedoutuserprovider.class); // these don't work either: // bindnamed(currentuserdto.class, "loggedin").toprovider(loggedinuserprovider.class); // bindnamed(currentuserdto.class, "loggedout").toprovider(loggedoutuserprovider.class); } public static class loggedinuserprovider implements provider<currentuserdto> { @override public currentuserdto get() { currentuserdto currentuser = new currentuserdto(true, 100l); // isloggedin, userid currentuser.setemail("john@example.com"); currentuser.setnickname("john"); currentuser.setlogouturl("#logout"); return currentuser; } } public static class loggedoutuserprovider implements provider<currentuserdto> { @override public currentuserdto get() { currentuserdto currentuser = new currentuserdto(false, null); // isloggedin, userid return currentuser; } } } @inject loginwidgetpresenter presenter; @test public void testloggedinuser(loginwidgetpresenter.myview myview, @named("loggedin") currentuserdto currentuser) { // when presenter.onreveal(); // verify(myview).displayemail(currentuser.getemail()); verify(myview).displaylogoutlink(currentuser.getlogouturl()); } @test public void testloggedoutuser(loginwidgetpresenter.myview myview, @named("loggedout") currentuserdto currentuser) { // when presenter.onreveal(); // verify(myview, never()).displayemail(currentuser.getemail()); verify(myview, never()).displaylogoutlink(currentuser.getlogouturl()); } }
i suspect may scopes, i'm new dependency injection still getting head around it.
when had 1 provider worked fine, now using @named
currentuserdto
objects in loginwidgetpresenter
null.
i assume loginwidgetpresenter
has bare currentuserdto
injected. parameter test method doesn't change dependencies of loginwidgetpresenter
. handle this, have 2 different modules, each binding currentuserdto
different provider
.
Comments
Post a Comment