use of org.hamcrest.Description in project indy by Commonjava.
the class GroupDataManagerTCK method createAndRetrieveEmptyGroup.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void createAndRetrieveEmptyGroup() throws Exception {
final Group grp = new Group("test");
store(grp);
final Group result = manager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).getByName(grp.getName());
assertThat(result, notNullValue());
assertThat(result.getName(), equalTo(grp.getName()));
assertThat(result.getConstituents(), anyOf(nullValue(), new BaseMatcher<List>() {
@Override
public boolean matches(final Object item) {
return (item instanceof List) && ((List) item).isEmpty();
}
@Override
public void describeTo(final Description description) {
description.appendText("empty list");
}
}));
}
use of org.hamcrest.Description in project double-espresso by JakeWharton.
the class AdapterViewTest method withAdaptedData.
private static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with class name: ");
dataMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof AdapterView)) {
return false;
}
@SuppressWarnings("rawtypes") Adapter adapter = ((AdapterView) view).getAdapter();
for (int i = 0; i < adapter.getCount(); i++) {
if (dataMatcher.matches(adapter.getItem(i))) {
return true;
}
}
return false;
}
};
}
use of org.hamcrest.Description in project android_frameworks_base by DirtyUnicorns.
the class MockUtils method checkUserRestrictions.
public static Bundle checkUserRestrictions(String... keys) {
final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
final Matcher<Bundle> m = new BaseMatcher<Bundle>() {
@Override
public boolean matches(Object item) {
if (item == null)
return false;
return UserRestrictionsUtils.areEqual((Bundle) item, expected);
}
@Override
public void describeTo(Description description) {
description.appendText("User restrictions=" + getRestrictionsAsString(expected));
}
};
return Mockito.argThat(m);
}
use of org.hamcrest.Description in project double-espresso by JakeWharton.
the class DataInteraction method displayingData.
private Matcher<View> displayingData(final Matcher<View> adapterMatcher, final Matcher<Object> dataMatcher, final AdapterViewProtocol adapterViewProtocol, final AdapterDataLoaderAction adapterDataLoaderAction) {
checkNotNull(adapterMatcher);
checkNotNull(dataMatcher);
checkNotNull(adapterViewProtocol);
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText(" displaying data matching: ");
dataMatcher.describeTo(description);
description.appendText(" within adapter view matching: ");
adapterMatcher.describeTo(description);
}
@SuppressWarnings("unchecked")
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
while (parent != null && !(parent instanceof AdapterView)) {
parent = parent.getParent();
}
if (parent != null && adapterMatcher.matches(parent)) {
Optional<AdaptedData> data = adapterViewProtocol.getDataRenderedByView((AdapterView<? extends Adapter>) parent, view);
if (data.isPresent()) {
return adapterDataLoaderAction.getAdaptedData().opaqueToken.equals(data.get().opaqueToken);
}
}
return false;
}
};
}
use of org.hamcrest.Description in project intellij-plugins by JetBrains.
the class MatcherAssert method assertThat.
public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {
if (!matcher.matches(actual)) {
Description description = new StringDescription();
description.appendText(reason).appendText("\nExpected: ").appendDescriptionOf(matcher).appendText("\n but: ");
matcher.describeMismatch(actual, description);
throw new AssertionError(description.toString());
}
}
Aggregations