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.junit.Test; 9import org.mockitoutil.TestBase; 10 11import java.math.BigDecimal; 12 13import static junit.framework.TestCase.assertEquals; 14import static junit.framework.TestCase.assertTrue; 15 16public class ComparableMatchersTest extends TestBase { 17 18 @Test 19 public void testLessThan() { 20 test(new LessThan<String>("b"), true, false, false, "lt"); 21 } 22 23 @Test 24 public void testGreaterThan() { 25 test(new GreaterThan<String>("b"), false, true, false, "gt"); 26 } 27 28 @Test 29 public void testLessOrEqual() { 30 test(new LessOrEqual<String>("b"), true, false, true, "leq"); 31 } 32 33 @Test 34 public void testGreaterOrEqual() { 35 test(new GreaterOrEqual<String>("b"), false, true, true, "geq"); 36 } 37 38 @Test 39 public void testCompareEqual() { 40 test(new CompareEqual<String>("b"), false, false, true, "cmpEq"); 41 42 // Make sure it works when equals provide a different result than compare 43 CompareEqual<BigDecimal> cmpEq = new CompareEqual<BigDecimal>(new BigDecimal("5.00")); 44 assertTrue(cmpEq.matches(new BigDecimal("5"))); 45 } 46 47 private void test(CompareTo<String> compareTo, boolean lower, boolean higher, 48 boolean equals, String name) { 49 50 assertEquals(lower, compareTo.matches("a")); 51 assertEquals(equals, compareTo.matches("b")); 52 assertEquals(higher, compareTo.matches("c")); 53 54 assertEquals(name + "(b)", compareTo.toString()); 55 } 56} 57