use of org.hamcrest.TypeSafeMatcher in project mule by mulesoft.
the class MessageProcessingFlowTraceManagerTestCase method hasExecutedProcessors.
private Matcher<ProcessorsTrace> hasExecutedProcessors(final String... expectedProcessors) {
return new TypeSafeMatcher<ProcessorsTrace>() {
private List<Matcher> failed = new ArrayList<>();
@Override
protected boolean matchesSafely(ProcessorsTrace processorsTrace) {
Matcher<Collection<? extends Object>> sizeMatcher = hasSize(expectedProcessors.length);
if (!sizeMatcher.matches(processorsTrace.getExecutedProcessors())) {
failed.add(sizeMatcher);
}
int i = 0;
for (String expectedProcessor : expectedProcessors) {
Matcher processorItemMatcher = is(expectedProcessor);
if (!processorItemMatcher.matches(processorsTrace.getExecutedProcessors().get(i))) {
failed.add(processorItemMatcher);
}
++i;
}
return failed.isEmpty();
}
@Override
public void describeTo(Description description) {
description.appendValue(Arrays.asList(expectedProcessors));
}
@Override
protected void describeMismatchSafely(ProcessorsTrace item, Description description) {
description.appendText("was ").appendValue(item.getExecutedProcessors());
}
};
}
use of org.hamcrest.TypeSafeMatcher in project openScale by oliexdev.
the class UserAddTest 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));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project linkki by linkki-framework.
the class OkCancelDialogTest method displayingMessage.
private Matcher<OkCancelDialog> displayingMessage(String text) {
return new TypeSafeMatcher<OkCancelDialog>() {
@SuppressWarnings("null")
@Override
public void describeTo(Description description) {
description.appendText("an OkCancelDialog displaying a message with the text '");
description.appendText(text);
description.appendText("'");
}
@SuppressWarnings("null")
@Override
protected boolean matchesSafely(OkCancelDialog dialog) {
VerticalLayout layout = (VerticalLayout) dialog.getContent();
VerticalLayout nestedLayout = (VerticalLayout) layout.getComponent(0);
return components(nestedLayout).filter(MessageRow.class::isInstance).findFirst().map(c -> ((MessageRow) c).getText().equals(text)).orElse(false);
}
};
}
use of org.hamcrest.TypeSafeMatcher in project kiwix-android by kiwix.
the class ContentTest 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));
}
};
}
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;
}
};
}
Aggregations