Skip to content

hasValueNotEqualTo #3701

@xenoterracide

Description

@xenoterracide

Feature summary

The inverse of optional.hasValue() essentially the wrapped object not equal to.

Example

    assertThat(Optional.of("foo"))
      .isPresent()
      .hasValue("foo")
      .hasValueNotEqualTo("bar");

not and equalTo are the methods on java Predicate. Obviously this feature is not useful for this example, but included because it would compile ;)

    assertThat(Optional.of("foo"))
      .isPresent()
      .hasValue("foo")
      .hasValueSatisfying(new Condition<>(not(isEqual("bar")), "not equal to " + "bar"));

it is when values are dynamic though

    var oid2 = commit(git);
    assertThat(mb.find(origin))
      .isPresent()
      .hasValue(remoteHead.apply())
      .hasValueSatisfying(new Condition<>(not(isEqual(oid2)), "not equal to " + oid2));
    var oid2 = commit(git);
    assertThat(mb.find(origin))
      .isPresent()
      .hasValue(remoteHead.apply())
      .hasValueNotEqualTo(oid2);

Maybe an alternative would be to start developing a Conditions library (although maybe this is too much like hamcrest)

    assertThat(Optional.of("foo"))
      .isPresent()
      .hasValue("foo")
      .hasValueSatifying(Conditions.notEqual("bar"));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for ✨ New Feature.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions