Create a gist now

Instantly share code, notes, and snippets.

anonymous /HomePage.java
Created Oct 12, 2012

What would you like to do?
Creating a WicketApplication through Guice
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));
}
}
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);
}
}
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