use of org.hamcrest.TypeSafeMatcher in project beam by apache.
the class CombineFnTesterTest method usesMatcher.
@Test
public void usesMatcher() {
final AtomicBoolean matcherUsed = new AtomicBoolean();
Matcher<Integer> matcher = new TypeSafeMatcher<Integer>() {
@Override
public void describeTo(Description description) {
}
@Override
protected boolean matchesSafely(Integer item) {
matcherUsed.set(true);
return item == 30;
}
};
CombineFnTester.testCombineFn(Sum.ofIntegers(), Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), matcher);
assertThat(matcherUsed.get(), is(true));
try {
CombineFnTester.testCombineFn(Sum.ofIntegers(), Arrays.asList(1, 2, 3, 4, 5), Matchers.not(Matchers.equalTo(15)));
} catch (AssertionError ignored) {
// Success! Return to avoid the call to fail();
return;
}
fail("The matcher should have failed, throwing an error");
}
use of org.hamcrest.TypeSafeMatcher in project Team-Plant-Power by Alexander1994.
the class HistoricalHumidityTest 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 ChipsLayoutManager by BelooS.
the class RecyclerViewEspressoFactory method orderMatcher.
// /////////////////////////////////////////////////////////////////////////
// Matcher
// /////////////////////////////////////////////////////////////////////////
private static Matcher<View> orderMatcher() {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with correct position order");
}
@Override
public boolean matchesSafely(View v) {
RecyclerView view = (RecyclerView) v;
if (view.getLayoutManager() == null)
return false;
ChildViewsIterable childViews = new ChildViewsIterable(view.getLayoutManager());
int pos = view.getChildAdapterPosition(childViews.iterator().next());
for (View child : childViews) {
if (pos != view.getChildAdapterPosition(child)) {
return false;
}
pos++;
}
return true;
}
};
}
use of org.hamcrest.TypeSafeMatcher in project junit4 by junit-team.
the class EventCollector method hasSingleFailureWithMessage.
static Matcher<EventCollector> hasSingleFailureWithMessage(final Matcher<String> messageMatcher) {
return new TypeSafeMatcher<EventCollector>() {
@Override
public boolean matchesSafely(EventCollector item) {
return hasSingleFailure().matches(item) && messageMatcher.matches(item.fFailures.get(0).getMessage());
}
public void describeTo(org.hamcrest.Description description) {
description.appendText("has single failure with message ");
messageMatcher.describeTo(description);
}
@Override
protected void describeMismatchSafely(EventCollector item, org.hamcrest.Description description) {
description.appendText("was ");
hasSingleFailure().describeMismatch(item, description);
description.appendText(": ");
boolean first = true;
for (Failure f : item.fFailures) {
if (!first) {
description.appendText(" ,");
}
description.appendText("'");
description.appendText(f.getMessage());
description.appendText("'");
first = false;
}
}
};
}
use of org.hamcrest.TypeSafeMatcher in project junit4 by junit-team.
the class EventCollector method failureIs.
static Matcher<EventCollector> failureIs(final Matcher<? super Throwable> exceptionMatcher) {
return new TypeSafeMatcher<EventCollector>() {
@Override
public boolean matchesSafely(EventCollector item) {
for (Failure f : item.fFailures) {
return exceptionMatcher.matches(f.getException());
}
return false;
}
public void describeTo(org.hamcrest.Description description) {
description.appendText("failure is ");
exceptionMatcher.describeTo(description);
}
};
}
Aggregations