ReplaceText extends TransformationOperation<ReplaceText> { @Override @edu.umd.cs.findbugs.annotations.SuppressFBWarnings (value="NP_ALWAYS_NULL_EXCEPTION") protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileToBeChanged = getAbsoluteFile(transformedAppFolder, transformationContext); if (!fileToBeChanged.exists()) { FileNotFoundException ex = new FileNotFoundException(fileToBeChanged.getAbsolutePath() + " (No such file or directory)"); TransformationOperationException toex = new TransformationOperationException("Could not replace text", ex); return TOExecutionResult.error(this, toex); } BufferedReader reader = null; BufferedWriter writer = null; TOExecutionResult result = null; try { File readFile = getOrCreateReadFile(transformedAppFolder, transformationContext); reader = new BufferedReader(new InputStreamReader(new FileInputStream(readFile), StandardCharsets.UTF_8)); writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileToBeChanged), StandardCharsets.UTF_8)); result = replace(reader, writer); } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("Could not replace text", e)); } finally { try { if (writer != null) try { writer.close(); } catch (IOException e) { result.addWarning(e); } } finally { if(reader != null) try { reader.close(); } catch (IOException e) { result.addWarning(e); } } } return result; } ReplaceText();  ReplaceText(String regex);  ReplaceText(String regex, String replacement); ReplaceText setRegex(String regex); ReplaceText setReplacement(String replacement); ReplaceText setFirstOnly(boolean firstOnly); String getRegex(); String getReplacement(); boolean isFirstOnly(); @Override String getDescription();  }
@Test public void fileDoesNotExistTest() { ReplaceText replaceText = new ReplaceText("foo").relative("/src/main/resources/application_zeta.properties"); TOExecutionResult executionResult = replaceText.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR); assertEquals(executionResult.getException().getClass(), TransformationOperationException.class); assertEquals(executionResult.getException().getMessage(), "Could not replace text"); assertEquals(executionResult.getException().getCause().getClass(), FileNotFoundException.class); assertEquals(executionResult.getException().getCause().getMessage(), new File(transformedAppFolder, "/src/main/resources/application_zeta.properties").getAbsolutePath() + " (No such file or directory)"); }