@Test
  public void testGetPersonalizedDetail() throws Exception {
    String userId = "1000";
    UserPreferences expectedDetail = actualUserPreferencesForUserId(userId);
    UserPreferences detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail));

    userId = "1010";
    detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    expectedDetail = actualUserPreferencesForUserId(userId);
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail));

    userId = "1020";
    detail = dao.getById(userId);
    assertThat(detail, nullValue());
    assertThat(detail, nullValue());

    userId = "2020";
    detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    expectedDetail = actualUserPreferencesForUserId(userId);
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail));
  }
  @Test
  public void testInsertPersonalizeDetail() throws Exception {
    String userId = "1020";

    // Verifying that the user does not exist
    assertThat(dao.getById(userId), nullValue());

    final UserPreferences expectedDetail_1020 =
        new UserPreferences(
            userId, "fr", "Test", "WA500", false, false, false, UserMenuDisplay.BOOKMARKS);

    Transaction.performInOne(() -> dao.save(expectedDetail_1020));

    UserPreferences detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1020));
    assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId)));

    userId = "1030";
    final UserPreferences expectedDetail_1030 =
        new UserPreferences(
            userId, "en", "Silverpeas", "WA26", true, false, false, UserMenuDisplay.DISABLE);

    Transaction.performInOne(() -> dao.save(expectedDetail_1030));

    detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1030));
    assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId)));

    userId = "1040";
    final UserPreferences expectedDetail_1040 =
        new UserPreferences(
            userId, "de", "Silverpeas_V", "WA38", false, true, false, UserMenuDisplay.ALL);

    Transaction.performInOne(() -> dao.save(expectedDetail_1040));

    detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1040));
    assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId)));

    userId = "1050";
    final UserPreferences expectedDetail_1050 =
        new UserPreferences(
            userId, "dl", "Silverpeas_V6", "WA38", false, false, true, UserMenuDisplay.DEFAULT);

    Transaction.performInOne(() -> dao.save(expectedDetail_1050));

    detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail_1050));
    assertThat(detail, PersonalizationMatcher.matches(actualUserPreferencesForUserId(userId)));
  }
  @Test
  public void testDeletePersonalizeDetail() throws Exception {
    String userId = "1000";
    final UserPreferences expectedDetail = actualUserPreferencesForUserId(userId);
    UserPreferences detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail));

    Transaction.performInOne(
        () -> {
          dao.delete(expectedDetail);
          return null;
        });

    assertThat(dao.getById(userId), nullValue());
    assertThat(actualUserPreferencesForUserId(userId), nullValue());
  }
  @Test
  public void testUpdatePersonalizeDetail() throws Exception {
    String userId = "1000";
    final UserPreferences expectedDetail = actualUserPreferencesForUserId(userId);
    UserPreferences detail = dao.getById(userId);
    assertThat(detail, notNullValue());
    assertThat(detail, PersonalizationMatcher.matches(expectedDetail));

    assertThat(expectedDetail.getLanguage(), is(not("DUMMY")));
    expectedDetail.setLanguage("DUMMY");

    Transaction.performInOne(() -> dao.save(expectedDetail));

    UserPreferences actual = actualUserPreferencesForUserId(userId);
    assertThat(actual, notNullValue());
    assertThat(actual, PersonalizationMatcher.matches(expectedDetail));
    assertThat(actual.getLanguage(), is("DUMMY"));
  }
 @Test
 public void testFindByDefaultSpace() throws Exception {
   String spaceId = "WA26";
   List<UserPreferences> userPreferencesList = dao.findByDefaultSpace(spaceId);
   assertThat(userPreferencesList, hasSize(2));
   assertThat(
       userPreferencesList.stream().map(UserPreferences::getId).collect(Collectors.toList()),
       containsInAnyOrder("1010", "2020"));
 }