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.hamcrest.Description; 9 import org.mockito.ArgumentMatcher; 10 11 import java.io.Serializable; 12 13 14 public class Same extends ArgumentMatcher<Object> implements Serializable { 15 16 private static final long serialVersionUID = -1226959355938572597L; 17 private final Object wanted; 18 Same(Object wanted)19 public Same(Object wanted) { 20 this.wanted = wanted; 21 } 22 matches(Object actual)23 public boolean matches(Object actual) { 24 return wanted == actual; 25 } 26 describeTo(Description description)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 appendQuoting(Description description)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