Skip to content

Commit

Permalink
[MJAVADOC-762] don't share state between tests (#218)
Browse files Browse the repository at this point in the history
* don't share state between tests
* use temporary directory per test
  • Loading branch information
elharo committed Sep 25, 2023
1 parent 05b12e8 commit 6fa9c86
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -78,27 +79,37 @@ public class JavadocReportTest extends AbstractMojoTestCase {

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

/** flag to copy repo only one time */
private static boolean TEST_REPO_CREATED = false;

private Path unit;

private File localRepo;

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

/** {@inheritDoc} */
@Override
protected void setUp() throws Exception {
super.setUp();

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

localRepo = new File(getBasedir(), "target/local-repo/");

createTestRepo();
}

@Override
protected void tearDown() throws Exception {
try {
deleteDirectory(localRepo);
} catch (IOException ex) {
// CI servers can have problems deleting files.
// It will get cleared out eventually, and since
// temporary directories have unique names,
// it shouldn't affect subsequent tests.
}

super.tearDown();
}

private JavadocReport lookupMojo(Path testPom) throws Exception {
JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom.toFile());

Expand All @@ -122,11 +133,7 @@ private JavadocReport lookupMojo(Path testPom) throws Exception {
* @throws IOException if any
*/
private void createTestRepo() throws IOException {
if (TEST_REPO_CREATED) {
return;
}

localRepo.mkdirs();
assertTrue(localRepo.mkdirs());

// ----------------------------------------------------------------------
// UMLGraph
Expand All @@ -146,7 +153,7 @@ private void createTestRepo() throws IOException {

// ----------------------------------------------------------------------
// commons-attributes-compiler
// http://www.tullmann.org/pat/taglets/
// https://www.tullmann.org/pat/taglets/
// ----------------------------------------------------------------------

sourceDir = unit.resolve("taglet-test/artifact-taglet");
Expand Down Expand Up @@ -181,8 +188,6 @@ private void createTestRepo() throws IOException {
file.delete();
}
}

TEST_REPO_CREATED = true;
}

/**
Expand Down

0 comments on commit 6fa9c86

Please sign in to comment.