Search in sources :

Example 61 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project bbct-android by BaseballCardTracker.

the class RecyclerViewMatcher method atPositionOnView.

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

        Resources resources = null;

        View childView;

        View targetView;

        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(String.format("with id: %s", 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) {
                    RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
                    if (viewHolder != null) {
                        childView = viewHolder.itemView;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            if (targetViewId == -1) {
                return view == childView;
            } else {
                if (targetView == null) {
                    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 62 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project terracotta-platform by Terracotta-OSS.

the class ConfigConversionIT method matches.

private static Matcher<Path> matches(String config) throws Exception {
    Path configPath = Paths.get(ConfigConversionIT.class.getResource(config).toURI());
    Properties expectedProps = Props.load(configPath);
    return new TypeSafeMatcher<Path>() {

        Path path;

        Properties props;

        @Override
        protected boolean matchesSafely(Path path) {
            this.path = path;
            this.props = Props.load(path);
            props.entrySet().forEach(e -> {
                if (e.getKey().toString().endsWith("-uid")) {
                    e.setValue("<uid>");
                }
            });
            props.entrySet().forEach(e -> {
                if (e.getKey().toString().endsWith(".stripe-name")) {
                    e.setValue("<generated>");
                }
            });
            return props.equals(expectedProps);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(path.getFileName() + " to contain:\n\n").appendText(Props.toString(expectedProps)).appendText("\nbut was:\n\n").appendText(Props.toString(props));
        }
    };
}
Also used : Path(java.nio.file.Path) RawPath(org.terracotta.dynamic_config.api.model.RawPath) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Properties(java.util.Properties)

Example 63 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project ApplicationInsights-Java by microsoft.

the class SpringBootControllerSpansEnabledTest method trackEvent.

@Test
@TargetUri("/basic/trackEvent")
public void trackEvent() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    mockedIngestion.waitForItemsInOperation("EventData", 2, operationId);
    // TODO get event data envelope and verify value
    List<EventData> data = mockedIngestion.getTelemetryDataByTypeInRequest("EventData");
    assertThat(data, hasItem(new TypeSafeMatcher<EventData>() {

        final String name = "EventDataTest";

        final Matcher<String> nameMatcher = Matchers.equalTo(name);

        @Override
        protected boolean matchesSafely(EventData item) {
            return nameMatcher.matches(item.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendDescriptionOf(nameMatcher);
        }
    }));
    assertThat(data, hasItem(new TypeSafeMatcher<EventData>() {

        final String expectedKey = "key";

        final String expectedName = "EventDataPropertyTest";

        final String expectedPropertyValue = "value";

        final Double expectedMetricValue = 1d;

        final Matcher<Map<? extends String, ? extends Double>> metricMatcher = Matchers.hasEntry(expectedKey, expectedMetricValue);

        final Matcher<Map<? extends String, ? extends String>> propertyMatcher = Matchers.hasEntry(expectedKey, expectedPropertyValue);

        final Matcher<String> nameMatcher = Matchers.equalTo(expectedName);

        @Override
        public void describeTo(Description description) {
            description.appendDescriptionOf(nameMatcher);
            description.appendDescriptionOf(propertyMatcher);
            description.appendDescriptionOf(metricMatcher);
        }

        @Override
        protected boolean matchesSafely(EventData item) {
            return nameMatcher.matches(item.getName()) && propertyMatcher.matches(item.getProperties()) && metricMatcher.matches(item.getMeasurements());
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matcher(org.hamcrest.Matcher) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) Test(org.junit.Test)

Example 64 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project ApplicationInsights-Java by microsoft.

the class SpringBootTest method trackEvent.

@Test
@TargetUri("/basic/trackEvent")
public void trackEvent() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    Envelope rdEnvelope = rdList.get(0);
    String operationId = rdEnvelope.getTags().get("ai.operation.id");
    mockedIngestion.waitForItemsInOperation("EventData", 2, operationId);
    // TODO get event data envelope and verify value
    List<EventData> data = mockedIngestion.getTelemetryDataByTypeInRequest("EventData");
    assertThat(data, hasItem(new TypeSafeMatcher<EventData>() {

        final String name = "EventDataTest";

        final Matcher<String> nameMatcher = Matchers.equalTo(name);

        @Override
        protected boolean matchesSafely(EventData item) {
            return nameMatcher.matches(item.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendDescriptionOf(nameMatcher);
        }
    }));
    assertThat(data, hasItem(new TypeSafeMatcher<EventData>() {

        final String expectedKey = "key";

        final String expectedName = "EventDataPropertyTest";

        final String expectedPropertyValue = "value";

        final Double expectedMetricValue = 1d;

        final Matcher<Map<? extends String, ? extends Double>> metricMatcher = Matchers.hasEntry(expectedKey, expectedMetricValue);

        final Matcher<Map<? extends String, ? extends String>> propertyMatcher = Matchers.hasEntry(expectedKey, expectedPropertyValue);

        final Matcher<String> nameMatcher = Matchers.equalTo(expectedName);

        @Override
        public void describeTo(Description description) {
            description.appendDescriptionOf(nameMatcher);
            description.appendDescriptionOf(propertyMatcher);
            description.appendDescriptionOf(metricMatcher);
        }

        @Override
        protected boolean matchesSafely(EventData item) {
            return nameMatcher.matches(item.getName()) && propertyMatcher.matches(item.getProperties()) && metricMatcher.matches(item.getMeasurements());
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matcher(org.hamcrest.Matcher) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) EventData(com.microsoft.applicationinsights.smoketest.schemav2.EventData) Test(org.junit.Test)

Example 65 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project OpenTracks by OpenTracksApp.

the class EspressoDeleteTrackTest method numberOfItemsListView.

private int numberOfItemsListView() {
    final int[] counts = new int[1];
    onView(withId(R.id.track_list)).check(matches(new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(View view) {
            ListView listView = (ListView) view;
            counts[0] = listView.getCount();
            return true;
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
    return counts[0];
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) ListView(android.widget.ListView) Description(org.hamcrest.Description) ViewMatchers.withContentDescription(androidx.test.espresso.matcher.ViewMatchers.withContentDescription) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) ListView(android.widget.ListView)

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