I have this function in a class called Test.java and it incudes;
public List<Path> getAllFoldersInTmp(String directory) throws IOException {
final List<Path> files = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Path.of(directory))) {
for (Path entry : stream) {
if (Files.isDirectory(entry)) {
files.add(entry);
}
}
}
return files;
}
so basically it returns all folders as a list in the "../../tmp" path. I want to write a test for it, and this is how i done but it does not work:
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
class Testing{
@Autowired
Test test;
@TempDir
Path directory;
@Test
public void givenDir_whenUsingDirectoryStream_thenListAllFiles() throws IOException {
File fileOne = directory.resolve("file1").toFile();
File fileTwo = directory.resolve("file2").toFile();
System.out.println(test.getAllFoldersInTmp("../../Temp")); //since the fileone and fileTwo are stored in `Temp/someRandomNumber` directory
}
}
I am getting the following error;
..\..\Temp
java.nio.file.NoSuchFileException: ..\..\Temp