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

com.nitorcreations.matchers.FormComponentMatchers 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.TypeSafeDiagnosingMatcher;

import org.apache.wicket.markup.html.form.FormComponent;

import static org.hamcrest.Matchers.is;

public final class FormComponentMatchers {

    private FormComponentMatchers() {}

    @Factory
    public static > Matcher hasLabel(final Matcher label) {
        return new TypeSafeDiagnosingMatcher() {
            @Override
            protected boolean matchesSafely(T item, Description mismatchDescription) {
                String labelText = item.getLabel().getObject();
                label.describeMismatch(labelText, mismatchDescription);
                return label.matches(labelText);
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with label ").appendDescriptionOf(label);
            }
        };
    }

    @Factory
    public static Matcher> hasLabel(String label) {
        return hasLabel(is(label));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy