com.nitorcreations.matchers.HasBehavior 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.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
public class HasBehavior extends TypeSafeMatcher {
private final Matcher super Behavior> behavior;
public HasBehavior(Matcher super Behavior> behavior) {
this.behavior = behavior;
}
@Override
public void describeTo(Description description) {
description.appendValue("Has behavior: ").appendDescriptionOf(behavior);
}
@Override
protected void describeMismatchSafely(T item, Description mismatchDescription) {
mismatchDescription.appendText("component contained behaviors: ").appendValue(item.getBehaviors());
}
@Override
protected boolean matchesSafely(T item) {
return Matchers.hasItem(behavior).matches(item.getBehaviors());
}
@Factory
public static Matcher hasBehavior(Behavior b) {
return new HasBehavior(Matchers.is(b));
}
@Factory
public static Matcher hasBehavior(Matcher super Behavior> behavior) {
return new HasBehavior(behavior);
}
@Factory
public static Matcher hasBehavior(Class extends Behavior> behaviorClazz) {
return new HasBehavior(Matchers.instanceOf(behaviorClazz));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy