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

org.hamcrest.CustomMatcher Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package org.hamcrest;

/**
 * Utility class for writing one off matchers.
 * For example:
 * 
 * Matcher<String> aNonEmptyString = new CustomMatcher<String>("a non empty string") {
 *   public boolean matches(Object object) {
 *     return ((object instanceof String) && !((String) object).isEmpty();
 *   }
 * };
 * 
*

* This class is designed for scenarios where an anonymous inner class * matcher makes sense. It should not be used by API designers implementing * matchers. * * @author Neil Dunn * @see CustomTypeSafeMatcher for a type safe variant of this class that you probably * want to use. * @param The type of object being matched. */ public abstract class CustomMatcher extends BaseMatcher { private final String fixedDescription; public CustomMatcher(String description) { if (description == null) { throw new IllegalArgumentException("Description should be non null!"); } this.fixedDescription = description; } @Override public final void describeTo(Description description) { description.appendText(fixedDescription); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy