Testing with files and directories in JUnit with @Rule

Testing with Files and directories in JUnit is easy thanks to TemporaryFolder @Rule . In JUnit rules ( @Rule ) can be used as an alternative or an addition to fixture setup and cleanup methods ( org.junit.Before , org.junit.After , org.junit.BeforeClass , and org.junit.AfterClass ), but they are more powerful, and can be more easily shared between projects and classes.