Search in sources :

Example 71 with TypeSafeMatcher

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

the class TransportTestUtil method eventuallyReceives.

public static Matcher<TransportConnection> eventuallyReceives(final Matcher<ResponseMessage>... messages) {
    return new TypeSafeMatcher<TransportConnection>() {

        @Override
        protected boolean matchesSafely(TransportConnection conn) {
            try {
                for (Matcher<ResponseMessage> matchesMessage : messages) {
                    final ResponseMessage message = receiveOneResponseMessage(conn);
                    assertThat(message, matchesMessage);
                }
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendValueList("Messages[", ",", "]", messages);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) Description(org.hamcrest.Description) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) IOException(java.io.IOException)

Example 72 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project sonarqube by SonarSource.

the class ReportSubmitterTest method submit_a_report_on_existing_project.

@Test
public void submit_a_report_on_existing_project() {
    ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
    userSession.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    mockSuccessfulPrepareSubmitCall();
    underTest.submit(defaultOrganizationKey, project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verifyZeroInteractions(permissionTemplateService);
    verifyZeroInteractions(favoriteUpdater);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(project.uuid()) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) Test(org.junit.Test)

Example 73 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project sonarqube by SonarSource.

the class ReportSubmitterTest method provision_project_if_does_not_exist.

@Test
public void provision_project_if_does_not_exist() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    userSession.addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID).addPermission(PROVISION_PROJECTS, organization);
    mockSuccessfulPrepareSubmitCall();
    ComponentDto createdProject = newProjectDto(organization, PROJECT_UUID).setKey(PROJECT_KEY);
    when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject);
    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), anyInt(), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT))).thenReturn(true);
    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), eq(organization.getUuid()), any(ComponentDto.class))).thenReturn(true);
    underTest.submit(organization.getKey(), PROJECT_KEY, null, PROJECT_NAME, IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(PROJECT_UUID) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : DbSession(org.sonar.db.DbSession) NewComponent(org.sonar.server.component.NewComponent) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 74 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher 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 75 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project wire-android by wireapp.

the class CustomMatchers method guidedEditTextWithId.

/**
     * Typing with regular {@link android.support.test.espresso.matcher.ViewMatchers#withId(int)} matchers won't work on a
     * GuidedEditText (GET) because the GET hides the EditText which Espresso needs. This matcher searches for an edit
     * text under a grandparent with the given id that has the type GET
     * @param id the id of the GuidedEditText which we want to type (or perform other actions) into
     * @return an Espresso compatible Matcher<View> for use in onView();
     */
public static Matcher<View> guidedEditTextWithId(final int id) {
    return new TypeSafeMatcher<View>() {

        Resources resources = null;

        @Override
        public void describeTo(Description description) {
            String idDescription = Integer.toString(id);
            if (resources != null) {
                try {
                    idDescription = resources.getResourceName(id);
                } catch (Resources.NotFoundException e) {
                    // No big deal, will just use the int value.
                    idDescription = String.format("%s (resource name not found)", id);
                }
            }
            description.appendText("with id: " + idDescription);
        }

        @Override
        public boolean matchesSafely(View view) {
            resources = view.getResources();
            GuidedEditText grandParent = getGrandParent(view);
            return grandParent != null && id == grandParent.getId() && view instanceof TypefaceEditText;
        }

        private GuidedEditText getGrandParent(View view) {
            ViewParent parent = view.getParent();
            if (!(parent instanceof FrameLayout)) {
                return null;
            }
            ViewParent grandParent = parent.getParent();
            if (!(grandParent instanceof GuidedEditText)) {
                return null;
            }
            return (GuidedEditText) grandParent;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) TypefaceEditText(com.waz.zclient.ui.text.TypefaceEditText) FrameLayout(android.widget.FrameLayout) Resources(android.content.res.Resources) GuidedEditText(com.waz.zclient.pages.main.profile.views.GuidedEditText) View(android.view.View)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)124 Description (org.hamcrest.Description)121 View (android.view.View)62 ViewParent (android.view.ViewParent)43 ViewGroup (android.view.ViewGroup)40 Espresso.onView (android.support.test.espresso.Espresso.onView)26 Espresso.onView (androidx.test.espresso.Espresso.onView)11 TextView (android.widget.TextView)10 Resources (android.content.res.Resources)9 Test (org.junit.Test)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 ArrayList (java.util.ArrayList)6 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 ViewMatchers.withContentDescription (androidx.test.espresso.matcher.ViewMatchers.withContentDescription)5 List (java.util.List)5 StringDescription (org.hamcrest.StringDescription)5 AdapterView (android.widget.AdapterView)4