Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
18   94   9   2
0   54   0,5   9
9     1  
1    
 
  CompareToTest       Line # 29 18 0% 9 5 81,5% 0.8148148
 
  (12)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.easymock.tests2;
18   
19    import static org.junit.Assert.*;
20   
21    import java.math.BigDecimal;
22   
23    import org.easymock.internal.matchers.*;
24    import org.junit.Test;
25   
26    /**
27    * @author Henri Tremblay
28    */
 
29    public class CompareToTest {
30   
 
31  2 toggle @Test
32    public void testNotComparable() {
33  2 final CompareTo<Long> cmpTo = new CompareTo<Long>(5L) {
34   
35    private static final long serialVersionUID = 1L;
36   
 
37  0 toggle @Override
38    protected String getName() {
39  0 return null;
40    }
41   
 
42  0 toggle @Override
43    protected boolean matchResult(final int result) {
44  0 fail("Shouldn't be called since the passed argument is not Comparable");
45  0 return true;
46    }
47   
48    };
49   
50  2 assertFalse(cmpTo.matches(new Object()));
51    }
52   
 
53  2 toggle @Test
54    public void testLessThan() {
55  2 test(new LessThan<String>("b"), true, false, false, "lt");
56    }
57   
 
58  2 toggle @Test
59    public void testGreateThan() {
60  2 test(new GreaterThan<String>("b"), false, true, false, "gt");
61    }
62   
 
63  2 toggle @Test
64    public void testLessOrEqual() {
65  2 test(new LessOrEqual<String>("b"), true, false, true, "leq");
66    }
67   
 
68  2 toggle @Test
69    public void testGreateOrEqual() {
70  2 test(new GreaterOrEqual<String>("b"), false, true, true, "geq");
71    }
72   
 
73  2 toggle @Test
74    public void testCompareEqual() {
75  2 test(new CompareEqual<String>("b"), false, false, true, "cmpEq");
76   
77    // Make sure it works when equals provide a different result than
78    // compare
79  2 final CompareEqual<BigDecimal> cmpEq = new CompareEqual<BigDecimal>(new BigDecimal("5.00"));
80  2 assertTrue(cmpEq.matches(new BigDecimal("5")));
81    }
82   
 
83  10 toggle private void test(final CompareTo<String> cmpTo, final boolean lower, final boolean higher,
84    final boolean equals, final String name) {
85   
86  10 assertEquals(lower, cmpTo.matches("a"));
87  10 assertEquals(equals, cmpTo.matches("b"));
88  10 assertEquals(higher, cmpTo.matches("c"));
89   
90  10 final StringBuffer sb = new StringBuffer();
91  10 cmpTo.appendTo(sb);
92  10 assertEquals(name + "(b)", sb.toString());
93    }
94    }