How to use method of org.easymock.tests.InvocationTest class

Best Easymock code snippet using org.easymock.tests.InvocationTest.

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.tests;
6
7import static org.junit.Assert.*;
8
9import java.lang.reflect.Method;
10
11import org.easymock.internal.EqualsMatcher;
12import org.easymock.internal.Invocation;
13import org.junit.Before;
14import org.junit.Test;
15
16public class InvocationTest {
17
18    private Invocation call;
19
20    private Invocation equalCall;
21
22    private Invocation nonEqualCall;
23
24    @Before
25    public void setup() throws SecurityException, NoSuchMethodException {
26        Object[] arguments1 = new Object[] { "" };
27        Object[] arguments2 = new Object[] { "" };
28        Object[] arguments3 = new Object[] { "X" };
29        Method m = Object.class.getMethod("equals", new Class[] { Object.class });
30        Object mock = new Object();
31        call = new Invocation(mock, m, arguments1);
32        equalCall = new Invocation(mock, m, arguments2);
33        nonEqualCall = new Invocation(mock, m, arguments3);
34    }
35
36    @Test
37    public void testEquals() {
38        assertFalse(call.equals(null));
39        assertFalse(call.equals(""));
40        assertTrue(call.equals(equalCall));
41        assertFalse(call.equals(nonEqualCall));
42    }
43
44    @Test
45    public void testHashCode() {
46        try {
47            call.hashCode();
48            fail();
49        } catch (UnsupportedOperationException expected) {
50            assertEquals("hashCode() is not implemented", expected.getMessage());
51        }
52    }
53
54    @Test
55    public void testShouldDisplayMocksToStringIfValidJavaIdentifier() throws SecurityException, NoSuchMethodException {
56        class ToString {
57            private final String name;
58
59            public ToString(String name) {
60                this.name = name;
61            }
62
63            @Override
64            public String toString() {
65                return name;
66            }
67
68            public void aMethod() {
69            }
70        }
71
72        Method method = ToString.class.getMethod("aMethod", new Class[0]);
73        Invocation invocation = new Invocation(new ToString("validJavaIdentifier"), method, null);
74
75        assertEquals(invocation.toString(new EqualsMatcher()), "validJavaIdentifier.aMethod()");
76
77        invocation = new Invocation(new ToString("no-valid-java-identifier"), method, null);
78
79        assertEquals(invocation.toString(new EqualsMatcher()), "aMethod()");
80
81    }
82}
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

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)