Created
September 26, 2013 19:35
-
-
Save bjpbakker/6719383 to your computer and use it in GitHub Desktop.
Hamcrest matcher for asserting that a Wicket page is stateless
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
package com.github.bjpbakker.gist; | |
import org.apache.wicket.Component; | |
import org.apache.wicket.Page; | |
import org.apache.wicket.util.visit.IVisit; | |
import org.apache.wicket.util.visit.IVisitor; | |
import org.hamcrest.Description; | |
import org.hamcrest.Matcher; | |
import org.hamcrest.TypeSafeDiagnosingMatcher; | |
/** | |
* Matches a page if it is stateless. Diagnoses if it is stateful. | |
*/ | |
public class StatelessPageMatcher extends TypeSafeDiagnosingMatcher<Page> { | |
public static Matcher<Page> stateless() { | |
return new StatelessPageMatcher(); | |
} | |
@Override | |
protected boolean matchesSafely(Page page, Description mismatchDescription) { | |
if (!page.isStateless()) { | |
mismatchDescription.appendText("page is stateful"); | |
} else if (!page.isPageStateless()) { | |
Component stateful = page.visitChildren(Component.class, new Stateful()); | |
if (stateful == null) { | |
mismatchDescription.appendText("found stateful page; stateful child is unknown, it must be hidden or disabled"); | |
} else { | |
mismatchDescription.appendText("found stateful child ").appendValue(stateful.getId()); | |
} | |
} | |
return page.isPageStateless(); | |
} | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("stateless"); | |
} | |
private static class Stateful implements IVisitor<Component, Component> { | |
@Override | |
public void component(Component c, IVisit<Component> visit) { | |
if (!c.isStateless()) { | |
visit.stop(c); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi,
how can you extend JDBCAppender is it's final, and its constructor is private?