Search in sources :

Example 96 with TypeSafeMatcher

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

the class TestUtils method childAtPosition.

public static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 97 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project pixabayapp by gkaffka.

the class MainActivityTest method childAtPosition.

private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 98 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project SEProject by NicholasBarreyre.

the class Matchers method withAdaptedData.

/**
 * AdapterView matcher
 * https://developer.android.com/training/testing/espresso/recipes.html
 *
 * @param dataMatcher
 * @return
 */
public 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) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 99 with TypeSafeMatcher

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

the class AssertEvents method defaultUserId.

public Matcher<String> defaultUserId() {
    return new TypeSafeMatcher<String>() {

        private String userId;

        @Override
        protected boolean matchesSafely(String item) {
            return item.equals(getUserId());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(getUserId());
        }

        private String getUserId() {
            if (userId == null) {
                UserRepresentation user = getUser(DEFAULT_USERNAME);
                if (user == null) {
                    throw new RuntimeException("Default user does not exist: " + DEFAULT_USERNAME + ". Make sure to add it to your test realm.");
                }
                userId = user.getId();
            }
            return userId;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Example 100 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project JSCover by tntim96.

the class MainTest method shouldRunCoberturaXmlReport.

@Test
public void shouldRunCoberturaXmlReport() throws IOException {
    given(config.getReportFormat()).willReturn(ReportFormat.COBERTURAXML);
    given(config.getVersion()).willReturn("version");
    File jsonDirectory = new File("jsonDir");
    File srcDir = new File("src");
    given(config.getJsonDirectory()).willReturn(jsonDirectory);
    given(config.getSourceDirectory()).willReturn(srcDir);
    String json = "json";
    given(ioUtils.loadFromFileSystem(new File(jsonDirectory, "jscoverage.json"))).willReturn(json);
    doReturn(srcDir.getCanonicalPath()).when(ioUtils).getCanonicalPath(srcDir);
    SortedMap<String, FileData> list = new TreeMap<>();
    given(jsonDataMerger.jsonToMap(json)).willReturn(list);
    given(coberturaXmlGenerator.generateXml(ArgumentMatchers.any(), anyString(), anyString())).willReturn("<xml/>");
    main.runMain(new String[] {});
    TypeSafeMatcher<CoberturaData> coberturaDataMatcher = new TypeSafeMatcher<CoberturaData>() {

        @Override
        protected boolean matchesSafely(CoberturaData coverable) {
            return true;
        }

        public void describeTo(Description description) {
        }
    };
    File xmlFile = new File(jsonDirectory, "cobertura-coverage.xml");
    verify(coberturaXmlGenerator).generateXml(argThat(coberturaDataMatcher), argThat(is(srcDir.getCanonicalPath())), argThat(is("version")));
    verify(ioUtils).copy("<xml/>", xmlFile);
    verifyNoInteractions(exitHelper);
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) TreeMap(java.util.TreeMap) File(java.io.File) CoberturaData(jscover.report.coberturaxml.CoberturaData) Test(org.junit.Test)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)123 Description (org.hamcrest.Description)120 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