org.mockito.internal.hamcrest.HamcrestArgumentMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-core Show documentation
Show all versions of mockito-core Show documentation
Mockito mock objects library core API and implementation
/*
* Copyright (c) 2016 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.hamcrest;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.mockito.ArgumentMatcher;
import static java.util.Objects.requireNonNull;
public class HamcrestArgumentMatcher implements ArgumentMatcher {
private final Matcher matcher;
private final Class type;
public HamcrestArgumentMatcher(Matcher matcher) {
this(Void.class, matcher);
}
public HamcrestArgumentMatcher(Matcher matcher, Class type) {
this(type, matcher);
}
private HamcrestArgumentMatcher(Class type, Matcher matcher) {
this.type = requireNonNull(type, "type");
this.matcher = requireNonNull(matcher, "matcher");
}
@Override
public boolean matches(Object argument) {
return this.matcher.matches(argument);
}
@Override
public String toString() {
// TODO SF add unit tests and integ test coverage for toString()
return StringDescription.toString(matcher);
}
@Override
public Class type() {
return type;
}
}