Search in sources :

Example 56 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project data-access by pentaho.

the class DatasourceResourceIT method testImportFile.

private void testImportFile(String filePath, final String expectedSchemaName) throws Exception {
    FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
    when(schemaFileInfo.getFileName()).thenReturn("stubFileName");
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    mockery.checking(new Expectations() {

        {
            oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                public boolean matchesSafely(IPlatformImportBundle bundle) {
                    return bundle.getProperty("domain-id").equals(expectedSchemaName) && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
                }

                public void describeTo(Description description) {
                    description.appendText("bundle with mondrian schema");
                }
            })));
        }
    });
    AnalysisService service = new AnalysisService();
    FileInputStream in = new FileInputStream(filePath);
    try {
        service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Example 57 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project collect by getodk.

the class RecyclerViewMatcher method atPositionOnView.

public Matcher<View> atPositionOnView(final int position, final int targetViewId) {
    return new TypeSafeMatcher<View>() {

        Resources resources;

        View childView;

        public void describeTo(Description description) {
            String idDescription = Integer.toString(recyclerViewId);
            if (this.resources != null) {
                try {
                    idDescription = this.resources.getResourceName(recyclerViewId);
                } catch (Resources.NotFoundException var4) {
                    idDescription = String.format("%s (resource name not found)", recyclerViewId);
                }
            }
            description.appendText("RecyclerView with id: " + idDescription + " at position: " + position);
        }

        public boolean matchesSafely(View view) {
            this.resources = view.getResources();
            if (childView == null) {
                RecyclerView recyclerView = view.getRootView().findViewById(recyclerViewId);
                if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
                    RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
                    if (viewHolder != null) {
                        childView = viewHolder.itemView;
                    }
                } else {
                    return false;
                }
            }
            if (targetViewId == -1) {
                return view == childView;
            } else {
                View targetView = childView.findViewById(targetViewId);
                return view == targetView;
            }
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) RecyclerView(androidx.recyclerview.widget.RecyclerView) Resources(android.content.res.Resources) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 58 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project android-test by android.

the class DomMatchersTest method testWithBody_DocumentWithNoBody.

@Test
public void testWithBody_DocumentWithNoBody() throws Exception {
    Document documentWithNoBody = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new StringBufferInputStream(HTML_NO_BODY));
    Matcher<Element> alwaysMatch = new TypeSafeMatcher<Element>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("always a match");
        }

        @Override
        public boolean matchesSafely(Element element) {
            return true;
        }
    };
    assertFalse(withBody(alwaysMatch).matches(documentWithNoBody));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) StringBufferInputStream(java.io.StringBufferInputStream) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 59 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project Catroid by Catrobat.

the class RecyclerViewMatcher method atPositionOnView.

public Matcher<View> atPositionOnView(final int position, final int targetViewId) {
    return new TypeSafeMatcher<View>() {

        Resources resources = null;

        View childView;

        public void describeTo(Description description) {
            String idDescription = Integer.toString(recyclerViewId);
            if (this.resources != null) {
                try {
                    idDescription = this.resources.getResourceName(recyclerViewId);
                } catch (Resources.NotFoundException ignored) {
                    idDescription = String.format("%s (resource name not found)", recyclerViewId);
                }
            }
            description.appendText("with id: " + idDescription);
        }

        public boolean matchesSafely(View view) {
            this.resources = view.getResources();
            if (childView == null) {
                RecyclerView recyclerView = view.getRootView().findViewById(recyclerViewId);
                if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
                    childView = recyclerView.findViewHolderForAdapterPosition(position).itemView;
                } else {
                    return false;
                }
            }
            if (targetViewId == -1) {
                return view == childView;
            } else {
                View targetView = childView.findViewById(targetViewId);
                return view == targetView;
            }
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) RecyclerView(androidx.recyclerview.widget.RecyclerView) Resources(android.content.res.Resources) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 60 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project pay-connector by alphagov.

the class XMLUnmarshallerSecurityTest method unmarshalExceptionWithLinkedSAXParseException.

private Matcher<Throwable> unmarshalExceptionWithLinkedSAXParseException(final String expectedMessage) {
    return new TypeSafeMatcher<Throwable>() {

        @Override
        protected boolean matchesSafely(Throwable throwable) {
            if (throwable instanceof UnmarshalException) {
                UnmarshalException ex = (UnmarshalException) throwable;
                Throwable linkedException = ex.getLinkedException();
                if (linkedException instanceof SAXParseException) {
                    return expectedMessage.equals(linkedException.getMessage());
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("UnmarshalException with linked exception to be SAXParseException").appendText(" and message: '").appendValue(expectedMessage).appendText("'");
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) UnmarshalException(javax.xml.bind.UnmarshalException) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)130 Description (org.hamcrest.Description)127 View (android.view.View)64 ViewParent (android.view.ViewParent)44 ViewGroup (android.view.ViewGroup)41 Espresso.onView (android.support.test.espresso.Espresso.onView)26 Espresso.onView (androidx.test.espresso.Espresso.onView)12 Test (org.junit.Test)11 TextView (android.widget.TextView)10 Resources (android.content.res.Resources)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 ViewMatchers.withContentDescription (androidx.test.espresso.matcher.ViewMatchers.withContentDescription)6 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 List (java.util.List)5 Matcher (org.hamcrest.Matcher)5 StringDescription (org.hamcrest.StringDescription)5