concept matcher in category java

This is an excerpt from Manning's book JUnit in Action, Second Edition.
To solve this problem we’re going to present a library of matchers for building test expressions. Hamcrest (http://code.google.com/p/hamcrest/) is a library that contains a lot of helpful matcher objects (known also as constraints or predicates), ported in several languages (Java, C++, Objective-C, Python, and PHP). Note that Hamcrest isn’t a testing framework itself, but rather it helps you declaratively specify simple matching rules. These matching rules can be used in many different situations, but they’re particularly helpful for unit testing.
Fortunately, there is a way, and that’s exactly what we show next. We start by implementing a simple matcher that checks whether a given string is null or empty. Listing B.8 shows the code for the matcher.
Basically, if we want to create a custom matcher, we need to extend one of the two classes BaseMatcher<T> or TypeSafeMatcher<T>. In this listing, we extend the first one
. Next, we override the matches method
, and we implement our logic on what occasion the matcher will match the conditions; our condition is matched successfully if the string parameter to which it is applied is not null and is different from an empty string.
. Next, we override the matches method
, and we implement our logic on what occasion the matcher will match the conditions; our condition is matched successfully if the string parameter to which it is applied is not null and is different from an empty string.