File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
approvaltests-util/src/main/java/com/spun/util/tests
approvaltests/src/test/java/org/approvaltests/namer Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,12 @@ public class TestUtils
2828{
2929 private static Random random ;
3030 private static Function2 <Class , String , File > getSourceDirectory = ClassUtils ::getSourceDirectory ;
31- public static void registerSourceDirectoryFinder (Function2 <Class , String , File > getSourceDirectory )
31+ public static AutoCloseable registerSourceDirectoryFinder (Function2 <Class , String , File > sourceDirectoryFinder )
3232 {
33- TestUtils .getSourceDirectory = getSourceDirectory ;
33+ Function2 <Class , String , File > original = getSourceDirectory ;
34+ AutoCloseable c = () -> TestUtils .getSourceDirectory = original ;
35+ TestUtils .getSourceDirectory = sourceDirectoryFinder ;
36+ return c ;
3437 }
3538 public static File getFile (String startingDir )
3639 {
Original file line number Diff line number Diff line change 11package org .approvaltests .namer ;
22
3+ import java .io .File ;
4+
5+ import org .junit .Assert ;
6+ import org .junit .jupiter .api .Assertions ;
37import org .junit .jupiter .api .DisplayName ;
48import org .junit .jupiter .api .Nested ;
59import org .junit .jupiter .api .RepeatedTest ;
1014
1115import com .spun .util .LambdaThreadLauncher ;
1216import com .spun .util .ObjectUtils ;
17+ import com .spun .util .tests .TestUtils ;
1318
1419public class JUnit5StackTraceNamerTest
1520{
@@ -61,8 +66,18 @@ void approvalFromInsideLambda() throws Exception
6166 }));
6267 lambda .getThread ().join (1000 );
6368 if (caught [0 ] != null )
69+ { throw ObjectUtils .throwAsError (caught [0 ]); }
70+ }
71+ @ Test
72+ void testOverridingDirectoryFinder () throws Exception
73+ {
74+ try (AutoCloseable autoCloseable = TestUtils
75+ .registerSourceDirectoryFinder ((c , s ) -> new File ("does not exist" )))
6476 {
65- throw ObjectUtils .throwAsError (caught [0 ]);
77+ StackTraceNamer name = new StackTraceNamer ();
78+ File file = new File (name .getSourceFilePath () + this .getClass ().getSimpleName () + ".java" );
79+ Assertions .assertFalse (file .exists ());
6680 }
81+ StackTraceNamerUtils .assertSourceFilePath (this .getClass ().getSimpleName ());
6782 }
6883}
You can’t perform that action at this time.
0 commit comments