How to use method of org.mockito.errorprone.bugpatterns.MockitoNotExtensibleTest class

Best Mockito code snippet using org.mockito.errorprone.bugpatterns.MockitoNotExtensibleTest.

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.errorprone.bugpatterns;
6
7import com.google.errorprone.CompilationTestHelper;
8import org.junit.Before;
9import org.junit.Test;
10import org.junit.runner.RunWith;
11import org.junit.runners.JUnit4;
12
13/** Verifies that there are no subclasses of {@link org.mockito.NotExtensible} Mockito types. */
14@RunWith(JUnit4.class)
15public class MockitoNotExtensibleTest {
16
17    private CompilationTestHelper compilationTestHelper;
18
19    @Before
20    public void setup() {
21        compilationTestHelper =
22            CompilationTestHelper.newInstance(MockitoNotExtensible.class, getClass());
23    }
24
25    @Test
26    public void notExtensibleSubclass_shouldWarn() {
27        compilationTestHelper
28            .addSourceLines(
29                "input.java",
30                "import org.mockito.invocation.InvocationOnMock;",
31                "// BUG: Diagnostic contains:",
32                "abstract class Invocation implements InvocationOnMock { }")
33            .doTest();
34    }
35
36    @Test
37    public void anonymousClassImplementingNotExtensible_shouldWarn() {
38        compilationTestHelper
39            .addSourceLines(
40                "input.java",
41                "import org.mockito.NotExtensible;",
42                "class Test {",
43                "  public void test() {",
44                "    // BUG: Diagnostic contains:",
45                "    new Anonymous() { };",
46                "  }",
47                "  @NotExtensible",
48                "  interface Anonymous {}",
49                "}")
50            .doTest();
51    }
52
53    @Test
54    public void anonymousClassImplementingOtherAnnotation_shouldNotWarn() {
55        compilationTestHelper
56            .addSourceLines(
57                "input.java",
58                "import org.mockito.NotExtensible;",
59                "class Test {",
60                "  public void test() {",
61                "    new Anonymous() { };",
62                "  }",
63                "  @OtherAnnotation",
64                "  interface Anonymous {}",
65                "  @interface OtherAnnotation {}",
66                "}")
67            .doTest();
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

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)