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

org.hamcrest.CustomTypeSafeMatcher 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 CustomTypeSafeMatcher<String>("a non empty string") {
 *   public boolean matchesSafely(String string) {
 *     return !string.isEmpty();
 *   }
 *   public void describeMismatchSafely(String string, Description mismatchDescription) {
 *     mismatchDescription.appendText("was empty");
 *   }
 * };
 * 
* This is a variant of {@link CustomMatcher} that first type checks * the argument being matched. By the time {@link TypeSafeMatcher#matchesSafely} is * is called the argument is guaranteed to be non-null and of the correct * type. * * @author Neil Dunn * @param The type of object being matched */ public abstract class CustomTypeSafeMatcher extends TypeSafeMatcher { private final String fixedDescription; public CustomTypeSafeMatcher(String description) { if (description == null) { throw new IllegalArgumentException("Description must be non null!"); } this.fixedDescription = description; } @Override public final void describeTo(Description description) { description.appendText(fixedDescription); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy