コード例 #1
0
  @Test
  public void shouldUpdateUserRoleWhenInvokeAuthoriseUser() {
    UserRole updatedUserRole = new UserRole();
    updatedUserRole.setUserId(1L);
    updatedUserRole.setRoleName("ROLE_ADMIN");

    when(userRoleMapper.get(userRole.getUserId())).thenReturn(userRole);

    userService.authoriseUser(userRole.getUserId());
    verify(userRoleMapper).get(userRole.getUserId());
    verify(userRoleMapper).update(argThat(new UserRoleMatcher(updatedUserRole)));
  }
コード例 #2
0
  @Test
  public void shouldReturnAllUsersWhithRoleWhenInvoked() {
    List<User> users = new ArrayList<User>();
    users.add(user);

    when(userMapper.findAllUsers()).thenReturn(users);
    when(userRoleMapper.get(user.getId())).thenReturn(userRole);

    Map<User, String> result = userService.getAllUsersWithRole();
    Map<User, String> expect = new HashMap<User, String>();
    expect.put(user, userRole.getRoleName());
    assertEquals(result, expect);
    verify(userMapper).findAllUsers();
    verify(userRoleMapper).get(user.getId());
  }