@Test public void testSave() { User user = new User(); user.setName("foo"); when(passwordEncoder.encode("password")).thenReturn("xxxx"); userService.save(user, "password"); ArgumentCaptor<User> userArg = ArgumentCaptor.forClass(User.class); verify(userRepository, times(1)).save(userArg.capture()); User actual = userArg.getValue(); assertThat(actual, is(user)); assertThat(user.getCreatedAt(), is(notNullValue())); assertThat(user.getUpdatedAt(), is(notNullValue())); assertThat(user.getPassword(), is("xxxx")); }
@Test public void shouldInsertUserWhenCreateNew() { userService.save(user); verify(userMapper).insert(user); }