下面列出了org.hamcrest.Matchers#not ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void addMatcher_doesNotNegateMatcher_when_negateNextMatcher_isFalse() {
final Start.Matcher matcher = Cortado.view();
final Cortado cortado = matcher.getCortado();
assertThat(cortado.matchers).hasSize(0);
assertThat(cortado.negateNextMatcher).isFalse();
// no matchers added, negateNextMatcher is false
org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");
org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);
cortado.negateNextMatcher = false;
cortado.addMatcher(viewMatcher);
assertThat(cortado.matchers).hasSize(1);
// one matcher added
assertThat(cortado.negateNextMatcher).isFalse();
// negateNextMatcher is still false
final Matcher<? super View> addedMatcher = cortado.matchers.get(0);
Utils.assertThat(addedMatcher).isEqualTo(viewMatcher);
Utils.assertThat(addedMatcher).isNotEqualTo(negatedViewMatcher);
}
@Test
public void addMatcher_negatesMatcher_when_negateNextMatcher_isTrue() {
final Start.Matcher matcher = Cortado.view();
final Cortado cortado = matcher.getCortado();
assertThat(cortado.matchers).hasSize(0);
assertThat(cortado.negateNextMatcher).isFalse();
// no matchers added, negateNextMatcher is false
org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");
org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);
cortado.negateNextMatcher = true;
cortado.addMatcher(viewMatcher);
assertThat(cortado.matchers).hasSize(1);
// one matcher added
assertThat(cortado.negateNextMatcher).isFalse();
// negateNextMatcher is back to false
final Matcher<? super View> addedMatcher = cortado.matchers.get(0);
Utils.assertThat(addedMatcher).isNotEqualTo(viewMatcher);
Utils.assertThat(addedMatcher).isEqualTo(negatedViewMatcher);
}
@VisibleForTesting
final void addMatcher(org.hamcrest.Matcher<View> matcher) {
if (negateNextMatcher) {
negateNextMatcher = false;
matcher = Matchers.not(matcher);
}
matchers.add(matcher);
}
/** Creates a matcher that matches if the examined {@link DisplayData} contains any items. */
public static Matcher<DisplayData> hasDisplayItem() {
return new FeatureMatcher<DisplayData, Collection<DisplayData.Item>>(
Matchers.not(Matchers.empty()), "DisplayData", "DisplayData") {
@Override
protected Collection<Item> featureValueOf(DisplayData actual) {
return actual.items();
}
};
}
private static Matcher<Iterable<? super String>> getDefaultClientScopeNameMatcher(ClientRepresentation rep) {
switch (rep.getClientId()) {
case "client-with-template":
return Matchers.hasItem("Default_test_template");
default:
return Matchers.not(Matchers.hasItem("Default_test_template"));
}
}
public static Matcher<Iterable<? super ValidationMessage>> noValidationInCollection() {
return Matchers.not(Matchers.hasItem(new AnyValidationMessageMatcher()));
}
public static Matcher<Iterable<? super ValidationViolation>> noValidationInCollection() {
return Matchers.not(Matchers.hasItem(new AnyValidationViolationMatcher()));
}
protected Matcher<? super T> negatedIfNeeded(final Matcher<? super T> matcher) {
return positive ? matcher : Matchers.not(matcher);
}