private UserAuthenticationEntity initForModifyAuthentication() {
    UserEntity user1 = new UserEntity();
    user1.setUserId(-1);
    user1.setUserName("user1");
    UserAuthenticationEntity userEntity = new UserAuthenticationEntity();
    userEntity.setAuthenticationKey("hello");
    userEntity.setAuthenticationType(UserAuthenticationType.LOCAL);
    userEntity.setUser(user1);
    user1.setAuthenticationEntities(ImmutableList.of(userEntity));
    EntityManager manager = mock(EntityManager.class);
    expect(manager.merge(userEntity)).andReturn(userEntity).once();

    UserDAO dao = createMock(UserDAO.class);
    UserEntity admin = new UserEntity();
    admin.setUserId(-1);
    admin.setUserName("admin");
    PrincipalEntity principalEntity = new PrincipalEntity();
    admin.setPrincipal(principalEntity);
    PrivilegeEntity privilegeEntity = new PrivilegeEntity();
    principalEntity.setPrivileges(ImmutableSet.of(privilegeEntity));
    PermissionEntity permissionEntity = new PermissionEntity();
    privilegeEntity.setPermission(permissionEntity);
    permissionEntity.setPermissionName(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME);
    UserAuthenticationEntity adminAuthentication = new UserAuthenticationEntity();
    admin.setAuthenticationEntities(ImmutableList.of(adminAuthentication));
    adminAuthentication.setAuthenticationKey("admin1234");
    expect(dao.findByPK(anyInt())).andReturn(admin).anyTimes();

    createInjector(dao, manager);
    replayAll();
    return userEntity;
  }
User creation should throw {@link AmbariException} in case another user exists with the same name but
different user type.
ambari-server/src/test/java/org/apache/ambari/server/security/authorization/UsersTest.java