Skip to content

Commit

Permalink
Merge pull request #897 from hazendaz/next
Browse files Browse the repository at this point in the history
[tests] Use path as temporary directory instead of file which we only…
  • Loading branch information
mathieucarbou authored Jan 27, 2025
2 parents fa66061 + 55b0af2 commit 3b73a27
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CopyrightRangeProviderTest {
private static Path fsRepoRoot;

@TempDir
static File tempFolder;
static Path tempFolder;

@Test
void copyrightRange() {
Expand Down Expand Up @@ -77,14 +77,13 @@ private void assertRange(CopyrightRangeProvider provider, String path, String in
}

private static Document newDocument(String relativePath) {
Path path = Path.of(fsRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar));
Path path = fsRepoRoot.resolve(relativePath.replace('/', File.separatorChar));
return new Document(path.toFile(), null, StandardCharsets.UTF_8, new String[0], null);
}

@BeforeAll
static void beforeClass() throws IOException {
fsRepoRoot = Path.of(tempFolder.toPath() + File.separator + "fs-test-repo");
fsRepoRoot = tempFolder.resolve("fs-test-repo");

Files.createDirectories(fsRepoRoot.resolve("dir1"));
Files.createFile(fsRepoRoot.resolve("dir1/file1.txt"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CopyrightAuthorProviderTest {
private static Path gitRepoRoot;

@TempDir
static File tempFolder;
static Path tempFolder;

@Test
void copyrightAuthor() {
Expand All @@ -61,17 +61,16 @@ void copyrightAuthor() {
}

private static Document newDocument(String relativePath) {
Path path = Path.of(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar));
Path path = gitRepoRoot.resolve(relativePath.replace('/', File.separatorChar));
return new Document(path.toFile(), null, StandardCharsets.UTF_8, new String[0], null);
}

@BeforeAll
static void beforeClass() throws IOException {
URL url = CopyrightAuthorProviderTest.class.getResource("git-test-repo.zip");
gitRepoRoot = Path.of(tempFolder.toPath() + File.separator + "git-test-repo");
gitRepoRoot = tempFolder.resolve("git-test-repo");

GitLookupTest.unzip(url, tempFolder.toPath());
GitLookupTest.unzip(url, tempFolder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CopyrightRangeProviderTest {
private static Path gitRepoRoot;

@TempDir
static File tempFolder;
static Path tempFolder;

@Test
void copyrightRange() {
Expand Down Expand Up @@ -83,17 +83,16 @@ private void assertRange(CopyrightRangeProvider provider, String path, String in
}

private static Document newDocument(String relativePath) {
Path path = Path.of(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar));
Path path = gitRepoRoot.resolve(relativePath.replace('/', File.separatorChar));
return new Document(path.toFile(), null, StandardCharsets.UTF_8, new String[0], null);
}

@BeforeAll
static void beforeClass() throws IOException {
URL url = CopyrightAuthorProviderTest.class.getResource("git-test-repo.zip");
gitRepoRoot = Path.of(tempFolder.toPath() + File.separator + "git-test-repo");
gitRepoRoot = tempFolder.resolve("git-test-repo");

GitLookupTest.unzip(url, tempFolder.toPath());
GitLookupTest.unzip(url, tempFolder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class GitLookupTest {
private static Path gitRepoRoot;

@TempDir
static File tempFolder;
static Path tempFolder;

@BeforeAll
static void beforeClass() throws IOException {
URL url = GitLookupTest.class.getResource("git-test-repo.zip");
gitRepoRoot = Path.of(tempFolder.toPath() + File.separator + "git-test-repo");
unzip(url, tempFolder.toPath());
gitRepoRoot = tempFolder.resolve("git-test-repo");
unzip(url, tempFolder);
}

static void unzip(URL url, Path unzipDestination) throws IOException {
Expand All @@ -58,7 +58,7 @@ static void unzip(URL url, Path unzipDestination) throws IOException {
while ((entry = zipInputStream.getNextEntry()) != null) {

String fileName = entry.getName();
Path unzippedFile = Path.of(unzipDestination.toAbsolutePath() + File.separator + fileName);
Path unzippedFile = unzipDestination.resolve(fileName);
if (entry.isDirectory()) {
unzippedFile.toFile().mkdirs();
} else {
Expand Down Expand Up @@ -251,15 +251,13 @@ private GitLookup newCommitterLookup(String... commitsToIgnore) throws IOExcepti

private void assertLastChange(GitLookup provider, String relativePath, int expected) throws
GitAPIException, IOException {
int actual = provider.getYearOfLastChange(Path.of(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar)).toFile());
int actual = provider.getYearOfLastChange(gitRepoRoot.resolve(relativePath.replace('/', File.separatorChar)).toFile());
Assertions.assertEquals(expected, actual);
}

private void assertCreation(GitLookup provider, String relativePath, int expected) throws
GitAPIException, IOException {
int actual = provider.getYearOfCreation(Path.of(gitRepoRoot + File.separator
+ relativePath.replace('/', File.separatorChar)).toFile());
int actual = provider.getYearOfCreation(gitRepoRoot.resolve(relativePath.replace('/', File.separatorChar)).toFile());
Assertions.assertEquals(expected, actual);
}

Expand Down

0 comments on commit 3b73a27

Please sign in to comment.