org.hamcrest
Class CustomTypeSafeMatcher<T>

java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.hamcrest.TypeSafeMatcher<T>
          extended by org.hamcrest.CustomTypeSafeMatcher<T>
Type Parameters:
T - The type of object being matched
All Implemented Interfaces:
Matcher<T>, SelfDescribing

public abstract class CustomTypeSafeMatcher<T>
extends TypeSafeMatcher<T>

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 CustomMatcher that first type checks the argument being matched. By the time TypeSafeMatcher.matchesSafely(T) is is called the argument is guaranteed to be non-null and of the correct type.


Constructor Summary
CustomTypeSafeMatcher(String description)
           
 
Method Summary
 void describeTo(Description description)
          Generates a description of the object.
 
Methods inherited from class org.hamcrest.TypeSafeMatcher
describeMismatch, describeMismatchSafely, matches, matchesSafely
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CustomTypeSafeMatcher

public CustomTypeSafeMatcher(String description)
Method Detail

describeTo

public final void describeTo(Description description)
Description copied from interface: SelfDescribing
Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters:
description - The description to be built or appended to.


Copyright © 2002–2020 JUnit. All rights reserved.