Hi,

i try to unit test a custom behavior. But i was wondering what's the right way to test it.

I provide some code to explain my mind mismatch. The behavior shall interrupt the rendering of a component. I would like to answer this with a 404. Calling the behavior method directly results in the expected exception. But if i render a using component it's not answered by the 404.

How can i get a 404 within the usage testcase (see below).

Thanks for helping me
Per

<code>
public class TestHomePage {

    public static class MyBehavior extends Behavior {
        @Override
        public void beforeRender(Component component) {
            if (true) {
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "This is for testing");
            }
        }
    }

public static class MyTestHomePage extends WebPage implements IMarkupResourceStreamProvider {

        public MyTestHomePage() {
            add(new MyBehavior());
        }

        @Override
        public IResourceStream getMarkupResourceStream(
                MarkupContainer container, Class<?> containerClass) {
            return Markup.of("<html></html>").getMarkupResourceStream();
        }
    }

    private WicketTester tester;

    @Before
    public void setUp() {
        tester = new WicketTester(new WicketApplication());
    }

    @Test
    public void abortRenderingOnUsage() {
        tester.startPage(MyTestHomePage.class);
        tester.assertRenderedPage(InternalErrorPage.class);
    }

    @Test(expected = AbortWithHttpErrorCodeException.class)
    public void abortRenderingOnUnitTesting() {
        MyBehavior behavior = new MyBehavior();
        behavior.beforeRender(null);
    }
}
</code>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to