Java Code Examples for org.hamcrest.Matchers#not()

The following examples show how to use org.hamcrest.Matchers#not() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cortado_Tests.java    From cortado with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: Cortado_Tests.java    From cortado with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: Cortado.java    From cortado with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
final void addMatcher(org.hamcrest.Matcher<View> matcher) {
    if (negateNextMatcher) {
        negateNextMatcher = false;
        matcher = Matchers.not(matcher);
    }
    matchers.add(matcher);
}
 
Example 4
Source File: DisplayDataMatchers.java    From beam with Apache License 2.0 5 votes vote down vote up
/** 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();
    }
  };
}
 
Example 5
Source File: ExportImportUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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"));
    }
}
 
Example 6
Source File: AnyValidationMessageMatcher.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
public static Matcher<Iterable<? super ValidationMessage>> noValidationInCollection() {
    return Matchers.not(Matchers.hasItem(new AnyValidationMessageMatcher()));
}
 
Example 7
Source File: AnyValidationViolationMatcher.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
public static Matcher<Iterable<? super ValidationViolation>> noValidationInCollection() {
    return Matchers.not(Matchers.hasItem(new AnyValidationViolationMatcher()));
}
 
Example 8
Source File: BoundExpectation.java    From lambda-behave with MIT License 4 votes vote down vote up
protected Matcher<? super T> negatedIfNeeded(final Matcher<? super T> matcher) {
    return positive ? matcher : Matchers.not(matcher);
}