I have simple page for displaying messages:

@MountPath("/wicket/page/error")
public class ErrorPage extends WebPage {

    private String message;

    public ErrorPage() {
        this(null);
    }

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

    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)
wicketTester.getLastRenderedPage();
        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...

Zbynek

Reply via email to