@Test
  public void shouldChangeUserPasswordWhenAsked() {
    User updatedUser = new User();
    updatedUser.setUserName(user.getUserName());
    updatedUser.setPasswordHash("newpass");
    when(userMapper.findByUsername(user.getUserName())).thenReturn(updatedUser);

    boolean ret = userService.password(user, "newpass");
    verify(userMapper).update(user);
    assertEquals(userService.getByUsername(user.getUserName()).getPasswordHash(), "newpass");
    assertEquals(ret, true);
  }
  @Before
  public void setup() {
    session = mock(SqlSession.class);
    userMapper = mock(UserMapper.class);
    userRoleMapper = mock(UserRoleMapper.class);

    sessionFactory = mock(SqlSessionFactory.class);

    when(sessionFactory.openSession()).thenReturn(session);
    when(session.getMapper(UserMapper.class)).thenReturn(userMapper);
    when(session.getMapper(UserRoleMapper.class)).thenReturn(userRoleMapper);

    userService = new UserServiceImpl(sessionFactory);

    user = new User();
    user.setUserName("user");
    user.setPasswordHash("password");
    user.setId(1L);

    userRole = new UserRole();
    userRole.setUserId(1L);
    userRole.setRoleName("ROLE_REGULAR");
  }