@Test
void getPermanentDirectoryWhenSetWithSystemProperty() throws Exception
{

    Logger logger = mock(Logger.class);
    ReflectionUtils.setFieldValue(this.environment, "logger", logger);
    File expectedPermanentDirectory = new File(System.getProperty("java.io.tmpdir"), "permanent");
    System.setProperty("xwiki.data.dir", expectedPermanentDirectory.toString());
    try {
        this.environment.setServletContext(mock(ServletContext.class));
        assertEquals(expectedPermanentDirectory.getCanonicalFile(),
            this.environment.getPermanentDirectory().getCanonicalFile());
    } finally {
        System.clearProperty("xwiki.data.dir");
    }
    verify(logger).info("Using permanent directory [{}]", expectedPermanentDirectory);
}