How to use method of org.easymock.tests2.UsageConstraintsTest class

Best Easymock code snippet using org.easymock.tests2.UsageConstraintsTest.

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.easymock.EasyMock.*;
8import static org.junit.Assert.*;
9
10import java.math.BigDecimal;
11import java.util.Comparator;
12
13import org.easymock.LogicalOperator;
14import org.easymock.internal.matchers.Equals;
15import org.easymock.tests.IMethods;
16import org.junit.Before;
17import org.junit.Test;
18
19public class UsageConstraintsTest {
20    private IMethods mock;
21
22    @Before
23    public void setUp() {
24        mock = createMock(IMethods.class);
25    }
26
27    @Test
28    public void equalsMissing() {
29        mock.simpleMethodWithArgument(not(eq("asd")));
30        try {
31            mock.simpleMethodWithArgument(not("jkl"));
32            fail();
33        } catch (IllegalStateException e) {
34            assertEquals("no matchers found.", e.getMessage());
35        }
36        try {
37            mock.simpleMethodWithArgument(or(eq("jkl"), "asd"));
38            fail();
39        } catch (IllegalStateException e) {
40            assertEquals("2 matchers expected, 1 recorded.", e.getMessage());
41        }
42        try {
43            mock.threeArgumentMethod(1, "asd", eq("asd"));
44            fail();
45        } catch (IllegalStateException e) {
46            assertEquals("3 matchers expected, 1 recorded.", e.getMessage());
47        }
48
49    }
50
51    @Test
52    public void differentConstraintsOnSameCall() {
53        mock.simpleMethodWithArgument((String) isNull());
54        mock.simpleMethodWithArgument((String) notNull());
55        replay(mock);
56        mock.simpleMethodWithArgument(null);
57        mock.simpleMethodWithArgument("2");
58    }
59
60    @Test
61    public void equals() {
62        assertEquals(new Equals(null), new Equals(null));
63        assertEquals(new Equals(new Integer(2)), new Equals(new Integer(2)));
64        assertFalse(new Equals(null).equals(null));
65        assertFalse(new Equals(null).equals("Test"));
66        try {
67            new Equals(null).hashCode();
68            fail();
69        } catch (UnsupportedOperationException expected) {
70        }
71    }
72
73    @Test
74    public void constraints() {
75        expect(mock.threeArgumentMethod(and(geq(7), leq(10)), isA(String.class), contains("123"))).andReturn("456")
76                .atLeastOnce();
77        replay(mock);
78        boolean failed = false;
79        try {
80            mock.threeArgumentMethod(11, "", "01234");
81        } catch (AssertionError expected) {
82            failed = true;
83        }
84        if (!failed) {
85            fail();
86        }
87        failed = false;
88        try {
89            mock.threeArgumentMethod(8, new Object(), "01234");
90        } catch (AssertionError expected) {
91            failed = true;
92        }
93        if (!failed) {
94            fail();
95        }
96        failed = false;
97        try {
98            mock.threeArgumentMethod(8, "", "no match");
99        } catch (AssertionError expected) {
100            failed = true;
101        }
102        if (!failed) {
103            fail();
104        }
105        assertEquals("456", mock.threeArgumentMethod(8, "", "01234"));
106        verify(mock);
107    }
108
109    @Test
110    public void andOverloaded() {
111        expect(mock.oneArg(and(eq(false), eq(false)))).andReturn("0");
112        expect(mock.oneArg(and(eq((byte) 1), eq((byte) 1)))).andReturn("1");
113        expect(mock.oneArg(and(eq('a'), eq('a')))).andReturn("2");
114        expect(mock.oneArg(and(eq((double) 1), eq((double) 1)))).andReturn("3");
115        expect(mock.oneArg(and(eq((float) 1), eq((float) 1)))).andReturn("4");
116        expect(mock.oneArg(and(eq((int) 1), eq((int) 1)))).andReturn("5");
117        expect(mock.oneArg(and(eq((long) 1), eq((long) 1)))).andReturn("6");
118        expect(mock.oneArg(and(eq((short) 1), eq((short) 1)))).andReturn("7");
119        expect(mock.oneArg(and(contains("a"), contains("d")))).andReturn("8");
120        expect(mock.oneArg(and(isA(Class.class), eq(Object.class)))).andReturn("9");
121        replay(mock);
122        assertEquals("9", mock.oneArg(Object.class));
123        assertEquals("0", mock.oneArg(false));
124        assertEquals("1", mock.oneArg((byte) 1));
125        assertEquals("2", mock.oneArg('a'));
126        assertEquals("3", mock.oneArg((double) 1));
127        assertEquals("7", mock.oneArg((short) 1));
128        assertEquals("8", mock.oneArg("abcde"));
129        assertEquals("4", mock.oneArg((float) 1));
130        assertEquals("5", mock.oneArg((int) 1));
131        assertEquals("6", mock.oneArg((long) 1));
132        verify(mock);
133    }
134
135    @Test
136    public void orOverloaded() {
137        expect(mock.oneArg(or(eq(false), eq(true)))).andReturn("0");
138        expect(mock.oneArg(or(eq((byte) 1), eq((byte) 2)))).andReturn("1");
139        expect(mock.oneArg(or(eq((char) 1), eq((char) 2)))).andReturn("2");
140        expect(mock.oneArg(or(eq((double) 1), eq((double) 2)))).andReturn("3");
141        expect(mock.oneArg(or(eq((float) 1), eq((float) 2)))).andReturn("4");
142        expect(mock.oneArg(or(eq((int) 1), eq((int) 2)))).andReturn("5");
143        expect(mock.oneArg(or(eq((long) 1), eq((long) 2)))).andReturn("6");
144        expect(mock.oneArg(or(eq((short) 1), eq((short) 2)))).andReturn("7");
145        expect(mock.oneArg(or(eq("asd"), eq("jkl")))).andReturn("8");
146        expect(mock.oneArg(or(eq(this.getClass()), eq(Object.class)))).andReturn("9");
147        replay(mock);
148        assertEquals("9", mock.oneArg(Object.class));
149        assertEquals("0", mock.oneArg(true));
150        assertEquals("1", mock.oneArg((byte) 2));
151        assertEquals("2", mock.oneArg((char) 1));
152        assertEquals("3", mock.oneArg((double) 2));
153        assertEquals("7", mock.oneArg((short) 1));
154        assertEquals("8", mock.oneArg("jkl"));
155        assertEquals("4", mock.oneArg((float) 1));
156        assertEquals("5", mock.oneArg((int) 2));
157        assertEquals("6", mock.oneArg((long) 1));
158        verify(mock);
159    }
160
161    @Test
162    public void notOverloaded() {
163        expect(mock.oneArg(not(eq(false)))).andReturn("0");
164        expect(mock.oneArg(not(eq((byte) 1)))).andReturn("1");
165        expect(mock.oneArg(not(eq('a')))).andReturn("2");
166        expect(mock.oneArg(not(eq((double) 1)))).andReturn("3");
167        expect(mock.oneArg(not(eq((float) 1)))).andReturn("4");
168        expect(mock.oneArg(not(eq((int) 1)))).andReturn("5");
169        expect(mock.oneArg(not(eq((long) 1)))).andReturn("6");
170        expect(mock.oneArg(not(eq((short) 1)))).andReturn("7");
171        expect(mock.oneArg(not(contains("a")))).andReturn("8");
172        expect(mock.oneArg(not(isA(Class.class)))).andReturn("9");
173        replay(mock);
174        assertEquals("9", mock.oneArg(new Object()));
175        assertEquals("0", mock.oneArg(true));
176        assertEquals("1", mock.oneArg((byte) 2));
177        assertEquals("2", mock.oneArg('b'));
178        assertEquals("3", mock.oneArg((double) 2));
179        assertEquals("7", mock.oneArg((short) 2));
180        assertEquals("8", mock.oneArg("bcde"));
181        assertEquals("4", mock.oneArg((float) 2));
182        assertEquals("5", mock.oneArg((int) 2));
183        assertEquals("6", mock.oneArg((long) 2));
184        verify(mock);
185    }
186
187    @Test
188    public void lessOrEqualOverloaded() {
189        expect(mock.oneArg(leq((byte) 1))).andReturn("1");
190        expect(mock.oneArg(leq((double) 1))).andReturn("3");
191        expect(mock.oneArg(leq((float) 1))).andReturn("4");
192        expect(mock.oneArg(leq((int) 1))).andReturn("5");
193        expect(mock.oneArg(leq((long) 1))).andReturn("6");
194        expect(mock.oneArg(leq((short) 1))).andReturn("7");
195        expect(mock.oneArg(leq(new BigDecimal("1")))).andReturn("8");
196        replay(mock);
197        assertEquals("1", mock.oneArg((byte) 1));
198        assertEquals("3", mock.oneArg((double) 1));
199        assertEquals("7", mock.oneArg((short) 0));
200        assertEquals("4", mock.oneArg((float) -5));
201        assertEquals("5", mock.oneArg((int) -2));
202        assertEquals("6", mock.oneArg((long) -3));
203        assertEquals("8", mock.oneArg(new BigDecimal("0.5")));
204        verify(mock);
205    }
206
207    @Test
208    public void lessThanOverloaded() {
209        expect(mock.oneArg(lt((byte) 1))).andReturn("1");
210        expect(mock.oneArg(lt((double) 1))).andReturn("3");
211        expect(mock.oneArg(lt((float) 1))).andReturn("4");
212        expect(mock.oneArg(lt((int) 1))).andReturn("5");
213        expect(mock.oneArg(lt((long) 1))).andReturn("6");
214        expect(mock.oneArg(lt((short) 1))).andReturn("7");
215        expect(mock.oneArg(lt(new BigDecimal("1")))).andReturn("8");
216        replay(mock);
217        assertEquals("1", mock.oneArg((byte) 0));
218        assertEquals("3", mock.oneArg((double) 0));
219        assertEquals("7", mock.oneArg((short) 0));
220        assertEquals("4", mock.oneArg((float) -4));
221        assertEquals("5", mock.oneArg((int) -34));
222        assertEquals("6", mock.oneArg((long) -6));
223        assertEquals("8", mock.oneArg(new BigDecimal("0.5")));
224        verify(mock);
225    }
226
227    @Test
228    public void greaterOrEqualOverloaded() {
229        expect(mock.oneArg(geq((byte) 1))).andReturn("1");
230        expect(mock.oneArg(geq((double) 1))).andReturn("3");
231        expect(mock.oneArg(geq((float) 1))).andReturn("4");
232        expect(mock.oneArg(geq((int) 1))).andReturn("5");
233        expect(mock.oneArg(geq((long) 1))).andReturn("6");
234        expect(mock.oneArg(geq((short) 1))).andReturn("7");
235        expect(mock.oneArg(geq(new BigDecimal("1")))).andReturn("8");
236        replay(mock);
237        assertEquals("1", mock.oneArg((byte) 2));
238        assertEquals("3", mock.oneArg((double) 1));
239        assertEquals("7", mock.oneArg((short) 2));
240        assertEquals("4", mock.oneArg((float) 3));
241        assertEquals("5", mock.oneArg((int) 4));
242        assertEquals("6", mock.oneArg((long) 5));
243        assertEquals("8", mock.oneArg(new BigDecimal("1.5")));
244        verify(mock);
245    }
246
247    @Test
248    public void greaterThanOverloaded() {
249        expect(mock.oneArg(gt((byte) 1))).andReturn("1");
250        expect(mock.oneArg(gt((double) 1))).andReturn("3");
251        expect(mock.oneArg(gt((float) 1))).andReturn("4");
252        expect(mock.oneArg(gt((int) 1))).andReturn("5");
253        expect(mock.oneArg(gt((long) 1))).andReturn("6");
254        expect(mock.oneArg(gt((short) 1))).andReturn("7");
255        expect(mock.oneArg(gt(new BigDecimal("1")))).andReturn("8");
256        replay(mock);
257        assertEquals("1", mock.oneArg((byte) 2));
258        assertEquals("3", mock.oneArg((double) 2));
259        assertEquals("7", mock.oneArg((short) 2));
260        assertEquals("4", mock.oneArg((float) 3));
261        assertEquals("5", mock.oneArg((int) 2));
262        assertEquals("6", mock.oneArg((long) 5));
263        assertEquals("8", mock.oneArg(new BigDecimal("1.5")));
264        verify(mock);
265    }
266
267    @Test
268    public void cmpTo() {
269        expect(mock.oneArg(cmpEq(new BigDecimal("1.5")))).andReturn("0");
270        replay(mock);
271        assertEquals("0", mock.oneArg(new BigDecimal("1.50")));
272        verify(mock);
273    }
274
275    public static class A {
276        private int value;
277
278        public A(int value) {
279            this.value = value;
280        }
281
282        public int getValue() {
283            return value;
284        }
285    }
286
287    @Test
288    public void compareWithComparator() {
289        Comparator<A> comparator = new Comparator<A>() {
290            public int compare(A a1, A a2) {
291                return a1.getValue() - a2.getValue();
292            }
293        };
294
295        // Check my comparator works
296        assertTrue(comparator.compare(new A(1), new A(2)) < 0);
297        assertTrue(comparator.compare(new A(2), new A(1)) > 0);
298        assertTrue(comparator.compare(new A(1), new A(1)) == 0);
299
300        // Now test EasyMock.cmp
301        checkOrder(mock, true);
302
303        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.EQUAL))).andReturn("0");
304
305        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.GREATER))).andReturn("1");
306
307        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.GREATER_OR_EQUAL))).andReturn("2");
308        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.GREATER_OR_EQUAL))).andReturn("2");
309
310        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.LESS_OR_EQUAL))).andReturn("3");
311        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.LESS_OR_EQUAL))).andReturn("3");
312
313        expect(mock.oneArg(cmp(new A(5), comparator, LogicalOperator.LESS_THAN))).andReturn("4");
314
315        replay(mock);
316
317        checkItFails(null); // null is not comparable so always return false
318        try {
319            mock.oneArg("");
320            fail();
321        } catch (AssertionError e) {
322        } // different type isn't either
323
324        checkItFails(new A(4));
325        checkItFails(new A(6));
326        assertEquals("0", mock.oneArg(new A(5)));
327
328        checkItFails(new A(4));
329        checkItFails(new A(5));
330        assertEquals("1", mock.oneArg(new A(6)));
331
332        checkItFails(new A(4));
333        assertEquals("2", mock.oneArg(new A(6)));
334        assertEquals("2", mock.oneArg(new A(5)));
335
336        checkItFails(new A(6));
337        assertEquals("3", mock.oneArg(new A(4)));
338        assertEquals("3", mock.oneArg(new A(5)));
339
340        checkItFails(new A(5));
341        checkItFails(new A(6));
342        assertEquals("4", mock.oneArg(new A(4)));
343
344        verify(mock);
345    }
346
347    private void checkItFails(A a) {
348        try {
349            mock.oneArg(a);
350            fail();
351        } catch (AssertionError e) {
352        }
353    }
354
355    @Test
356    public void any() {
357        expect(mock.oneArg(anyBoolean())).andReturn("0");
358        expect(mock.oneArg(anyByte())).andReturn("1");
359        expect(mock.oneArg(anyChar())).andReturn("2");
360        expect(mock.oneArg(anyDouble())).andReturn("3");
361        expect(mock.oneArg(anyFloat())).andReturn("4");
362        expect(mock.oneArg(anyInt())).andReturn("5");
363        expect(mock.oneArg(anyLong())).andReturn("6");
364        expect(mock.oneArg(anyShort())).andReturn("7");
365        expect(mock.oneArg((String) anyObject())).andReturn("8");
366        expect(mock.oneArg(anyObject())).andReturn("9");
367        replay(mock);
368        assertEquals("9", mock.oneArg(new Object()));
369        assertEquals("0", mock.oneArg(true));
370        assertEquals("1", mock.oneArg((byte) 1));
371        assertEquals("2", mock.oneArg((char) 1));
372        assertEquals("3", mock.oneArg((double) 1));
373        assertEquals("7", mock.oneArg((short) 1));
374        assertEquals("8", mock.oneArg("Test"));
375        assertEquals("4", mock.oneArg((float) 1));
376        assertEquals("5", mock.oneArg((int) 1));
377        assertEquals("6", mock.oneArg((long) 1));
378        verify(mock);
379    }
380
381    @Test
382    public void arrayEquals() {
383        expect(mock.oneArray(aryEq(new boolean[] { true }))).andReturn("0");
384        expect(mock.oneArray(aryEq(new byte[] { 1 }))).andReturn("1");
385        expect(mock.oneArray(aryEq(new char[] { 1 }))).andReturn("2");
386        expect(mock.oneArray(aryEq(new double[] { 1 }))).andReturn("3");
387        expect(mock.oneArray(aryEq(new float[] { 1 }))).andReturn("4");
388        expect(mock.oneArray(aryEq(new int[] { 1 }))).andReturn("5");
389        expect(mock.oneArray(aryEq(new long[] { 1 }))).andReturn("6");
390        expect(mock.oneArray(aryEq(new short[] { 1 }))).andReturn("7");
391        expect(mock.oneArray(aryEq(new String[] { "Test" }))).andReturn("8");
392        expect(mock.oneArray(aryEq(new Object[] { "Test" }))).andReturn("9");
393        replay(mock);
394        assertEquals("9", mock.oneArray(new Object[] { "Test" }));
395        assertEquals("0", mock.oneArray(new boolean[] { true }));
396        assertEquals("1", mock.oneArray(new byte[] { 1 }));
397        assertEquals("2", mock.oneArray(new char[] { 1 }));
398        assertEquals("3", mock.oneArray(new double[] { 1 }));
399        assertEquals("7", mock.oneArray(new short[] { 1 }));
400        assertEquals("8", mock.oneArray(new String[] { "Test" }));
401        assertEquals("4", mock.oneArray(new float[] { 1 }));
402        assertEquals("5", mock.oneArray(new int[] { 1 }));
403        assertEquals("6", mock.oneArray(new long[] { 1 }));
404        verify(mock);
405    }
406
407    @Test
408    public void greaterOrEqual() {
409        expect(mock.oneArg(geq(7))).andReturn("1").times(3);
410        expect(mock.oneArg(lt(7))).andStubReturn("2");
411
412        replay(mock);
413
414        assertEquals("1", mock.oneArg(7));
415        assertEquals("2", mock.oneArg(6));
416        assertEquals("1", mock.oneArg(8));
417        assertEquals("2", mock.oneArg(6));
418        assertEquals("1", mock.oneArg(9));
419
420        verify(mock);
421    }
422
423    @Test
424    public void greaterThan() {
425        expect(mock.oneArg(gt(7))).andReturn("1").times(3);
426        expect(mock.oneArg(leq(7))).andStubReturn("2");
427
428        replay(mock);
429
430        assertEquals("1", mock.oneArg(8));
431        assertEquals("2", mock.oneArg(7));
432        assertEquals("1", mock.oneArg(9));
433        assertEquals("2", mock.oneArg(6));
434        assertEquals("1", mock.oneArg(10));
435
436        verify(mock);
437    }
438
439    @Test
440    public void lessOrEqual() {
441        expect(mock.oneArg(leq(7))).andReturn("1").times(3);
442        expect(mock.oneArg(gt(7))).andStubReturn("2");
443
444        replay(mock);
445
446        assertEquals("1", mock.oneArg(7));
447        assertEquals("2", mock.oneArg(8));
448        assertEquals("1", mock.oneArg(6));
449        assertEquals("2", mock.oneArg(9));
450        assertEquals("1", mock.oneArg(5));
451
452        verify(mock);
453    }
454
455    @Test
456    public void lessThan() {
457        expect(mock.oneArg(lt(7))).andReturn("1").times(3);
458        expect(mock.oneArg(geq(7))).andStubReturn("2");
459
460        replay(mock);
461
462        assertEquals("1", mock.oneArg(5));
463        assertEquals("2", mock.oneArg(7));
464        assertEquals("1", mock.oneArg(6));
465        assertEquals("2", mock.oneArg(8));
466        assertEquals("1", mock.oneArg(4));
467
468        verify(mock);
469    }
470
471    @Test
472    public void testOr() {
473        expect(mock.oneArg(or(eq(7), eq(9)))).andReturn("1").atLeastOnce();
474        expect(mock.oneArg(anyInt())).andStubReturn("2");
475
476        replay(mock);
477
478        assertEquals("1", mock.oneArg(7));
479        assertEquals("1", mock.oneArg(9));
480        assertEquals("2", mock.oneArg(10));
481
482        verify(mock);
483    }
484
485    @Test
486    public void testNull() {
487        expect(mock.threeArgumentMethod(eq(1), isNull(), eq(""))).andReturn("1").atLeastOnce();
488        expect(mock.threeArgumentMethod(eq(1), not(isNull()), eq(""))).andStubReturn("2");
489
490        replay(mock);
491
492        assertEquals("1", mock.threeArgumentMethod(1, null, ""));
493        assertEquals("2", mock.threeArgumentMethod(1, new Object(), ""));
494
495        verify(mock);
496    }
497
498    @Test
499    public void testNotNull() {
500        expect(mock.threeArgumentMethod(eq(1), notNull(), eq(""))).andReturn("1").atLeastOnce();
501        expect(mock.threeArgumentMethod(eq(1), not(notNull()), eq(""))).andStubReturn("2");
502
503        replay(mock);
504
505        assertEquals("1", mock.threeArgumentMethod(1, new Object(), ""));
506        assertEquals("2", mock.threeArgumentMethod(1, null, ""));
507
508        verify(mock);
509    }
510
511    @Test
512    public void testFind() {
513        expect(mock.oneArg(find("[a-z]+\\d"))).andReturn("1").atLeastOnce();
514        expect(mock.oneArg(find("\\d\\d"))).andStubReturn("2");
515
516        replay(mock);
517
518        assertEquals("1", mock.oneArg("1ab12"));
519        assertEquals("2", mock.oneArg("312xx"));
520
521        verify(mock);
522    }
523
524    @Test
525    public void testMatches() {
526        expect(mock.oneArg(matches("[a-z]+\\d\\d"))).andReturn("1").atLeastOnce();
527        expect(mock.oneArg(matches("\\d\\d\\d"))).andStubReturn("2");
528
529        replay(mock);
530
531        assertEquals("1", mock.oneArg("a12"));
532        assertEquals("2", mock.oneArg("131"));
533
534        verify(mock);
535    }
536
537    @Test
538    public void testContains() {
539        expect(mock.oneArg(contains("ab"))).andReturn("1").atLeastOnce();
540        expect(mock.oneArg(contains("bc"))).andStubReturn("2");
541
542        replay(mock);
543
544        assertEquals("1", mock.oneArg("xabcx"));
545        assertEquals("2", mock.oneArg("xdbcx"));
546
547        verify(mock);
548    }
549
550    @Test
551    public void testStartsWith() {
552        expect(mock.oneArg(startsWith("ab"))).andReturn("1").atLeastOnce();
553        expect(mock.oneArg(startsWith("bc"))).andStubReturn("2");
554
555        replay(mock);
556
557        assertEquals("1", mock.oneArg("abcx"));
558        assertEquals("2", mock.oneArg("bcxe"));
559
560        verify(mock);
561    }
562
563    @Test
564    public void testEndsWith() {
565        expect(mock.oneArg(endsWith("ab"))).andReturn("1").atLeastOnce();
566        expect(mock.oneArg(endsWith("bc"))).andStubReturn("2");
567
568        replay(mock);
569
570        assertEquals("1", mock.oneArg("xab"));
571        assertEquals("2", mock.oneArg("xbc"));
572
573        verify(mock);
574    }
575
576    @Test
577    public void equalsWithDelta() {
578        expect(mock.oneArg(eq(1.0D, 0.1D))).andReturn("1").atLeastOnce();
579        expect(mock.oneArg(eq(2.0D, 0.1D))).andStubReturn("2");
580        expect(mock.oneArg(eq(1.0F, 0.1F))).andReturn("3").atLeastOnce();
581        expect(mock.oneArg(eq(2.0F, 0.1F))).andStubReturn("4");
582        expect(mock.oneArg(eq(2.0F, 0.1F))).andStubReturn("4");
583
584        replay(mock);
585
586        assertEquals("1", mock.oneArg(1.0));
587        assertEquals("1", mock.oneArg(0.91));
588        assertEquals("1", mock.oneArg(1.09));
589        assertEquals("2", mock.oneArg(2.0));
590
591        assertEquals("3", mock.oneArg(1.0F));
592        assertEquals("3", mock.oneArg(0.91F));
593        assertEquals("3", mock.oneArg(1.09F));
594        assertEquals("4", mock.oneArg(2.0F));
595
596        verify(mock);
597    }
598
599    @Test
600    public void testSame() {
601        Object one = new String("1243");
602        Object two = new String("1243");
603
604        assertNotSame(one, two);
605        assertEquals(one, two);
606
607        expect(mock.oneArg(same(one))).andReturn("1").atLeastOnce();
608        expect(mock.oneArg(same(two))).andStubReturn("2");
609
610        replay(mock);
611
612        assertEquals("1", mock.oneArg(one));
613        assertEquals("2", mock.oneArg(two));
614
615        verify(mock);
616    }
617}
618
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
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)