title: How to verify method, which has transactional lines, in unit test for Spring Boot Service?
body: <p>i Have following UserServiceImpl Service Class:</p>
  <pre><code>@Service @Transactional
  public class UserServiceImpl implements UserDetailsService {
      ...
      public void addRoleToUser(String username, String name) {
          User user = this.userRepository.findByUsername(username);
          Role role = this.roleRepository.findByName(name);
          user.getRoles().add(role);
      }
      
  }
  </code></pre>
  <p>and it's corresponding test class:</p>
  <pre><code>public class UserServiceImplTest {
  
      @Mock private UserRepository userRepository;
      @Mock private RoleRepository roleRepository;
  
      private AutoCloseable autoCloseable;
  
      private UserServiceImpl userServiceImpl;
  
  
      @BeforeEach
      void setUp(){
          autoCloseable = MockitoAnnotations.openMocks(this);
          userServiceImpl = new UserServiceImpl(userRepository, roleRepository);
      }
  
      @AfterEach
      void tearDown() throws Exception{
          autoCloseable.close();
      }
  
      @Test
      void testAddRoleToUser() {
          ... // user and role def. here
          
          userServiceImpl.addRoleToUser(username, roleName);
          
          // what should be here?
      }
  }
  </code></pre>
  <p>But how can I verify that <code>user.getRoles().add(role);</code> is invoked in unit test? Is using mockito, and ArgumentCaptor enough?</p>
  <p>Thank you.</p>