### Question:
EnvironmentCmdExecutor implements CmdExecutor { @Override public String executeCommand(final String command, final Map<String, String> environmentVariables, final File workDir, final String username) { return executor.executeCommand(command, withDefaults(environmentVariables), workDir, username); }  @Override String executeCommand(final String command,
                                 final Map<String, String> environmentVariables,
                                 final File workDir,
                                 final String username); @Override Process launchCommand(final String command,
                                 final Map<String, String> environmentVariables,
                                 final File workDir,
                                 final String username);  }### Answer:
@Test public void executorShouldDelegateCallToInnerExecutor() { final CmdExecutor envCmdExecutor = getEnvCmdExecutor(Collections.emptyMap()); envCmdExecutor.executeCommand(COMMAND); verify(innerExecutor).executeCommand(eq(COMMAND), eq(Collections.emptyMap()), eq(null), eq(null)); }
@Test public void executorShouldMergePredefinedAndGivenEnvironmentVariables() { final Map<String, String> predefinedEnvVars = new HashMap<>(); predefinedEnvVars.put("a", "a"); predefinedEnvVars.put("b", "b"); final Map<String, String> givenEnvVars = new HashMap<>(); givenEnvVars.put("c", "c"); givenEnvVars.put("d", "d"); final Map<String, String> mergedEnvVars = new HashMap<>(); mergedEnvVars.put("a", "a"); mergedEnvVars.put("b", "b"); mergedEnvVars.put("c", "c"); mergedEnvVars.put("d", "d"); final CmdExecutor envCmdExecutor = getEnvCmdExecutor(predefinedEnvVars); envCmdExecutor.executeCommand(COMMAND, givenEnvVars); verify(innerExecutor).executeCommand(eq(COMMAND), eq(mergedEnvVars), eq(null), eq(null)); }
@Test public void executorShouldOverridePredefinedEnvironmentVariableWithGivenEnvironmentVariableIfThereIsAnyOverlaps() { final Map<String, String> predefinedEnvVars = new HashMap<>(); predefinedEnvVars.put("a", "a"); predefinedEnvVars.put("b", "predefined"); final Map<String, String> givenEnvVars = new HashMap<>(); givenEnvVars.put("b", "given"); givenEnvVars.put("c", "c"); final CmdExecutor envCmdExecutor = getEnvCmdExecutor(predefinedEnvVars); envCmdExecutor.executeCommand(COMMAND, givenEnvVars); verify(innerExecutor).executeCommand(eq(COMMAND), argThat(map -> map.get("b").equals("given")), eq(null), eq(null)); }