@Override
  public String getCommandName() {
    return COMMAND_NAME;
  }
@Test
  public void backupCmdExecuted()
          throws IOException, AlluxioException, NoSuchFieldException, IllegalAccessException {
    CollectEnvCommand cmd = new CollectEnvCommand(FileSystemContext.create());

    // Write to temp dir
    File targetDir = InfoCollectorTestUtils.createTemporaryDirectory();
    CommandLine mockCommandLine = mock(CommandLine.class);
    String[] mockArgs = new String[]{cmd.getCommandName(), targetDir.getAbsolutePath()};
    when(mockCommandLine.getArgs()).thenReturn(mockArgs);
    when(mockCommandLine.getOptionValue("output-dir", ""))
            .thenReturn(targetDir.getAbsolutePath());

    // Replace commands to execute
    Field f = cmd.getClass().getSuperclass().getDeclaredField("mCommands");
    f.setAccessible(true);
    ShellCommand mockCommandFail = mock(ShellCommand.class);
    when(mockCommandFail.runWithOutput()).thenReturn(
            new CommandReturn(255, "command failed"));
    Map<String, ShellCommand> mockCommandMap = new HashMap<>();
    mockCommandMap.put("mockCommand", mockCommandFail);
    f.set(cmd, mockCommandMap);

    // Replace better command to execute
    Field cb = cmd.getClass().getSuperclass().getDeclaredField("mCommandsAlt");
    cb.setAccessible(true);
    ShellCommand mockCommandBackup = mock(ShellCommand.class);
    when(mockCommandBackup.runWithOutput()).thenReturn(
            new CommandReturn(0, "backup command executed"));
    Map<String, ShellCommand> mockBetterMap = new HashMap<>();
    mockBetterMap.put("mockCommand", mockCommandBackup);
    cb.set(cmd, mockBetterMap);

    // The backup command worked so exit code is 0
    int ret = cmd.run(mockCommandLine);
    assertEquals(0, ret);

    // Verify the 1st option command failed, then backup executed
    verify(mockCommandFail).runWithOutput();
    verify(mockCommandBackup).runWithOutput();

    // Files will be copied to sub-dir of target dir
    File subDir = new File(Paths.get(targetDir.getAbsolutePath(), cmd.getCommandName()).toString());
    assertEquals(new String[]{"collectEnv.txt"}, subDir.list());

    // Verify only the better version command output is found
    String fileContent = new String(Files.readAllBytes(subDir.listFiles()[0].toPath()));
    assertTrue(fileContent.contains("backup command executed"));
  }