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

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

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

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

/**
 * A ComponentFinder that is satisfied only if it finds a single, matching component.
 */
public class SingleComponentFinder implements ComponentSelector {
    private final ComponentFinder finder;

    public SingleComponentFinder(ComponentFinder finder) {
        this.finder = finder;
    }

    public T component() {
        return components().get(0);
    }

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

    public boolean isSatisfied() {
        return finder.isSatisfied() && isSingle();
    }

    public void probe() {
        finder.probe();
    }

    public void describeTo(Description description) {
        description.appendText("exactly 1 ")
                .appendDescriptionOf(finder);
    }

    /**
     * This expects the ComponentFinder it wraps to describe how many were actually found.
     */
    public void describeFailureTo(Description description) {
        finder.describeFailureTo(description);
    }

    private boolean isSingle() {
        return components().size() == 1;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy