• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito.internal.matchers;
7 
8 import org.mockito.ArgumentMatcher;
9 
10 import java.io.Serializable;
11 
12 public class EqualsWithDelta implements ArgumentMatcher<Number>, Serializable {
13 
14     private final Number wanted;
15     private final Number delta;
16 
EqualsWithDelta(Number value, Number delta)17     public EqualsWithDelta(Number value, Number delta) {
18         this.wanted = value;
19         this.delta = delta;
20     }
21 
matches(Number actual)22     public boolean matches(Number actual) {
23         if (wanted == null ^ actual == null) {
24             return false;
25         }
26 
27         if (wanted == actual) {
28             return true;
29         }
30 
31         return wanted.doubleValue() - delta.doubleValue() <= actual.doubleValue()
32                 && actual.doubleValue() <= wanted.doubleValue()
33                         + delta.doubleValue();
34     }
35 
toString()36     public String toString() {
37         return "eq(" + wanted + ", " + delta + ")";
38     }
39 }
40