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;
}
}
};
}
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));
}
};
}
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());
}
}));
}
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());
}
}));
}
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];
}
Aggregations