Search in sources :

Example 1 with Repository

use of org.icij.datashare.Repository in project datashare by ICIJ.

the class UsersInDbTest method find_user_in_db_with_password.

@Test
public void find_user_in_db_with_password() {
    Repository repository = mock(Repository.class);
    User expected = new User("foo", "bar", "mail", "icij", new HashMap<String, Object>() {

        {
            put("password", Hasher.SHA_256.hash("bar"));
        }
    });
    when(repository.getUser("foo")).thenReturn(expected);
    User actual = (User) new UsersInDb(repository).find("foo", "bar");
    assertThat(actual.id).isEqualTo(expected.id);
    assertThat(actual.name).isEqualTo(expected.name);
    assertThat(actual.email).isEqualTo(expected.email);
    assertThat(actual.details).isEqualTo(expected.details);
    assertThat(actual.provider).isEqualTo(expected.provider);
}
Also used : Repository(org.icij.datashare.Repository) User(org.icij.datashare.user.User) Test(org.junit.Test)

Example 2 with Repository

use of org.icij.datashare.Repository in project datashare by ICIJ.

the class UsersInDbTest method find_user_in_db_with_bad_password.

@Test
public void find_user_in_db_with_bad_password() {
    Repository repository = mock(Repository.class);
    User expected = new User("foo", "bar", "mail", "icij", new HashMap<String, Object>() {

        {
            put("password", "unused");
        }
    });
    when(repository.getUser("foo")).thenReturn(expected);
    assertThat(new UsersInDb(repository).find("foo", "bad")).isNull();
}
Also used : Repository(org.icij.datashare.Repository) User(org.icij.datashare.user.User) Test(org.junit.Test)

Example 3 with Repository

use of org.icij.datashare.Repository in project datashare by ICIJ.

the class UsersInDbTest method find_user_in_db.

@Test
public void find_user_in_db() {
    Repository repository = mock(Repository.class);
    User expected = new User("foo", "bar", "mail", "icij", new HashMap<String, Object>() {

        {
            put("field1", "val1");
        }
    });
    when(repository.getUser("foo")).thenReturn(expected);
    User actual = (User) new UsersInDb(repository).find("foo");
    assertThat(actual.id).isEqualTo(expected.id);
    assertThat(actual.name).isEqualTo(expected.name);
    assertThat(actual.email).isEqualTo(expected.email);
    assertThat(actual.details).isEqualTo(expected.details);
    assertThat(actual.provider).isEqualTo(expected.provider);
}
Also used : Repository(org.icij.datashare.Repository) User(org.icij.datashare.user.User) Test(org.junit.Test)

Aggregations

Repository (org.icij.datashare.Repository)3 User (org.icij.datashare.user.User)3 Test (org.junit.Test)3