コード例 #1
0
 @Before
 public void setUp() {
   userService = new UserServiceImpl();
   userRepository = mock(UserRepository.class);
   userService.userRepository = userRepository;
   passwordEncoder = mock(PasswordEncoder.class);
   userService.passwordEncoder = passwordEncoder;
 }
コード例 #2
0
  @Test
  public void testFindOne() {
    User user = new User();
    when(userRepository.findOne(100)).thenReturn(user);

    User result = userService.findOne(100);

    assertThat(result, is(user));
  }
コード例 #3
0
  @Test
  public void testDelete() {
    User user = new User();

    userService.delete(user);

    ArgumentCaptor<User> userArg = ArgumentCaptor.forClass(User.class);
    verify(userRepository, times(1)).delete(userArg.capture());
    assertThat(userArg.getValue(), is(user));
  }
コード例 #4
0
  @Test
  public void testFindByNameLike() {
    Pageable pageable = new PageRequest(1, 10);
    Page<User> page = new PageImpl<User>(Arrays.asList(new User()));
    when(userRepository.findByNameLike("foo", pageable)).thenReturn(page);

    Page<User> result = userService.findByNameLike("foo", pageable);

    assertThat(result, is(page));
  }
コード例 #5
0
  @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"));
  }