org.mockito.internal.matchers.EqualsWithDelta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of securemock Show documentation
Show all versions of securemock Show documentation
Libraries for Elasticsearch
The newest version!
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.matchers;
import org.mockito.ArgumentMatcher;
import java.io.Serializable;
public class EqualsWithDelta implements ArgumentMatcher, Serializable {
private final Number wanted;
private final Number delta;
public EqualsWithDelta(Number value, Number delta) {
this.wanted = value;
this.delta = delta;
}
public boolean matches(Number actual) {
if (wanted == null ^ actual == null) {
return false;
}
if (wanted == actual) {
return true;
}
return wanted.doubleValue() - delta.doubleValue() <= actual.doubleValue()
&& actual.doubleValue() <= wanted.doubleValue()
+ delta.doubleValue();
}
public String toString() {
return "eq(" + wanted + ", " + delta + ")";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy