org.jdesktop.test.matchers.Matchers Maven / Gradle / Ivy
package org.jdesktop.test.matchers;
import static org.hamcrest.CoreMatchers.any;
import java.beans.PropertyChangeEvent;
import org.hamcrest.Matcher;
/**
* A collection of matchers useful for testing.
*
* @author kschaefer
*/
public final class Matchers {
/**
* A matcher for any property change.
*
* @return {@code true} if any property can be matched; {@code false} otherwise
*/
public static Matcher anyProperty() {
return any(PropertyChangeEvent.class);
}
/**
* A matcher for a specified property.
*
* @param propertyName
* the name of the property to match
* @return {@code true} if the property exists and has a name that matches the specified name;
* {@code false} otherwise
*/
public static Matcher propertyWithName(String propertyName) {
return new PropertyChangeEventMatcher(propertyName, null, null);
}
/**
* A matcher for a specified property.
*
* @param propertyName
* the name of the property to match
* @param oldValue
* the old property value
* @param newValue
* the new property value
* @return {@code true} if the property exists and all parameters match the specified values;
* {@code false} otherwise
*/
public static Matcher property(String propertyName, Object oldValue, Object newValue) {
return new PropertyChangeEventMatcher(propertyName, oldValue, newValue);
}
/**
* This matcher returns {@code true} when the arguments are equivalent.
*
* For purposes of this matcher equivalence is as follows:
*
* - the objects are equal
* - the objects contain the same contents, insofar as the {@link java.beans.BeanInfo class
* info} for each object instance returns equivalent values
*
*
* @param
* the type of the matcher
* @param object
* the object to test
* @return {@code true} if the object is equivalent; {@code false} otherwise
*/
public static Matcher equivalentTo(T object) {
return new EquivalentMatcher(object);
}
}