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

com.objogate.wl.swing.probe.ComponentPropertyAssertionProbe 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.Probe;
import com.objogate.wl.Query;
import com.objogate.wl.swing.ComponentSelector;

public class ComponentPropertyAssertionProbe implements Probe {
    private final ComponentSelector selector;
    private final Query propertyValueQuery;
    private final Matcher propertyValueMatcher;

    private P propertyValue;

    public ComponentPropertyAssertionProbe(ComponentSelector selector, Query propertyValueQuery, Matcher propertyValueMatcher) {
        this.selector = selector;
        this.propertyValueQuery = propertyValueQuery;
        this.propertyValueMatcher = propertyValueMatcher;
    }

    public void probe() {
        selector.probe();
        if (selector.isSatisfied()) {
            propertyValue = propertyValueQuery.query(selector.component());
        }
    }

    public boolean isSatisfied() {
        return selector.isSatisfied() && propertyValueMatcher.matches(propertyValue);
    }

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

    public void describeFailureTo(Description description) {
        selector.describeFailureTo(description);
        if (selector.isSatisfied()) {
        description.appendText("\n    ")
                .appendDescriptionOf(propertyValueQuery)
                .appendText(" was ")
                .appendValue(propertyValue);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy