File tree Expand file tree Collapse file tree 2 files changed +19
-6
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 +19
-6
lines changed Original file line number Diff line number Diff line change @@ -28,13 +28,26 @@ public class TestUtils
2828{
2929 private static Random random ;
3030 private static Function2 <Class , String , File > getSourceDirectory = ClassUtils ::getSourceDirectory ;
31- public static AutoCloseable registerSourceDirectoryFinder (Function2 <Class , String , File > sourceDirectoryFinder )
31+ public static SourceDirectoryRestorer registerSourceDirectoryFinder (
32+ Function2 <Class , String , File > sourceDirectoryFinder )
3233 {
33- Function2 <Class , String , File > original = getSourceDirectory ;
34- AutoCloseable c = () -> TestUtils .getSourceDirectory = original ;
34+ SourceDirectoryRestorer c = new SourceDirectoryRestorer ();
3535 TestUtils .getSourceDirectory = sourceDirectoryFinder ;
3636 return c ;
3737 }
38+ public static class SourceDirectoryRestorer implements AutoCloseable
39+ {
40+ private final Function2 <Class , String , File > original ;
41+ public SourceDirectoryRestorer ()
42+ {
43+ this .original = TestUtils .getSourceDirectory ;
44+ }
45+ @ Override
46+ public void close ()
47+ {
48+ TestUtils .getSourceDirectory = original ;
49+ }
50+ }
3851 public static File getFile (String startingDir )
3952 {
4053 JFrame frame = new JFrame ();
Original file line number Diff line number Diff line change 22
33import java .io .File ;
44
5- import org .junit .Assert ;
65import org .junit .jupiter .api .Assertions ;
76import org .junit .jupiter .api .DisplayName ;
87import org .junit .jupiter .api .Nested ;
1514import com .spun .util .LambdaThreadLauncher ;
1615import com .spun .util .ObjectUtils ;
1716import com .spun .util .tests .TestUtils ;
17+ import com .spun .util .tests .TestUtils .SourceDirectoryRestorer ;
1818
1919public class JUnit5StackTraceNamerTest
2020{
@@ -69,9 +69,9 @@ void approvalFromInsideLambda() throws Exception
6969 { throw ObjectUtils .throwAsError (caught [0 ]); }
7070 }
7171 @ Test
72- void testOverridingDirectoryFinder () throws Exception
72+ void testOverridingDirectoryFinder ()
7373 {
74- try (AutoCloseable autoCloseable = TestUtils
74+ try (SourceDirectoryRestorer sdr = TestUtils
7575 .registerSourceDirectoryFinder ((c , s ) -> new File ("does not exist" )))
7676 {
7777 StackTraceNamer name = new StackTraceNamer ();
You can’t perform that action at this time.
0 commit comments