private void initForCreateUser(@Nullable UserEntity existingUser) {
    UserDAO userDao = createStrictMock(UserDAO.class);
    expect(userDao.findUserByName(anyString())).andReturn(existingUser);
    userDao.create(anyObject(UserEntity.class));
    expectLastCall();
    EntityManager entityManager = createNiceMock(EntityManager.class);
    expect(entityManager.find(eq(PrincipalEntity.class), EasyMock.anyObject())).andReturn(null);
    replayAll();
    createInjector(userDao, entityManager);
  }
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