Package org.approvej.approve
Class InlineValueRewriter
java.lang.Object
org.approvej.approve.InlineValueRewriter
Rewrites
byValue() string arguments in test source files.
When the Configuration.defaultInlineValueReviewer() is
configured (e.g. as automatic), this class replaces the string argument of a
byValue() call with a text block containing the new received value. Only the argument itself is
replaced — the rest of the file is left untouched.
Supports Java (.java), Kotlin (.kt), Groovy (.groovy), and Scala
(.scala) source files.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidRewrites thebyValue()call in the given test method, replacing the string argument with a text block containing the new value.static StringrewriteContent(String content, String methodName, String newValue, Path sourcePath) Rewrites the content of a source file, replacing thebyValue()argument in the given method with a text block containing the new value.
-
Method Details
-
rewrite
Rewrites thebyValue()call in the given test method, replacing the string argument with a text block containing the new value.The method is located in the source file by its name, then the
byValue()call within that method is rewritten. This approach is robust even when earlier rewrites have shifted line numbers in the same file.- Parameters:
sourcePath- path to the source filemethodName- the name of the test method containing thebyValue()callnewValue- the new value to write as a text block argument
-
rewriteContent
public static String rewriteContent(String content, String methodName, String newValue, Path sourcePath) Rewrites the content of a source file, replacing thebyValue()argument in the given method with a text block containing the new value.- Parameters:
content- the source file contentmethodName- the test method namenewValue- the new valuesourcePath- the source file path (used to detect the language)- Returns:
- the rewritten content
-