Same.java revision e0ae5d7e87b1dd6e789803c1b9615a84bd7488b7
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.internal.matchers;
7
8import org.hamcrest.Description;
9import org.mockito.ArgumentMatcher;
10
11import java.io.Serializable;
12
13
14public class Same extends ArgumentMatcher<Object> implements Serializable {
15
16    private static final long serialVersionUID = -1226959355938572597L;
17    private final Object wanted;
18
19    public Same(Object wanted) {
20        this.wanted = wanted;
21    }
22
23    public boolean matches(Object actual) {
24        return wanted == actual;
25    }
26
27    public void describeTo(Description description) {
28        description.appendText("same(");
29        appendQuoting(description);
30        description.appendText("" + wanted);
31        appendQuoting(description);
32        description.appendText(")");
33    }
34
35    private void appendQuoting(Description description) {
36        if (wanted instanceof String) {
37            description.appendText("\"");
38        } else if (wanted instanceof Character) {
39            description.appendText("'");
40        }
41    }
42}
43