title: Testing a void service method with mocked repository in Spring Boot?
body: <p>My Spring Boot application provides the following service which increments a counter on the <code>User</code> entity and persists it to the database.</p>
  <pre class="lang-java prettyprint-override"><code>@Service
  public class MyService {
      
      @Autowired
      UserRepo userRepo;
      
      public void incrementLoginFailures(String email) throws UserNotFoundException {
          final User user = userRepo.findByEmail(email).orElseThrow(UserNotFoundException::new);
          user.incrementLoginFailures();
          userRepo.save(user);
      }
  }
  </code></pre>
  <p>Now I'd like to write a JUnit 5 test for this, preferrably mocking the respository but I guess I have some trouble understanding the concept of mocking here.</p>
  <p>As you can see, the service method <code>incrementLoginFailures()</code> does not return anything so I don't know how I could check that the login counter on the <code>User</code> entity was actually incremented. Do I need to write an integration test for this kind of check which actually spins up a database?</p>
  <pre class="lang-java prettyprint-override"><code>@ExtendWith(MockitoExtension.class)
  public class UserServiceTest {
  
    @InjectMocks
    private UserService userService;
  
    @Mock
    private UserRepo userRepo;
  
    @Test
    public void shouldIncrement() {
      userService.incrementLoginFailures(&quot;foo@bar.com&quot;);
      Assertions.assertEquals(1, xyz);  // from what source would xyz come from?
    }
  }
  </code></pre>