How to use VerificationStartedNotifier class of org.mockito.internal.listeners package

Best Mockito code snippet using org.mockito.internal.listeners.VerificationStartedNotifier

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/**
2 * Copyright (c) 2017 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.listeners;
6
7
8import VerificationStartedNotifier.Event;
9import java.util.Collections;
10import java.util.List;
11import java.util.Map;
12import java.util.Set;
13import org.junit.Assert;
14import org.junit.Test;
15import org.mockito.MockingDetails;
16import org.mockito.Mockito;
17import org.mockitoutil.TestBase;
18
19
20public class VerificationStartedNotifierTest extends TestBase {
21    MockingDetails mockingDetails = Mockito.mockingDetails(Mockito.mock(List.class));
22
23    @Test
24    public void does_not_do_anything_when_list_is_empty() throws Exception {
25        // expect nothing to happen
26        VerificationStartedNotifier.notifyVerificationStarted(((List) (Collections.emptyList())), mockingDetails);
27    }
28
29    @Test
30    public void decent_exception_when_setting_non_mock() throws Exception {
31        VerificationStartedNotifier.Event event = new VerificationStartedNotifier.Event(mockingDetails);
32        try {
33            // when
34            event.setMock("not a mock");
35            Assert.fail();
36        } catch (Exception e) {
37            // then
38            Assert.assertEquals(("VerificationStartedEvent.setMock() does not accept parameter which is not a Mockito mock.\n" + ("  Received parameter: \"not a mock\".\n" + "  See the Javadoc.")), e.getMessage());
39        }
40    }
41
42    @Test
43    public void shows_clean_exception_message_when_illegal_null_arg_is_used() throws Exception {
44        VerificationStartedNotifier.Event event = new VerificationStartedNotifier.Event(mockingDetails);
45        try {
46            // when
47            event.setMock(null);
48            Assert.fail();
49        } catch (Exception e) {
50            // then
51            Assert.assertEquals("VerificationStartedEvent.setMock() does not accept null parameter. See the Javadoc.", e.getMessage());
52        }
53    }
54
55    @Test
56    public void decent_exception_when_setting_mock_of_wrong_type() throws Exception {
57        final Set differentTypeMock = Mockito.mock(Set.class);
58        VerificationStartedNotifier.Event event = new VerificationStartedNotifier.Event(mockingDetails);
59        try {
60            // when
61            event.setMock(differentTypeMock);
62            Assert.fail();
63        } catch (Exception e) {
64            // then
65            Assert.assertEquals(TestBase.filterHashCode(("VerificationStartedEvent.setMock() does not accept parameter which is not the same type as the original mock.\n" + (("  Required type: java.util.List\n" + "  Received parameter: Mock for Set, hashCode: xxx.\n") + "  See the Javadoc."))), TestBase.filterHashCode(e.getMessage()));
66        }
67    }
68
69    @Test
70    public void decent_exception_when_setting_mock_that_does_not_implement_all_desired_interfaces() throws Exception {
71        final Set mock = Mockito.mock(Set.class, Mockito.withSettings().extraInterfaces(List.class));
72        final Set missingExtraInterface = Mockito.mock(Set.class);
73        VerificationStartedNotifier.Event event = new VerificationStartedNotifier.Event(Mockito.mockingDetails(mock));
74        try {
75            // when setting mock that does not have all necessary interfaces
76            event.setMock(missingExtraInterface);
77            Assert.fail();
78        } catch (Exception e) {
79            // then
80            Assert.assertEquals(TestBase.filterHashCode(("VerificationStartedEvent.setMock() does not accept parameter which does not implement all extra interfaces of the original mock.\n" + ((("  Required type: java.util.Set\n" + "  Required extra interface: java.util.List\n") + "  Received parameter: Mock for Set, hashCode: xxx.\n") + "  See the Javadoc."))), TestBase.filterHashCode(e.getMessage()));
81        }
82    }
83
84    @Test
85    public void accepts_replacement_mock_if_all_types_are_compatible() throws Exception {
86        final Set mock = Mockito.mock(Set.class, Mockito.withSettings().extraInterfaces(List.class, Map.class));
87        final Set compatibleMock = Mockito.mock(Set.class, Mockito.withSettings().extraInterfaces(List.class, Map.class));
88        VerificationStartedNotifier.Event event = new VerificationStartedNotifier.Event(Mockito.mockingDetails(mock));
89        // when
90        event.setMock(compatibleMock);
91        // then
92        Assert.assertEquals(compatibleMock, event.getMock());
93    }
94}
95
96
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 popular Stackoverflow questions on VerificationStartedNotifier

    No relevant questions found for this class 😞

Most used methods in VerificationStartedNotifier

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)