Skip to content

Commit 6fa9c86

Browse files
authored
[MJAVADOC-762] don't share state between tests (#218)
* don't share state between tests * use temporary directory per test
1 parent 05b12e8 commit 6fa9c86

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.nio.charset.StandardCharsets;
2727
import java.nio.file.Files;
2828
import java.nio.file.Path;
29+
import java.nio.file.Paths;
2930
import java.util.HashMap;
3031
import java.util.List;
3132
import java.util.Map;
@@ -78,27 +79,37 @@ public class JavadocReportTest extends AbstractMojoTestCase {
7879

7980
public static final String OPTIONS_UMLAUT_ENCODING = "Options Umlaut Encoding ö ä ü ß";
8081

81-
/** flag to copy repo only one time */
82-
private static boolean TEST_REPO_CREATED = false;
83-
8482
private Path unit;
8583

8684
private File localRepo;
8785

8886
private static final Logger LOGGER = LoggerFactory.getLogger(JavadocReportTest.class);
8987

90-
/** {@inheritDoc} */
9188
@Override
9289
protected void setUp() throws Exception {
9390
super.setUp();
9491

92+
Path tempDirectory = Files.createTempDirectory("JavadocReportTest");
93+
localRepo = tempDirectory.resolve(Paths.get("target/local-repo/")).toFile();
9594
unit = new File(getBasedir(), "src/test/resources/unit").toPath();
9695

97-
localRepo = new File(getBasedir(), "target/local-repo/");
98-
9996
createTestRepo();
10097
}
10198

99+
@Override
100+
protected void tearDown() throws Exception {
101+
try {
102+
deleteDirectory(localRepo);
103+
} catch (IOException ex) {
104+
// CI servers can have problems deleting files.
105+
// It will get cleared out eventually, and since
106+
// temporary directories have unique names,
107+
// it shouldn't affect subsequent tests.
108+
}
109+
110+
super.tearDown();
111+
}
112+
102113
private JavadocReport lookupMojo(Path testPom) throws Exception {
103114
JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom.toFile());
104115

@@ -122,11 +133,7 @@ private JavadocReport lookupMojo(Path testPom) throws Exception {
122133
* @throws IOException if any
123134
*/
124135
private void createTestRepo() throws IOException {
125-
if (TEST_REPO_CREATED) {
126-
return;
127-
}
128-
129-
localRepo.mkdirs();
136+
assertTrue(localRepo.mkdirs());
130137

131138
// ----------------------------------------------------------------------
132139
// UMLGraph
@@ -146,7 +153,7 @@ private void createTestRepo() throws IOException {
146153

147154
// ----------------------------------------------------------------------
148155
// commons-attributes-compiler
149-
// http://www.tullmann.org/pat/taglets/
156+
// https://www.tullmann.org/pat/taglets/
150157
// ----------------------------------------------------------------------
151158

152159
sourceDir = unit.resolve("taglet-test/artifact-taglet");
@@ -181,8 +188,6 @@ private void createTestRepo() throws IOException {
181188
file.delete();
182189
}
183190
}
184-
185-
TEST_REPO_CREATED = true;
186191
}
187192

188193
/**

0 commit comments

Comments
 (0)