Search in sources :

Example 91 with Description

use of org.hamcrest.Description in project neo4j by neo4j.

the class Assert method assertEventually.

public static <T, E extends Exception> void assertEventually(String reason, ThrowingSupplier<T, E> actual, Matcher<? super T> matcher, long timeout, TimeUnit timeUnit) throws E, InterruptedException {
    long endTimeMillis = System.currentTimeMillis() + timeUnit.toMillis(timeout);
    T last;
    boolean matched;
    do {
        long sampleTime = System.currentTimeMillis();
        last = actual.get();
        matched = matcher.matches(last);
        if (matched || sampleTime > endTimeMillis) {
            break;
        }
        Thread.sleep(100);
    } while (true);
    if (!matched) {
        Description description = new StringDescription();
        description.appendText(reason).appendText("\nExpected: ").appendDescriptionOf(matcher).appendText("\n     but: ");
        matcher.describeMismatch(last, description);
        throw new AssertionError("Timeout hit (" + timeout + " " + timeUnit.toString().toLowerCase() + ") while waiting for condition to match: " + description.toString());
    }
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription)

Example 92 with Description

use of org.hamcrest.Description in project neo4j by neo4j.

the class DBMSModuleTest method shouldNotRegisterUserServiceWhenAuthDisabled.

@SuppressWarnings("unchecked")
@Test
public void shouldNotRegisterUserServiceWhenAuthDisabled() throws Exception {
    WebServer webServer = mock(WebServer.class);
    Config config = mock(Config.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(false);
    DBMSModule module = new DBMSModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(anyList(), anyString(), anyCollection());
    verify(webServer, never()).addJAXRSClasses(Matchers.argThat(new ArgumentMatcher<List<String>>() {

        @Override
        public boolean matches(Object argument) {
            List<String> argumentList = (List<String>) argument;
            return argumentList.contains(UserService.class.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("<List containing " + UserService.class.getName() + ">");
        }
    }), anyString(), anyCollection());
}
Also used : Description(org.hamcrest.Description) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) UserService(org.neo4j.server.rest.dbms.UserService) Config(org.neo4j.kernel.configuration.Config) ArgumentMatcher(org.mockito.ArgumentMatcher) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 93 with Description

use of org.hamcrest.Description in project double-espresso by JakeWharton.

the class RootMatchers method isDialog.

/**
   * Matches {@link Root}s that are dialogs (i.e. is not a window of the currently resumed
   * activity).
   */
public static Matcher<Root> isDialog() {
    return new TypeSafeMatcher<Root>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("is dialog");
        }

        @Override
        public boolean matchesSafely(Root root) {
            int type = root.getWindowLayoutParams().get().type;
            if ((type != WindowManager.LayoutParams.TYPE_BASE_APPLICATION && type < WindowManager.LayoutParams.LAST_APPLICATION_WINDOW)) {
                IBinder windowToken = root.getDecorView().getWindowToken();
                IBinder appToken = root.getDecorView().getApplicationWindowToken();
                if (windowToken == appToken) {
                    // therefore it must be a dialog box.
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : IBinder(android.os.IBinder) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Root(com.google.android.apps.common.testing.ui.espresso.Root)

Example 94 with Description

use of org.hamcrest.Description in project double-espresso by JakeWharton.

the class ViewMatchers method withChild.

/**
   * A matcher that returns true if and only if the view's child is accepted by the provided
   * matcher.
   *
   * @param childMatcher the matcher to apply on the child views.
   */
public static Matcher<View> withChild(final Matcher<View> childMatcher) {
    checkNotNull(childMatcher);
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("has child: ");
            childMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            if (!(view instanceof ViewGroup)) {
                return false;
            }
            ViewGroup group = (ViewGroup) view;
            for (int i = 0; i < group.getChildCount(); i++) {
                if (childMatcher.matches(group.getChildAt(i))) {
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View)

Example 95 with Description

use of org.hamcrest.Description in project double-espresso by JakeWharton.

the class ViewMatchers method hasSibling.

/**
   * Returns an {@link Matcher} that matches {@link View}s based on their siblings.<br>
   * <br>
   * This may be particularly useful when a view cannot be uniquely selected on properties such as
   * text or R.id. For example: a call button is repeated several times in a contacts layout and the
   * only way to differentiate the call button view is by what appears next to it (e.g. the unique
   * name of the contact).
   *
   * @param siblingMatcher a {@link Matcher} for the sibling of the view.
   */
public static Matcher<View> hasSibling(final Matcher<View> siblingMatcher) {
    checkNotNull(siblingMatcher);
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("has sibling: ");
            siblingMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            if (!(parent instanceof ViewGroup)) {
                return false;
            }
            ViewGroup parentGroup = (ViewGroup) parent;
            for (int i = 0; i < parentGroup.getChildCount(); i++) {
                if (siblingMatcher.matches(parentGroup.getChildAt(i))) {
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View)

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