22
33import com .spun .util .StringUtils ;
44import com .spun .util .io .FileUtils ;
5+ import org .apache .commons .lang3 .function .TriFunction ;
56import org .approvaltests .core .ApprovalFailureReporter ;
67import org .approvaltests .core .ApprovalReporterWithCleanUp ;
78import org .approvaltests .namer .StackTraceNamer ;
9+ import org .lambda .functions .Function3 ;
810
911import java .io .File ;
1012import java .util .regex .Matcher ;
1113import java .util .regex .Pattern ;
1214
1315public class InlineJavaReporter implements ApprovalFailureReporter , ApprovalReporterWithCleanUp
1416{
15- private final String sourceFilePath ;
16- private final StackTraceNamer stackTraceNamer ;
17- private final ApprovalFailureReporter reporter ;
18- private final String additionalLines ;
17+ private final String sourceFilePath ;
18+ private final StackTraceNamer stackTraceNamer ;
19+ public ApprovalFailureReporter reporter ;
20+ private final String additionalLines ;
21+ public Function3 <String , String , String , String > createNewReceivedFileText ;
1922 public InlineJavaReporter (ApprovalFailureReporter reporter , boolean addApprovalLine )
2023 {
2124 this .reporter = reporter ;
2225 this .stackTraceNamer = new StackTraceNamer ();
2326 this .sourceFilePath = stackTraceNamer .getSourceFilePath ();
24- this .additionalLines = addApprovalLine ? "***** DELETE ME TO APPROVE *****" : "" ;
27+ this .additionalLines = addApprovalLine ? "***** DELETE ME TO APPROVE *****\n " : "" ;
28+ this .createNewReceivedFileText = InlineJavaReporter ::createNewReceivedFileText ;
2529 }
2630 public String getSourceFilePath ()
2731 {
@@ -39,7 +43,7 @@ public String createReceived(String actual)
3943 String file = sourceFilePath + stackTraceNamer .getInfo ().getClassName () + ".java" ;
4044 String received = getReceivedFileName ();
4145 String text = FileUtils .readFile (file );
42- String fullText = createNewReceivedFileText (text , actual + additionalLines ,
46+ String fullText = this . createNewReceivedFileText . call (text , actual + additionalLines ,
4347 this .stackTraceNamer .getInfo ().getMethodName ());
4448 FileUtils .writeFile (new File (received ), fullText );
4549 return received ;
@@ -48,10 +52,10 @@ private String getReceivedFileName()
4852 {
4953 return sourceFilePath + stackTraceNamer .getInfo ().getClassName () + ".received.txt" ;
5054 }
51- public static String createNewReceivedFileText (String text , String actual , String methodName )
55+ public static String createNewReceivedFileText (String javaSourceCode , String actual , String methodName )
5256 {
53- text = text .replaceAll ("\r \n " , "\n " );
54- CodeParts codeParts = CodeParts .splitCode (text , methodName );
57+ javaSourceCode = javaSourceCode .replaceAll ("\r \n " , "\n " );
58+ CodeParts codeParts = CodeParts .splitCode (javaSourceCode , methodName );
5559 if (codeParts .method .contains ("expected = \" \" \" " ))
5660 {
5761 replaceExpected (codeParts , actual );
0 commit comments