### Question:
TerraformClean implements TerraformOperation<String> { @Override public String execute(Properties properties) throws TerraformException { boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); try { if (!this.tfRootModulePath.toFile().exists()) { throw new IOException(this.tfRootModulePath.toString() + " does not exist!"); } StringBuilder response = new StringBuilder("Deleting...\n"); if (this.tfModulesPath.toFile().exists()) { response.append(this.tfModulesPath.toString()).append('\n'); FileUtils.forceDelete(this.tfModulesPath.toFile()); } List<Path> terraformModuleFiles = recursivelyWalk(this.tfRootModulePath.getParent(), path -> path.getParent().toAbsolutePath().toString().endsWith(String.format(".terraform%1$smodules", File.separator)) || path.getFileName().toString().contains(".tfstate")); for (Path file : terraformModuleFiles) { if (isWindows && file.getParent().endsWith(String.format(".terraform%1$smodules", File.separator))) { try { response.append(file.toString()).append('\n'); file.toFile().delete(); } catch (Exception e) { response.append("**failed to delete ").append(file.toString()).append('\n'); } } if (file.toFile().exists()) { response.append(file.toString()).append('\n'); FileUtils.forceDelete(file.toFile()); } } Files.walk(this.tfRootModulePath.getParent()).filter(path -> path.toString().endsWith(".terraform")) .map(Path::toFile) .forEach(file -> { response.append(file.toString()).append('\n'); try { FileUtils.forceDelete(file); } catch (Exception ex) { response.append("**failed to delete ").append(file.toString()).append('\n'); } }); return response.toString(); } catch (IOException e) { throw new TerraformException(e); } } TerraformClean(String tfModules, String tfRootModule); @Override String execute(Properties properties);  }### Answer:
@Test public void terraformCleanCleansUpTerraformStateFilesAndTerraformWorkingDirectory() throws IOException, TerraformException { TerraformClean terraformClean = new TerraformClean( this.tfModulesWorkingDir.toString(), this.tfInitWorkingDir.resolve("root").toString()); terraformClean.execute(new Properties()); Assert.assertFalse(this.tfModulesWorkingDir.toFile().exists()); Assert.assertFalse(Files.walk(this.tfInitWorkingDir) .filter(path -> path.getFileName().toString().endsWith(".terraform") || path.getFileName().toString().endsWith(".tfstate")) .findAny().isPresent()); }
@Test(expected = TerraformException.class) public void terraformCleanThrowsTerraformExceptionOnInvalidPath() throws IOException, TerraformException { TerraformClean terraformClean = new TerraformClean( this.tfModulesWorkingDir.resolveSibling("invalid").toString(), "invalid"); terraformClean.execute(new Properties()); }