The static factory methods for each matcher are generated to com.nitorcreations.WicketMatchers
class.
Available in Maven central repository. Add this to your pom.xml
<dependency>
<groupId>com.nitorcreations</groupId>
<artifactId>wicket-matchers</artifactId>
<version>1.0</version>
</dependency>
The package contains the following matchers:
hasId(String)
,hasId(Matcher<String>)
- matches the components wicket idvisibleInHierarchy()
enabledInHierarchy()
label(String)
,label(Matcher<?>)
- matches aLabel
with the given texthasModelObject(Matcher<?>)
,hasModelObject(Object)
- matchesComponent#getDefaultModelObject()
listViewThat(Matcher<?>)
- matches aListView
whose ListView#getList() matches the given valuemultiLineLabel(Matcher<String>)
,multiLineLabel(String)
- matches aMultiLineLabel
with the given valuerequired()
- matches ifisRequired()
returnstrue
bookmarkableLink(Class<S extends Page>)
,bookmarkableLink(Class<S extends Page> clazz, PageParameters params)
- matches aBookmarkablePageLink
hasParent(Matcher<?>)
- matches whenComponent#getParent()
matches.
hasChild(Matcher<? super Component>)
- Matches, if theWebMarkupContainer
has a child that matches the given child matcher. Will not match any grand-children.
hasLabel(Matcher<String>)
,hasLabel(String)
- matchesFormComponent.getLabel().getObject()
hasBehavior(Behavior)
,hasBehavior(Matcher<? super Behavior>)
,hasBehavior(Class<? extends Behavior>)
hasTag(String)
,hasTag(BaseWicketTester)
- looks up the tag from the given response string orBaseWicketTester#getLastResponseAsString()
that corresponds to the component.- Add tag attributes by
.with(String, String)
or.with(String, Matcher<? super String>)
- Example:
assertThat(label, hasTag(wicketTester).with("class", is("blue")));
hasError()
,hasFeedback(int, String)
,hasFeedback(Matcher<Integer>, Matcher<String>)
- Matches if the component has a feedback message, e.g.,
input.error("Error") => assertThat(input, hasFeedback(FeedbackMessage.ERROR, "Error");
- Only works with Wicket 6, since Wicket 1.5 has different feedback mechanism.
modelThat(Matcher<?>)
/modelThat(T)
- matches that the model's object matches
If you add new matcher classes, be sure to add @Factory
annotations to the static factory methods, and remember to add the new class to the matchers.xml
file. This will ensure that the factory methods will be accessible in the common com.nitorcreations.WicketMatchers
class.
Example:
public class HasBehavior<T extends Component> extends TypeSafeMatcher<T> {
@Factory
public static <T extends Component> Matcher<T> hasBehavior(Behavior b) {
return new HasBehavior<T>(Matchers.is(b));
}
And the corresponding row in matchers.xml
:
<matchers>
...
<factory class="com.nitorcreations.matchers.HasBehavior"/>
...
</matchers>