use of org.hamcrest.Description in project material-components-android by material-components.
the class TestUtilsMatchers method withStartDrawableFilledWith.
/**
* Returns a matcher that matches TextViews whose start drawable is filled with the specified fill
* color.
*/
public static Matcher withStartDrawableFilledWith(@ColorInt final int fillColor, final int allowedComponentVariance) {
return new BoundedMatcher<View, TextView>(TextView.class) {
private String failedCheckDescription;
@Override
public void describeTo(final Description description) {
description.appendText(failedCheckDescription);
}
@Override
public boolean matchesSafely(final TextView view) {
final Drawable[] compoundDrawables = view.getCompoundDrawables();
final boolean isRtl = (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL);
final Drawable startDrawable = isRtl ? compoundDrawables[2] : compoundDrawables[0];
if (startDrawable == null) {
failedCheckDescription = "no start drawable";
return false;
}
try {
final Rect bounds = startDrawable.getBounds();
TestUtils.assertAllPixelsOfColor("", startDrawable, bounds.width(), bounds.height(), true, fillColor, allowedComponentVariance, true);
} catch (Throwable t) {
failedCheckDescription = t.getMessage();
return false;
}
return true;
}
};
}
use of org.hamcrest.Description in project junit4 by junit-team.
the class Guesser method reguesses.
@Override
public List<ReguessableValue> reguesses(AssumptionViolatedException e) {
final ArrayList<ReguessableValue> returnThis = new ArrayList<ReguessableValue>();
e.describeTo(new BaseDescription() {
@Override
protected void append(char arg0) {
}
boolean expectedSeen = false;
Object expected = null;
@Override
public Description appendValue(Object value) {
noteValue(value);
return super.appendValue(value);
}
private void noteValue(Object value) {
if (!expectedSeen) {
expected = value;
expectedSeen = true;
return;
}
GuessMap newGuesses = guesses.replaceGuess(expected, value);
returnThis.add(new Guesser<T>(getType(), newGuesses));
}
});
return returnThis;
}
use of org.hamcrest.Description in project cucumber-jvm by cucumber.
the class AbstractMatcherTest method assertDescription.
public static void assertDescription(String expected, Matcher<?> matcher) {
Description description = new StringDescription();
description.appendDescriptionOf(matcher);
Assert.assertEquals("Expected description", expected, description.toString().trim());
}
use of org.hamcrest.Description in project cucumber-jvm by cucumber.
the class AbstractMatcherTest method mismatchDescription.
public static <T> String mismatchDescription(Matcher<? super T> matcher, T arg) {
Description description = new StringDescription();
matcher.describeMismatch(arg, description);
return description.toString().trim();
}
use of org.hamcrest.Description in project gradle by gradle.
the class FileCollectionMatchers method sameCollection.
@Factory
public static <T extends FileCollection> Matcher<T> sameCollection(final FileCollection expected) {
return new BaseMatcher<T>() {
public boolean matches(Object o) {
FileCollection actual = (FileCollection) o;
List<? extends FileCollection> actualCollections = unpack(actual);
List<? extends FileCollection> expectedCollections = unpack(expected);
boolean equals = actualCollections.equals(expectedCollections);
if (!equals) {
System.out.println("expected: " + expectedCollections);
System.out.println("actual: " + actualCollections);
}
return equals;
}
private List<? extends FileCollection> unpack(FileCollection expected) {
if (expected instanceof UnionFileCollection) {
UnionFileCollection collection = (UnionFileCollection) expected;
return new ArrayList<FileCollection>(collection.getSources());
}
if (expected instanceof DefaultConfigurableFileCollection) {
DefaultConfigurableFileCollection collection = (DefaultConfigurableFileCollection) expected;
return new ArrayList<FileCollection>((Set) collection.getFrom());
}
if (expected instanceof CompositeFileCollection) {
CompositeFileCollection collection = (CompositeFileCollection) expected;
DefaultFileCollectionResolveContext context = new DefaultFileCollectionResolveContext(TestFiles.resolver());
collection.visitContents(context);
return context.resolveAsFileCollections();
}
throw new RuntimeException("Cannot get children of " + expected);
}
public void describeTo(Description description) {
description.appendText("same file collection as ").appendValue(expected);
}
};
}
Aggregations