How to test file operations with Junit5 TempDir
In Junit4 we had TemporaryFolder. In Junit5 the way to test objects that are interacting with the file system it is pretty straightforward with the use of @TempDir. To make things easier to understand lets assume that we have a class that reads all the files, directories, sub directories and files in sub directories and gathers information about them in a form of a simple dto that contains the extension, if it is directory, the absolute path etc. and adds them in a list. So given a Path you get a list of objects that contain the file information. In order to test this functionality we are going to use the TempDir helper from Junit5. This will create a temporary directory in our filesystem that will be cleaned automatically when our testing is finished. Check out the example bellow Check on line 20 how we pass the temporary directory as a test parameter annotated accordingly. @TempDir will create a directory (depending on your OS) on a tmp folder like /tmp/junit6110933399026626368, but...