Search in sources :

Example 96 with Description

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");
        }
    }));
}
Also used : Group(org.commonjava.indy.model.core.Group) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) List(java.util.List) Test(org.junit.Test)

Example 97 with Description

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;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) AdapterView(android.widget.AdapterView) Adapter(android.widget.Adapter) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 98 with Description

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);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) Bundle(android.os.Bundle)

Example 99 with Description

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;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) AdapterView(android.widget.AdapterView) AdaptedData(com.google.android.apps.common.testing.ui.espresso.action.AdapterViewProtocol.AdaptedData) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 100 with Description

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());
    }
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription)

Aggregations

Description (org.hamcrest.Description)122 Test (org.junit.Test)38 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)29 BaseMatcher (org.hamcrest.BaseMatcher)27 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6