How to use method of org.easymock.internal.matchers.CompareEqual class

Best Easymock code snippet using org.easymock.internal.matchers.CompareEqual.

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/*
2 * Copyright (c) 2001-2007 OFFIS, Tammo Freese.
3 * This program is made available under the terms of the MIT License.
4 */
5package org.easymock.tests2;
6
7import static org.junit.Assert.*;
8
9import java.math.BigDecimal;
10
11import org.easymock.internal.matchers.CompareEqual;
12import org.easymock.internal.matchers.CompareTo;
13import org.easymock.internal.matchers.GreaterOrEqual;
14import org.easymock.internal.matchers.GreaterThan;
15import org.easymock.internal.matchers.LessOrEqual;
16import org.easymock.internal.matchers.LessThan;
17import org.junit.Test;
18
19public class CompareToTest {
20
21    @Test
22    public void testNotComparable() {
23        CompareTo<Long> cmpTo = new CompareTo<Long>(5L) {
24
25            @Override
26            protected String getName() {
27                return null;
28            }
29
30            @Override
31            protected boolean matchResult(int result) {
32                fail("Shouldn't be called since the passed argument is not Comparable");
33                return true;
34            }
35
36        };
37
38        assertFalse(cmpTo.matches(new Object()));
39    }
40
41    @Test
42    public void testLessThan() {
43        test(new LessThan<String>("b"), true, false, false, "lt");
44    }
45
46    @Test
47    public void testGreateThan() {
48        test(new GreaterThan<String>("b"), false, true, false, "gt");
49    }
50
51    @Test
52    public void testLessOrEqual() {
53        test(new LessOrEqual<String>("b"), true, false, true, "leq");
54    }
55
56    @Test
57    public void testGreateOrEqual() {
58        test(new GreaterOrEqual<String>("b"), false, true, true, "geq");
59    }
60
61    @Test
62    public void testCompareEqual() {
63        test(new CompareEqual<String>("b"), false, false, true, "cmpEq");
64
65        // Make sure it works when equals provide a different result than
66        // compare
67        CompareEqual<BigDecimal> cmpEq = new CompareEqual<BigDecimal>(new BigDecimal("5.00"));
68        assertTrue(cmpEq.matches(new BigDecimal("5")));
69    }
70
71    private void test(CompareTo<String> cmpTo, boolean lower, boolean higher, boolean equals, String name) {
72
73        assertEquals(lower, cmpTo.matches("a"));
74        assertEquals(equals, cmpTo.matches("b"));
75        assertEquals(higher, cmpTo.matches("c"));
76
77        StringBuffer sb = new StringBuffer();
78        cmpTo.appendTo(sb);
79        assertEquals(name + "(b)", sb.toString());
80    }
81}
82
Full Screen
copy
1/*
2 * Copyright 2001-2009 OFFIS, Tammo Freese
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 */
16package org.easymock.internal.matchers;
17
18public class CompareEqual<T extends Comparable<T>> extends CompareTo<T> {
19
20    private static final long serialVersionUID = 7616033998227799268L;
21
22    public CompareEqual(Comparable<T> value) {
23        super(value);
24    }
25
26    @Override
27    protected String getName() {
28        return "cmpEq";
29    }
30
31    @Override
32    protected boolean matchResult(int result) {
33        return result == 0;
34    }
35}
36
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in CompareEqual

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)