All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nitorcreations.matchers.HasBehavior Maven / Gradle / Ivy

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 behavior;

    public HasBehavior(Matcher 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 behavior) {
        return new HasBehavior(behavior);
    }

    @Factory
    public static  Matcher hasBehavior(Class behaviorClazz) {
        return new HasBehavior(Matchers.instanceOf(behaviorClazz));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy