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 12 public abstract class CompareTo<T extends Comparable<T>> extends ArgumentMatcher<T> { 13 private final Comparable<T> wanted; 14 15 public CompareTo(Comparable<T> value) { 16 this.wanted = value; 17 } 18 19 @SuppressWarnings("unchecked") 20 public boolean matches(Object actual) { 21 22 if(!(actual instanceof Comparable)) { 23 return false; 24 } 25 26 return matchResult(((Comparable) actual).compareTo(wanted)); 27 } 28 29 public void describeTo(Description description) { 30 description.appendText(getName() + "(" + wanted + ")"); 31 } 32 33 protected abstract String getName(); 34 35 protected abstract boolean matchResult(int result); 36 } 37