September 2016
Intermediate to advanced
336 pages
9h 33m
English
LISTING B.1 PremiumPurchaseMatcher: A custom matcher that matches specific business rules.
import org.hamcrest.Description;import org.hamcrest.TypeSafeMatcher;public class PremiumPurchaseMatcher extends TypeSafeMatcher<Purchase> { @Override public boolean matchesSafely(Purchase purchase) { return purchase.getPrice() > 1000 && purchase.getItemCount() < 5; } @Override public void describeTo(Description desc) { desc.appendText("A purchase with the " + "total price > 1000 and fewer than 5 items"); }}
LISTING B.2 A JUnit-based implementation of a parameterized test.
Read now
Unlock full access