Skip to content

Commit eac96aa

Browse files
ScottBobJayBazuziisidore
committed
- F Added FileUtils.getResolvedPath
Co-authored-by: Jay Bazuzi <jay@bazuzi.com> Co-authored-by: Llewellyn Falco <llewellyn.falco@gmail.com>
1 parent 160a1d4 commit eac96aa

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

approvaltests-tests/src/test/java/org/approvaltests/ApprovedFileLogTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.junit.jupiter.api.Test;
88

99
import java.io.File;
10+
import java.io.IOException;
1011

1112
import static org.junit.jupiter.api.Assertions.assertEquals;
1213
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -32,4 +33,12 @@ void testTempDirectoryGetsGitIgnore()
3233
String result = FileUtils.readFile(LoggingUtils.getTempDirectory() + "/.gitignore");
3334
assertEquals("*\n", result);
3435
}
36+
@Test
37+
void testAbsoluteDirectory()
38+
{
39+
File file = new File("./temp.temp");
40+
String absolutePath = FileUtils.getResolvedPath(file);
41+
String currentDirectory = File.separator + "." + File.separator;
42+
assertFalse(absolutePath.contains(currentDirectory), absolutePath);
43+
}
3544
}

approvaltests-util/src/main/java/com/spun/util/io/FileUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,12 @@ public static Stream<Path> walkPath(String channelsPath, int maxDepth)
460460
throw ObjectUtils.throwAsError(e);
461461
}
462462
}
463+
464+
public static String getResolvedPath(File file) {
465+
try {
466+
return file.getCanonicalFile().getAbsolutePath();
467+
} catch (IOException e) {
468+
throw ObjectUtils.throwAsError(e);
469+
}
470+
}
463471
}

0 commit comments

Comments
 (0)