How to use method of org.easymock.EasyMock class

Best Easymock code snippet using org.easymock.EasyMock.

Run Easymock automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 *    http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.apache.kafka.streams.state.internals.metrics;
18
19import org.apache.kafka.streams.processor.TaskId;
20import org.junit.Before;
21import org.junit.Test;
22
23import static org.easymock.EasyMock.expect;
24import static org.easymock.EasyMock.niceMock;
25import static org.easymock.EasyMock.replay;
26import static org.easymock.EasyMock.resetToDefault;
27import static org.easymock.EasyMock.verify;
28import static org.junit.Assert.assertThrows;
29
30public class RocksDBMetricsRecordingTriggerTest {
31
32    private final static String STORE_NAME1 = "store-name1";
33    private final static String STORE_NAME2 = "store-name2";
34    private final static TaskId TASK_ID1 = new TaskId(1, 2);
35    private final static TaskId TASK_ID2 = new TaskId(2, 4);
36    private final RocksDBMetricsRecorder recorder1 = niceMock(RocksDBMetricsRecorder.class);
37    private final RocksDBMetricsRecorder recorder2 = niceMock(RocksDBMetricsRecorder.class);
38
39    private final RocksDBMetricsRecordingTrigger recordingTrigger = new RocksDBMetricsRecordingTrigger();
40
41    @Before
42    public void setUp() {
43        expect(recorder1.storeName()).andStubReturn(STORE_NAME1);
44        expect(recorder1.taskId()).andStubReturn(TASK_ID1);
45        replay(recorder1);
46        expect(recorder2.storeName()).andStubReturn(STORE_NAME2);
47        expect(recorder2.taskId()).andStubReturn(TASK_ID2);
48        replay(recorder2);
49    }
50
51    @Test
52    public void shouldTriggerAddedMetricsRecorders() {
53        recordingTrigger.addMetricsRecorder(recorder1);
54        recordingTrigger.addMetricsRecorder(recorder2);
55
56        resetToDefault(recorder1);
57        recorder1.record();
58        replay(recorder1);
59        resetToDefault(recorder2);
60        recorder2.record();
61        replay(recorder2);
62
63        recordingTrigger.run();
64
65        verify(recorder1);
66        verify(recorder2);
67    }
68
69    @Test
70    public void shouldThrowIfRecorderToAddHasBeenAlreadyAdded() {
71        recordingTrigger.addMetricsRecorder(recorder1);
72
73        assertThrows(
74            IllegalStateException.class,
75            () -> recordingTrigger.addMetricsRecorder(recorder1)
76        );
77    }
78
79    @Test
80    public void shouldThrowIfRecorderToRemoveCouldNotBeFound() {
81        recordingTrigger.addMetricsRecorder(recorder1);
82        assertThrows(
83            IllegalStateException.class,
84            () -> recordingTrigger.removeMetricsRecorder(recorder2)
85        );
86    }
87}
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)