com.nitorcreations.matchers.ContainerWithChild Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicket-matchers Show documentation
Show all versions of wicket-matchers Show documentation
Useful Hamcrest 1.3 matchers for Wicket 6 projects
The newest version!
package com.nitorcreations.matchers;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
public final class ContainerWithChild extends TypeSafeDiagnosingMatcher {
private final Matcher super Component> child;
private ContainerWithChild(Matcher super Component> child) {
this.child = child;
}
/**
* Matches, if the {@link WebMarkupContainer} has a child that matches the given {@code child} matcher. Will not
* match any grand-children
*
* @param child
* @return
*/
@Factory
public static Matcher hasChild(final Matcher super Component> child) {
return new ContainerWithChild(child);
}
@Override
protected boolean matchesSafely(WebMarkupContainer item, Description mismatchDescription) {
for (Component c : item) {
if (child.matches(c)) {
return true;
}
}
mismatchDescription.appendText("no child that matches ").appendDescriptionOf(child);
return false;
}
@Override
public void describeTo(Description description) {
description.appendText(" has child: ").appendDescriptionOf(child);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy