public static List<String> getUnixGroups(String user) throws IOException {
    String effectiveGroupsResult;
    String allGroupsResult;
    List<String> groups = new ArrayList<>();
    try {
      effectiveGroupsResult = ShellUtils.execCommand(
          ShellUtils.getEffectiveGroupsForUserCommand(user));
      allGroupsResult = ShellUtils.execCommand(
          ShellUtils.getAllGroupsForUserCommand(user));
    } catch (ExitCodeException e) {
      // if we didn't get the group - just return empty list
      LOG.warn("got exception trying to get groups for user {}: {}", user, e.toString());
      return groups;
    }

    StringTokenizer tokenizer = new StringTokenizer(
        effectiveGroupsResult, ShellUtils.TOKEN_SEPARATOR_REGEX);
    while (tokenizer.hasMoreTokens()) {
      groups.add(tokenizer.nextToken());
    }
    tokenizer = new StringTokenizer(allGroupsResult, ShellUtils.TOKEN_SEPARATOR_REGEX);
    while (tokenizer.hasMoreTokens()) {
      groups.add(tokenizer.nextToken());
    }
    return groups;
  }
@Test
  public void userGroup() throws Throwable {
    String userName = "alluxio-user1";
    String userEffectiveGroup1 = "alluxio-user1-effective-group1";
    String userEffectiveGroup2 = "alluxio-user1-effective-group2";
    String userAllGroup1 = "alluxio-user1-all-group1";
    String userAllGroup2 = "alluxio-user1-all-group2";
    List<String> userEffectiveGroups = new ArrayList<>();
    List<String> userAllGroups = new ArrayList<>();
    userEffectiveGroups.add(userEffectiveGroup1);
    userEffectiveGroups.add(userEffectiveGroup2);
    userAllGroups.add(userAllGroup1);
    userAllGroups.add(userAllGroup2);

    setupShellMocks(userName, userEffectiveGroups, userAllGroups);

    List<String> groups = CommonUtils.getUnixGroups(userName);

    assertNotNull(groups);
    assertEquals(groups.size(), 4);
    assertEquals(groups.get(0), userEffectiveGroup1);
    assertEquals(groups.get(1), userEffectiveGroup2);
    assertEquals(groups.get(2), userAllGroup1);
    assertEquals(groups.get(3), userAllGroup2);
  }