temporaryFolder.newFolder(String... folderNames)
階層全体をパラメーターとして受け取ります。
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void test() throws Exception {
File child = temporaryFolder.newFolder("grandparent", "parent", "child"); //...
assertEquals("child", child.getName());
assertEquals("parent", child.getParentFile().getName());
assertEquals("grandparent", child.getParentFile().getParentFile().getName());
System.out.println(child.getAbsolutePath());
}
テストに合格し、次のように出力されます。
/var/folders/.../T/junit8666449860303204067/grandparent/parent/child