Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public String getDescription() {
return description;
}

/**
* @return A {@link DescribedPredicate} that will return {@code true} whenever this predicate would return {@code false}, and vice versa.
*/
@Override
@PublicAPI(usage = ACCESS)
public DescribedPredicate<T> negate() {
return new NotPredicate<>(this);
}

/**
* Overwrites the description of this {@link DescribedPredicate}. E.g.
*
Expand Down Expand Up @@ -176,7 +185,7 @@ public static <T> DescribedPredicate<T> doNot(DescribedPredicate<? super T> pred

/**
* @param predicate Any {@link DescribedPredicate}
* @return A predicate that will return {@code true} whenever the original predicate would return {@code false} and vice versa.
* @return A predicate that will return {@code true} whenever the original predicate would return {@code false}, and vice versa.
* @param <T> The type of object the {@link DescribedPredicate predicate} applies to
*/
@PublicAPI(usage = ACCESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,25 @@ public void describe_works() {
@DataProvider
public static Object[][] not_scenarios() {
return $$(
$(new NotScenario("not") {
$(new NotScenario("not", ".negate") {
@Override
<T> DescribedPredicate<T> apply(DescribedPredicate<T> input) {
return input.negate();
}
}),
$(new NotScenario("not", "not") {
@Override
<T> DescribedPredicate<T> apply(DescribedPredicate<T> input) {
return not(input);
}
}),
$(new NotScenario("do not") {
$(new NotScenario("do not", "doNot") {
@Override
<T> DescribedPredicate<T> apply(DescribedPredicate<T> input) {
return doNot(input);
}
}),
$(new NotScenario("does not") {
$(new NotScenario("does not", "doesNot") {
@Override
<T> DescribedPredicate<T> apply(DescribedPredicate<T> input) {
return doesNot(input);
Expand Down Expand Up @@ -279,16 +285,18 @@ private Function<Object, Integer> constant(int integer) {

private abstract static class NotScenario {
private final String expectedPrefix;
private final String methodName;

NotScenario(String expectedPrefix) {
NotScenario(String expectedPrefix, String methodName) {
this.expectedPrefix = expectedPrefix;
this.methodName = methodName;
}

abstract <T> DescribedPredicate<T> apply(DescribedPredicate<T> input);

@Override
public String toString() {
return expectedPrefix;
return expectedPrefix + " (via " + methodName + ")";
}
}

Expand Down