forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Equals.java
72 lines (57 loc) · 1.83 KB
/
Equals.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* 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;
import org.mockito.internal.matchers.text.ValuePrinter;
public class Equals implements ArgumentMatcher<Object>, ContainsExtraTypeInfo, Serializable {
private final Object wanted;
public Equals(Object wanted) {
this.wanted = wanted;
}
@Override
public boolean matches(Object actual) {
return Equality.areEqual(this.wanted, actual);
}
@Override
public String toString() {
return describe(wanted);
}
private String describe(Object object) {
return ValuePrinter.print(object);
}
protected final Object getWanted() {
return wanted;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Equals)) {
return false;
}
Equals other = (Equals) o;
return (this.wanted == null && other.wanted == null)
|| this.wanted != null && this.wanted.equals(other.wanted);
}
@Override
public int hashCode() {
return 1;
}
@Override
public String toStringWithType() {
return "(" + wanted.getClass().getSimpleName() + ") " + describe(wanted);
}
@Override
public String toStringWithFullName() {
return "(" + wanted.getClass().getCanonicalName() + ") " + describe(wanted);
}
@Override
public boolean typeMatches(Object target) {
return wanted != null && target != null && target.getClass() == wanted.getClass();
}
@Override
public boolean sameName(Object target) {
return wanted != null && target != null && target.getClass().getSimpleName().equals(wanted.getClass().getSimpleName());
}
}