Skip to content

Commit

Permalink
SAK-32453 Switch to a loop to build the OR.
Browse files Browse the repository at this point in the history
This just drops out the older class.
  • Loading branch information
buckett authored and jonespm committed Apr 20, 2017
1 parent 08662b0 commit d65df55
Showing 1 changed file with 7 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import org.mockito.MockitoAnnotations;
import org.mockito.internal.hamcrest.HamcrestArgumentMatcher;

import org.mockito.internal.matchers.Any;
import org.mockito.internal.matchers.Not;
import org.mockito.internal.matchers.Or;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.tags.api.MissingUuidException;
import org.sakaiproject.tags.api.Tag;
Expand All @@ -41,19 +44,15 @@
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

import static org.hamcrest.Matchers.hasProperty;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.when;
import static org.mockito.internal.matchers.Null.NULL;

public abstract class BaseStorageTest {

Expand Down Expand Up @@ -262,43 +261,15 @@ protected <T> HamcrestArgumentMatcher<T> argHasProperty(String propertyName, Mat
}

protected <T> T argThatMatchesAnyOf(ArgumentMatcher<?>... matchers) {
final Or or = new Or(Lists.newArrayList(matchers));
ArgumentMatcher or = new Not(Any.ANY);
for (ArgumentMatcher<?> matcher : matchers) {
or = new Or(matcher, or);
}
return (T) argThat(or);
}

protected long now() {
return new Date().getTime();
}

//This was changed in https://github.com/mockito/mockito/pull/833, using old implementation
@SuppressWarnings("unchecked")
public class Or implements ArgumentMatcher, Serializable {

private final List<ArgumentMatcher> matchers;

public Or(List<ArgumentMatcher> matchers) {
this.matchers = matchers;
}

public boolean matches(Object actual) {
for (ArgumentMatcher matcher : matchers) {
if (matcher.matches(actual)) {
return true;
}
}
return false;
}

public String toString() {
//TODO SF here and in other places we should reuse ValuePrinter
StringBuilder sb = new StringBuilder("or(");
for (Iterator<ArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
sb.append(it.next().toString());
if (it.hasNext()) {
sb.append(", ");
}
}
return sb.append(")").toString();
}
}
}

0 comments on commit d65df55

Please sign in to comment.