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

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

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1
2package org.mockito.errorprone.bugpatterns;
3
4import com.google.errorprone.CompilationTestHelper;
5import org.junit.Before;
6import org.junit.Test;
7import org.junit.runner.RunWith;
8import org.junit.runners.JUnit4;
9
10/**
11 * Verify that there are no usages of Mockito internal implementations.
12 *
13 * @author tvanderlippe@google.com (Tim van der Lippe)
14 */
15@RunWith(JUnit4.class)
16public class MockitoInternalUsageTest {
17
18  private CompilationTestHelper compilationHelper;
19
20  @Before
21  public void setUp() {
22    compilationHelper = CompilationTestHelper.newInstance(MockitoInternalUsage.class, getClass());
23  }
24
25  @Test
26  public void testPositiveCases() {
27    compilationHelper
28        .addSourceLines(
29            "Test.java",
30            "import java.io.Serializable;",
31            "class MockitoInternalUsagePositiveCases {",
32            "  public void newObject() {",
33            "    // BUG: Diagnostic contains:",
34            "    new org.mockito.internal.MockitoCore();",
35            "    // BUG: Diagnostic contains:",
36            "    new InternalConsumer(new org.mockito.internal.MockitoCore());",
37            "  }",
38            "  public void staticMethodInvocation() {",
39            "    // BUG: Diagnostic contains:",
40            "    org.mockito.internal.configuration.GlobalConfiguration.validate();",
41            "  }",
42            "  public void variableTypeDeclaration() {",
43            "    // BUG: Diagnostic contains:",
44            "    org.mockito.internal.stubbing.InvocationContainerImpl container = null;",
45            "  }",
46            "  // BUG: Diagnostic contains:",
47            "  class ExtendsClause extends org.mockito.internal.MockitoCore {}",
48            "  // BUG: Diagnostic contains:",
49            "  abstract class ImplementsClause implements"
50                + " org.mockito.internal.junit.MockitoTestListener {}",
51            "  abstract class SecondImplementsClause",
52            "      // BUG: Diagnostic contains:",
53            "      implements Serializable, org.mockito.internal.junit.MockitoTestListener {}",
54            "  // BUG: Diagnostic contains:",
55            "  class ExtendsGeneric<T extends org.mockito.internal.stubbing.InvocationContainerImpl>"
56                + " {}",
57            "  // BUG: Diagnostic contains:",
58            "  class SecondExtendsGeneric<R, T extends"
59                + " org.mockito.internal.stubbing.InvocationContainerImpl> {}",
60            "  class FieldClause {",
61            "    // BUG: Diagnostic contains:",
62            "    org.mockito.internal.MockitoCore core;",
63            "  }",
64            "  class MethodArgumentClause {",
65            "    // BUG: Diagnostic contains:",
66            "    public void methodArgument(org.mockito.internal.MockitoCore core) {}",
67            "  }",
68            "  static class InternalConsumer {",
69            "    // BUG: Diagnostic contains:",
70            "    InternalConsumer(org.mockito.internal.MockitoCore core) {}",
71            "  }",
72            "}")
73        .doTest();
74  }
75
76  @Test
77  public void testPositiveImportsCases() {
78    compilationHelper
79        .addSourceLines(
80            "Test.java",
81            "package foo;",
82            "// BUG: Diagnostic contains:",
83            "import org.mockito.internal.MockitoCore;",
84            "// BUG: Diagnostic contains:",
85            "import org.mockito.internal.stubbing.InvocationContainerImpl;",
86            "// BUG: Diagnostic contains:",
87            "import org.mockito.internal.*;",
88            "class Test {}")
89        .doTest();
90  }
91
92  @Test
93  public void testNegativeCases() {
94    compilationHelper
95        .addSourceLines(
96            "Test.java",
97            "package org.mockito;",
98            "import org.mockito.internal.MockitoCore;",
99            "class Mockito {}")
100        .doTest();
101  }
102}
103
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)