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

com.objogate.wl.swing.probe.ComponentAssertionProbe Maven / Gradle / Ivy

The newest version!
package com.objogate.wl.swing.probe;

import java.awt.Component;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import com.objogate.wl.swing.ComponentFinder;
import com.objogate.wl.swing.ComponentSelector;

public class ComponentAssertionProbe implements ComponentFinder {
    private final ComponentSelector selector;
    private final Matcher assertion;

    private boolean assertionMet = false;

    public ComponentAssertionProbe(ComponentSelector selector, Matcher assertion) {
        this.assertion = assertion;
        this.selector = selector;
    }

    public java.util.List components() {
        return selector.components();
    }

    public void probe() {
        selector.probe();
        assertionMet = selector.isSatisfied() && assertion.matches(selector.component());
    }

    public boolean isSatisfied() {
        return assertionMet;
    }

    public void describeTo(Description description) {
        description.appendDescriptionOf(selector)
                .appendText("\nand check that it is ")
                .appendDescriptionOf(assertion);
    }

    public void describeFailureTo(Description description) {
        selector.describeFailureTo(description);
        if (selector.isSatisfied()) {
            description.appendText("\n   it ")
                    .appendText(assertionMet ? "is " : "is not ")
                    .appendDescriptionOf(assertion);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy