@Test(dataProvider = "invalidAuthenticationTestData")
  public void login_withInvalidArguments_shouldThrowClientException(
      String login, String password, ExceptionBody expected) throws GeneralSecurityException {
    UserResource sut = createSystemUnderTest(null, null, null, null);

    try {
      sut.login(login, password);
    } catch (ClientException ex) {
      assertEquals(ex.getResponse().getEntity(), expected);
      return;
    }
    fail();
  }
  @Test
  public void login_ifPasswordIsNotCorrect_shouldThrowClientException()
      throws GeneralSecurityException {

    final String password = "******";
    final String login = "******";
    UserFactory userFactoryStub = mock(UserFactory.class);
    when(userFactoryStub.create(any(String.class), any(String.class))).thenReturn(new User(login));
    User user = userFactoryStub.create(login, password);
    user.setPasswordHash(password);
    UserRepository repositoryStub = mock(UserRepository.class);
    when(repositoryStub.getByLogin(login)).thenReturn(user);
    UserResource sut = createSystemUnderTest(repositoryStub, null, userFactoryStub, null);

    try {
      sut.login("foo", "bzr");
    } catch (ClientException e) {
      assertEquals(e.getResponse().getEntity(), new ExceptionBody("Password is not correct"));
      return;
    }
    fail();
  }
 public void login(String username, String password) {
   user.login(username, password);
 }