### Question:
TerraformCommandLineDecorator implements Executable { @Override public String execute(String command, int timeout) throws IOException, InterruptedException { return commandLine.execute(getTerraformCommand(command), timeout); } TerraformCommandLineDecorator(TerraformCommand cmd, Executable commandLine, Logger logger);  TerraformCommandLineDecorator(TerraformCommand cmd, Executable commandLine);  TerraformCommandLineDecorator(TerraformCommand cmd, Logger logger);  TerraformCommandLineDecorator(TerraformCommand cmd);  TerraformCommandLineDecorator(TerraformCommand cmd, String tfRootDir); @Override String execute(String command, int timeout); @Override String execute(String command); @Override void setLogger(Logger logger); Executable getCommandLine();  }### Answer:
@Test public void executeDelegatesToExecutableWithTimeout() throws IOException, InterruptedException { String response = "Success!"; int timeout = 1000; String terraformCommand = "terraform init "; Executable executable = Mockito.mock(Executable.class); Mockito.when(executable.execute(terraformCommand, timeout)).thenReturn(response); TerraformCommandLineDecorator terraform = new TerraformCommandLineDecorator(TerraformCommand.INIT, executable); String output = terraform.execute("", timeout); Assert.assertEquals(response, output); Mockito.verify(executable, Mockito.times(1)).execute(terraformCommand, timeout); }
@Ignore("not yet ready , Please ignore.") @Test public void terraformCommandLineDecoratorDoesntBlowUpWithoutLogging() throws IOException, InterruptedException { Path tfPath = Paths.get(".tf"); File fetchFile = new File(String.format("..%stf-maven-plugin%ssrc%smain%sresources%stf",File.separator,File.separator,File.separator,File.separator,File.separator)); File tfDir = tfPath.toFile(); String[] tfwFileNames = {"tfw", "tfw.cmd", "tfw.ps1", "terraform-maven.properties"}; if (!tfDir.exists()) { try { tfDir.mkdir(); } catch (Exception e) { System.out.printf("Unable to create .tf directory\n"); } } for (String tfwFileName : tfwFileNames) { String tfwFile = (fetchFile.toPath().toFile() + File.separator + tfwFileName); String tfwFileDestName = (".tf" + File.separator + tfwFileName); File tfwFileSource = new File(tfwFile); File tfwFileDest = new File(tfwFileDestName); if (!tfwFileDest.exists()) { Files.copy(tfwFileSource.toPath(), tfwFileDest.toPath()); tfwFileDest.setExecutable(true,false); } } TerraformCommandLineDecorator terraformCommandLineDecorator = new TerraformCommandLineDecorator(TerraformCommand.VERSION); terraformCommandLineDecorator.execute("init"); String[]entries = tfDir.list(); for (String s: entries) { File currentFile = new File(tfDir.getPath(), s); currentFile.delete(); } tfDir.delete(); }
@Test public void executeDelegatesToExecutable() throws IOException, InterruptedException { String response = "Success!"; String terraformCommand = "terraform init "; Executable executable = Mockito.mock(Executable.class); Mockito.when(executable.execute(terraformCommand)).thenReturn(response); TerraformCommandLineDecorator terraform = new TerraformCommandLineDecorator(TerraformCommand.INIT, executable); String output = terraform.execute(""); Assert.assertEquals(response, output); Mockito.verify(executable, Mockito.times(1)).execute(terraformCommand); }