Java Code Examples for org.mockito.Mockito#validateMockitoUsage()

The following examples show how to use org.mockito.Mockito#validateMockitoUsage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      MockitoAnnotations.initMocks(target);
      try {
        base.evaluate();
      } finally {
        Mockito.validateMockitoUsage();
      }
    }
  };
}
 
Example 2
Source Project: AndroidUnitTest   File: AndroidUnitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            MockitoAnnotations.initMocks(target);
            androidUnitTestAnnotations.init(target);
            base.evaluate();
            Mockito.validateMockitoUsage();
        }
    };
}
 
Example 3
Source Project: DaggerMock   File: DaggerMockRule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            MockitoAnnotations.initMocks(target);

            setupComponent(target);

            base.evaluate();

            Mockito.validateMockitoUsage();
        }
    };
}
 
Example 4
public void applyFor(IInvokedMethod method, ITestResult testResult) {
    Mockito.validateMockitoUsage();

    if (method.isTestMethod()) {
        resetMocks(testResult.getInstance());
    }
}
 
Example 5
@Override
public void testFinished(Description description) throws Exception {
    super.testFinished(description);
    try {
        Mockito.validateMockitoUsage();
    } catch(Throwable t) {
        notifier.fireTestFailure(new Failure(description, t));
    }
}
 
Example 6
@Test
public void shouldDetectUnfinishedStubbing() {
    when(mock.simpleMethod());
    try {
        Mockito.validateMockitoUsage();
        fail();
    } catch (UnfinishedStubbingException e) {}
}
 
Example 7
@Test
public void shouldDetectMisplacedArgumentMatcher() {
    anyObject();
    try {
        Mockito.validateMockitoUsage();
        fail();
    } catch (InvalidUseOfMatchersException e) {}
}
 
Example 8
public void applyFor(IInvokedMethod method, ITestResult testResult) {
    Mockito.validateMockitoUsage();

    if (method.isTestMethod()) {
        resetMocks(testResult.getInstance());
    }
}
 
Example 9
@Override
public void testFinished(Description description) throws Exception {
    super.testFinished(description);
    try {
        Mockito.validateMockitoUsage();
    } catch(Throwable t) {
        notifier.fireTestFailure(new Failure(description, t));
    }
}
 
Example 10
@Test
public void shouldValidateExplicitly() {
    verify(mock);
    try {
        Mockito.validateMockitoUsage();
        fail();
    } catch (UnfinishedVerificationException e) {}
}
 
Example 11
@Test
public void shouldDetectUnfinishedStubbing() {
    when(mock.simpleMethod());
    try {
        Mockito.validateMockitoUsage();
        fail();
    } catch (UnfinishedStubbingException e) {}
}
 
Example 12
@Test
public void shouldDetectMisplacedArgumentMatcher() {
    anyObject();
    try {
        Mockito.validateMockitoUsage();
        fail();
    } catch (InvalidUseOfMatchersException e) {}
}
 
Example 13
@After
public void validateMocks() {
  Mockito.validateMockitoUsage();
}
 
Example 14
Source Project: dcos-commons   File: ServiceTest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void afterTest() {
    Mockito.validateMockitoUsage();
}
 
Example 15
@After
public void afterTest() {
  Mockito.validateMockitoUsage();
}
 
Example 16
@After
public void tearDown() {
  Mockito.validateMockitoUsage();
}
 
Example 17
@After
public void tearDown() {
  Mockito.validateMockitoUsage();
}
 
Example 18
@After
public void tearDown() {
  Mockito.validateMockitoUsage();
}
 
Example 19
@After
public void tearDown() {
  Mockito.validateMockitoUsage();
}
 
Example 20
Source Project: DaggerMock   File: DaggerMockRule.java    License: Apache License 2.0 3 votes vote down vote up
public void initMocks(Object target) {
    MockitoAnnotations.initMocks(target);

    setupComponent(target);

    Mockito.validateMockitoUsage();
}