I have simple page for displaying messages:

public class ErrorPage extends WebPage {

    private String message;

    public ErrorPage() {

    public ErrorPage(String msg) {
        if(StringUtils.hasText(msg)) {
            this.message = msg;
        } else {
            this.message = getString("sapi2.page.error.default_message");
        add(new Label("errorMsg",

    public String getMessage() {
        return message;

now I would like to test this with WickeTester:

@Testpublic void testPageRenders() {

        wicketTester.startPage(new ErrorPage(message));
        ErrorPage errorPage = (ErrorPage)
        assertEquals(message, errorPage.getMessage());

but the test is failing and I can see the constructor is called twice, once
with my "message" parameter (as expected) and then again via empty
constructor and thus the errorPage.getMessage() returns null. Why is the
empty constructor called at all? After some painful debugging I suspect it
has something to do with the page being stateless...


Reply via email to