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

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

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

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

/**
 * A ComponentFinder that always find a given component.
 * 

* This is useful for unit-testing a component. */ public class ComponentIdentity implements ComponentSelector { private final T component; public ComponentIdentity(T component) { this.component = component; } public static ComponentSelector selectorFor(U component) { return new ComponentIdentity(component); } public T component() { return component; } public java.util.List components() { return Collections.singletonList(component); } public void probe() { // Nothing to do } public boolean isSatisfied() { return true; } public void describeTo(Description description) { description.appendText(" the exact "); description.appendText(component.getClass().getSimpleName()); description.appendText(" '"); description.appendValue(component.toString()); description.appendText("' "); } public void describeFailureTo(Description description) { // Cannot fail } }