Skip to content

Clean up AbstractDependencyMojoTestCase setUp #1490

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,62 @@ public abstract class AbstractDependencyMojoTestCase extends AbstractMojoTestCas

protected DependencyArtifactStubFactory stubFactory;

protected void setUp(String testDirectoryName, boolean createFiles) throws Exception {
setUp(testDirectoryName, createFiles, true);
}

protected void setUp(String testDirectoryName, boolean createFiles, boolean flattenedPath) throws Exception {
// required for mojo lookups to work
/**
* Initializes the test environment by creating a temporary directory and setting up the stub factory.
* Subclasses must call super.setUp() in their own setUp method to ensure proper initialization.
* To customize the test directory name, file creation, or path structure, override getTestDirectoryName(),
* shouldCreateFiles(), and shouldUseFlattenedPath() respectively.
*
* @throws Exception if setup fails
*/
protected void setUp() throws Exception {
// Required for mojo lookups to work
super.setUp();

testDir = Files.createTempDirectory(testDirectoryName).toFile();
testDir = Files.createTempDirectory(getTestDirectoryName()).toFile();
testDir.deleteOnExit();

stubFactory = new DependencyArtifactStubFactory(this.testDir, createFiles, flattenedPath);
stubFactory = new DependencyArtifactStubFactory(testDir, shouldCreateFiles(), shouldUseFlattenedPath());
}

/**
* Returns the name of the temporary test directory. Subclasses can override to customize.
*
* @return the test directory name
*/
protected String getTestDirectoryName() {
return "test-dir";
}

/**
* Determines whether files should be created by the stub factory. Subclasses can override to customize.
*
* @return true if files should be created, false otherwise
*/
protected boolean shouldCreateFiles() {
return true;
}

/**
* Determines whether the stub factory should use flattened paths. Subclasses can override to customize.
*
* @return true if flattened paths should be used, false otherwise
*/
protected boolean shouldUseFlattenedPath() {
return true;
}

/**
* Cleans up the test environment by deleting the temporary directory.
* Subclasses must call super.tearDown() in their own tearDown method to ensure proper cleanup.
*
* @throws Exception if cleanup fails
*/
@Override
protected void tearDown() throws Exception {
if (testDir != null) {
FileUtils.deleteDirectory(testDir);
assertFalse(testDir.exists());
assertFalse("Test directory should not exist after cleanup", testDir.exists());
}
super.tearDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@

public class TestCollectMojo extends AbstractDependencyMojoTestCase {

@Override
protected String getTestDirectoryName() {
return "markers";
}

@Override
protected boolean shouldCreateFiles() {
return false;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", false);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,20 @@
public class TestGetMojo extends AbstractDependencyMojoTestCase {
private GetMojo mojo;

@Override
protected String getTestDirectoryName() {
return "markers";
}

@Override
protected boolean shouldCreateFiles() {
return false;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", false);
super.setUp();
MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@
public class TestListClassesMojo extends AbstractDependencyMojoTestCase {
private ListClassesMojo mojo;

@Override
protected String getTestDirectoryName() {
return "markers";
}

@Override
protected boolean shouldCreateFiles() {
return false;
}

@Override
protected void setUp() throws Exception {
super.setUp("markers", false);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@
import org.apache.maven.project.MavenProject;

public class TestPropertiesMojo extends AbstractDependencyMojoTestCase {

@Override
protected String getTestDirectoryName() {
return "markers";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", true);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,24 @@ public class AnalyzeExclusionsMojoTest extends AbstractDependencyMojoTestCase {
private ResolverUtil resolverUtil;

@Override
public void setUp() throws Exception {
super.setUp("analyze-exclusions", true, false);
protected String getTestDirectoryName() {
return "analyze-exclusions";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected boolean shouldUseFlattenedPath() {
return false;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp();

project = new DependencyProjectStub();
project.setName("projectName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@

public class TestArtifactItem extends AbstractDependencyMojoTestCase {

@Override
protected String getTestDirectoryName() {
return "artifactItems";
}

@Override
protected boolean shouldCreateFiles() {
return false;
}

@Override
protected void setUp() throws Exception {
setUp("artifactItems", false);
// required for mojo lookups to work
super.setUp();
}

public void testArtifactItemConstructor() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,26 @@
public class TestCopyMojo extends AbstractDependencyMojoTestCase {
private CopyMojo mojo;

@Override
protected String getTestDirectoryName() {
return "copy";
}

@Override
protected boolean shouldCreateFiles() {
return false;
}

@Override
protected boolean shouldUseFlattenedPath() {
return false;
}

@Override
protected void setUp() throws Exception {
super.setUp("copy", false, false);
// required for mojo lookups to work
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,25 @@ public class TestIncludeExcludeUnpackMojo extends AbstractDependencyMojoTestCase

private UnpackMojo mojo;

@Override
protected String getTestDirectoryName() {
return "unpack";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected boolean shouldUseFlattenedPath() {
return false;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("unpack", true, false);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,25 @@ public class TestUnpackMojo extends AbstractDependencyMojoTestCase {

UnpackMojo mojo;

@Override
protected String getTestDirectoryName() {
return "unpack";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected boolean shouldUseFlattenedPath() {
return false;
}

@Override
protected void setUp() throws Exception {
super.setUp("unpack", true, false);
// required for mojo lookups to work
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ public class TestBuildClasspathMojo extends AbstractDependencyMojoTestCase {

private BuildClasspathMojo mojo;

@Override
protected String getTestDirectoryName() {
return "build-classpath";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("build-classpath", true);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,25 @@ public class TestCopyDependenciesMojo extends AbstractDependencyMojoTestCase {

CopyDependenciesMojo mojo;

@Override
protected String getTestDirectoryName() {
return "copy-dependencies";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected boolean shouldUseFlattenedPath() {
return false;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true, false);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ public class TestCopyDependenciesMojo2 extends AbstractDependencyMojoTestCase {

private CopyDependenciesMojo mojo;

@Override
protected String getTestDirectoryName() {
return "copy-dependencies";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true);
super.setUp();
MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ public class TestIncludeExcludeUnpackDependenciesMojo extends AbstractDependency

private UnpackDependenciesMojo mojo;

@Override
protected String getTestDirectoryName() {
return "unpack-dependencies";
}

@Override
protected boolean shouldCreateFiles() {
return true;
}

@Override
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("unpack-dependencies", true);
super.setUp();

MavenProject project = new DependencyProjectStub();
getContainer().addComponent(project, MavenProject.class.getName());
Expand Down
Loading