Created
October 12, 2012 16:59
-
-
Save anonymous/3880246 to your computer and use it in GitHub Desktop.
Creating a WicketApplication through Guice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomePage extends WebPage { | |
@Inject | |
private Injector injector; | |
public HomePage(final PageParameters parameters) { | |
super(parameters); | |
String hello = injector.getInstance(Key.get(String.class, Names.named("hello"))); | |
add(new Label("hello", hello)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestHomePage { | |
private WicketTester tester; | |
@Before | |
public void setUp() { | |
Injector injector = Guice.createInjector(new AbstractModule() { | |
@Override | |
protected void configure() { | |
bind(Key.get(String.class, Names.named("hello"))).toInstance("world!"); | |
} | |
}); | |
tester = new WicketTester(new WicketApplication(injector)); | |
} | |
@Test | |
public void homepageRendersSuccessfully() { | |
tester.startPage(HomePage.class); | |
tester.assertLabel("hello", "world!"); | |
tester.assertRenderedPage(HomePage.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WicketApplication extends WebApplication { | |
private final Injector injector; | |
@Inject | |
public WicketApplication(Injector injector) { | |
this.injector = injector; | |
} | |
@Override | |
public Class<HomePage> getHomePage() { | |
return HomePage.class; | |
} | |
@Override | |
public void init() { | |
super.init(); | |
getComponentInstantiationListeners().add(new GuiceComponentInjector(this, injector)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment