• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.junit.Test;
9 import org.mockitoutil.TestBase;
10 
11 import java.math.BigDecimal;
12 
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue;
15 
16 public class ComparableMatchersTest extends TestBase {
17 
18     @Test
testLessThan()19     public void testLessThan() {
20         test(new LessThan<String>("b"), true, false, false, "lt");
21     }
22 
23     @Test
testGreaterThan()24     public void testGreaterThan() {
25         test(new GreaterThan<String>("b"), false, true, false, "gt");
26     }
27 
28     @Test
testLessOrEqual()29     public void testLessOrEqual() {
30         test(new LessOrEqual<String>("b"), true, false, true, "leq");
31     }
32 
33     @Test
testGreaterOrEqual()34     public void testGreaterOrEqual() {
35         test(new GreaterOrEqual<String>("b"), false, true, true, "geq");
36     }
37 
38     @Test
testCompareEqual()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 
test(CompareTo<String> compareTo, boolean lower, boolean higher, boolean equals, String name)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