| career | drupal | java | mac | mysql | perl | scala | uml | unix  

EasyMock example source code file (

This example EasyMock source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - EasyMock tags/keywords

bigdecimal, bigdecimal, comparable, compareequal, compareequal, compareto, lessorequal, math, object, override, string, string, stringbuffer, test, test

The EasyMock source code

 * Copyright (c) 2001-2007 OFFIS, Tammo Freese.
 * This program is made available under the terms of the MIT License.
package org.easymock.tests2;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.easymock.internal.matchers.*;
import org.junit.Test;

public class CompareToTest {

    public void testNotComparable() {
        CompareTo<Long> cmpTo = new CompareTo(5L) {

            protected String getName() {
                return null;

            protected boolean matchResult(int result) {
                fail("Shouldn't be called since the passed argument is not Comparable");
                return true;
        assertFalse(cmpTo.matches(new Object()));
    public void testLessThan() {
        test(new LessThan<String>("b"), true, false, false, "lt");

    public void testGreateThan() {
        test(new GreaterThan<String>("b"), false, true, false, "gt");

    public void testLessOrEqual() {
        test(new LessOrEqual<String>("b"), true, false, true, "leq");

    public void testGreateOrEqual() {
        test(new GreaterOrEqual<String>("b"), false, true, true, "geq");

    public void testCompareEqual() {
        test(new CompareEqual<String>("b"), false, false, true, "cmpEq");

        // Make sure it works when equals provide a different result than
        // compare
        CompareEqual<BigDecimal> cmpEq = new CompareEqual(
                new BigDecimal("5.00"));
        assertTrue(cmpEq.matches(new BigDecimal("5")));

    private void test(CompareTo<String> cmpTo, boolean lower, boolean higher,
            boolean equals, String name) {

        assertEquals(lower, cmpTo.matches("a"));
        assertEquals(equals, cmpTo.matches("b"));
        assertEquals(higher, cmpTo.matches("c"));

        StringBuffer sb = new StringBuffer();
        assertEquals(name + "(b)", sb.toString());

Other EasyMock examples (source code examples)

Here is a short list of links related to this EasyMock source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.