shadows/framework/src/main/java/org/robolectric/shadows/ShadowUserManager.java
public void switchUser(int userId) {
    if (!userInfoMap.containsKey(userId)) {
      throw new UnsupportedOperationException("Must add user before switching to it");
    }

    ShadowProcess.setUid(userPidMap.get(userId));
  }
public void switchUser(int userId) {
    if (!userInfoMap.containsKey(userId)) {
      throw new UnsupportedOperationException("Must add user before switching to it");
    }

    ShadowProcess.setUid(userPidMap.get(userId));
  }
Switches the current user to {@code userHandle}.

@param userId the integer handle of the user, where 0 is the primary user.