OverrideDescription.java
package fr.sii.ogham.testing.assertion.hamcrest;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
/**
* Override description generated by Hamcrest with a fixed string.
*
* @param <T>
* the type of the actual value
*
*
* @author Aurélien Baudet
*
*/
public class OverrideDescription<T> extends BaseMatcher<T> implements DecoratorMatcher<T>, CustomDescriptionProvider<T> {
private final String description;
private final Matcher<T> matcher;
public OverrideDescription(String description, Matcher<T> matcher) {
super();
this.description = description;
this.matcher = matcher;
}
@Override
public boolean matches(Object actual) {
return matcher.matches(actual);
}
@Override
public void describeTo(Description description) {
matcher.describeTo(description);
}
@Override
public Description describe(String reason, T actual, String additionalText) {
return new FixedDescription(description);
}
@Override
public Matcher<T> getDecoree() {
return matcher;
}
}