How to use method of org.easymock.samples.ConstructorCalledMockTest class

Best Easymock code snippet using org.easymock.samples.ConstructorCalledMockTest.

Run Easymock automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright 2003-2009 OFFIS, Henri Tremblay
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.samples;
17
18import java.math.*;
19
20import org.junit.*;
21import static org.junit.Assert.*;
22
23import org.easymock.*;
24import static org.easymock.EasyMock.*;
25
26/**
27 * Example of how to partial mock with actually calling a constructor.
28 */
29public final class ConstructorCalledMockTest extends EasyMockSupport
30{
31   TaxCalculator tc;
32
33   @Before
34   public void setUp()
35   {
36      BigDecimal[] taxValues = {new BigDecimal("5"), new BigDecimal("15")};
37
38      // No need to mock any methods, abstract ones are mocked by default:
39      tc = createMockBuilder(TaxCalculator.class).withConstructor((Object) taxValues).createMock();
40   }
41
42   @After
43   public void tearDown()
44   {
45      verifyAll();
46   }
47
48   @Test
49   public void testTax()
50   {
51      expect(tc.rate()).andStubReturn(new BigDecimal("0.20"));
52      replayAll();
53
54      BigDecimal tax = tc.tax();
55
56      assertEquals(new BigDecimal("4.00"), tax);
57   }
58
59   @Test
60   public void testTax_ZeroRate()
61   {
62      expect(tc.rate()).andStubReturn(BigDecimal.ZERO);
63      replayAll();
64
65      BigDecimal tax = tc.tax();
66
67      assertEquals(BigDecimal.ZERO, tax);
68   }
69}
70
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 ConstructorCalledMockTest

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)