title: Resetting Mockito mocks, provided as Spring beans, between tests?
body: <p>I have a Java application that uses Spring's dependency injection.  I want to mock out a bean, and verify that it receives certain method calls.</p>
  
  <p>The problem is that Mockito does not reset the mock between tests, so I cannot correctly verify method calls on it.</p>
  
  <p>My unit under test:</p>
  
  <pre><code>public class MyClass {
    @Resource
    SomeClientClass client;
  
    public void myMethod() {
      client.someMethod();
    }
  }
  </code></pre>
  
  <p>The unit test class:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = UnitTestConfig.class)
  public class MyClassTest {
    @Resource
    SomeClientClass client;
  
    @Test
    public void verifySomething() {
      // ...
      Mockito.verify(client).publish();
    }
  }
  </code></pre>
  
  <p>Finally,</p>
  
  <pre><code>@Configuration
  public class UnitTestConfig {
    @Bean
    SomeClientClass client() {
      return Mockito.mock(SomeClientClass.class);
    }
  }
  </code></pre>
  
  <p>Though I could hack my way around this problem by manually resetting mocks between tests, I wonder if there's a cleaner / more idiomatic approach.</p>