org.mockito.internal.matchers.CompareTo 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) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.matchers;
import java.io.Serializable;
import org.mockito.ArgumentMatcher;
public abstract class CompareTo>
implements ArgumentMatcher, Serializable {
private final T wanted;
public CompareTo(T value) {
this.wanted = value;
}
@Override
public final boolean matches(T actual) {
if (actual == null) {
return false;
}
if (!actual.getClass().isInstance(wanted)) {
return false;
}
int result = actual.compareTo(wanted);
return matchResult(result);
}
@Override
public final String toString() {
return getName() + "(" + wanted + ")";
}
protected abstract String getName();
protected abstract boolean matchResult(int result);
}