Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MJAVADOC-762] don't share state between tests #218

Merged
merged 10 commits into from
Sep 25, 2023
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