Skip to content

Commit 6fc5d17

Browse files
elharomichael-o
authored andcommitted
[MSITE-945] More modern temporary file handling (#203)
* More modern temporary file handling
1 parent eb0b0f6 commit 6fc5d17

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/test/java/org/apache/maven/plugins/site/deploy/AbstractSiteDeployWebDavTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
import org.apache.maven.settings.Settings;
4141
import org.codehaus.plexus.util.ReflectionUtils;
4242
import org.junit.Before;
43+
import org.junit.Rule;
4344
import org.junit.Test;
45+
import org.junit.rules.TemporaryFolder;
4446
import org.junit.runner.RunWith;
4547
import org.junit.runners.JUnit4;
4648

@@ -51,15 +53,19 @@
5153
@RunWith(JUnit4.class)
5254
public abstract class AbstractSiteDeployWebDavTest extends AbstractMojoTestCase {
5355

54-
File siteTargetPath = new File(getBasedir() + File.separator + "target" + File.separator + "siteTargetDeploy");
56+
// Can use @TempDir with JUnit 5
57+
@Rule
58+
public TemporaryFolder directory = new TemporaryFolder();
59+
60+
private File siteTargetPath;
5561

5662
@Override
5763
@Before
5864
public void setUp() throws Exception {
5965
super.setUp();
66+
siteTargetPath = new File(directory.newFolder(), "target");
6067
if (!siteTargetPath.exists()) {
6168
siteTargetPath.mkdirs();
62-
FileUtils.cleanDirectory(siteTargetPath);
6369
}
6470
}
6571

@@ -69,7 +75,6 @@ public void setUp() throws Exception {
6975

7076
@Test
7177
public void noAuthzDavDeploy() throws Exception {
72-
FileUtils.cleanDirectory(siteTargetPath);
7378
SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
7479

7580
try {
@@ -104,8 +109,6 @@ public void noAuthzDavDeploy() throws Exception {
104109

105110
@Test
106111
public void davDeployThruProxyWithoutAuthzInProxy() throws Exception {
107-
108-
FileUtils.cleanDirectory(siteTargetPath);
109112
SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler(siteTargetPath);
110113
try {
111114
File pluginXmlFile = getTestFile("src/test/resources/unit/deploy-dav/pom.xml");
@@ -151,10 +154,6 @@ public void davDeployThruProxyWithoutAuthzInProxy() throws Exception {
151154

152155
@Test
153156
public void davDeployThruProxyWitAuthzInProxy() throws Exception {
154-
155-
FileUtils.cleanDirectory(siteTargetPath);
156-
// SimpleDavServerHandler simpleDavServerHandler = new SimpleDavServerHandler( siteTargetPath );
157-
158157
Map<String, String> authentications = new HashMap<>();
159158
authentications.put("foo", "titi");
160159

@@ -226,8 +225,8 @@ private void assertContentInFiles() throws Exception {
226225

227226
File cssFile = new File(siteTargetPath, "site" + File.separator + "css" + File.separator + "maven-base.css");
228227
assertTrue(cssFile.exists());
229-
fileContent = FileUtils.readFileToString(cssFile, StandardCharsets.UTF_8);
230-
assertTrue(fileContent.contains("background-image: url(../images/collapsed.gif);"));
228+
String cssContent = FileUtils.readFileToString(cssFile, StandardCharsets.UTF_8);
229+
assertTrue(cssContent.contains("background-image: url(../images/collapsed.gif);"));
231230
}
232231

233232
/**

0 commit comments

Comments
 (0)