Skip to content

Commit

Permalink
Convert to JUnit 5 (#445)
Browse files Browse the repository at this point in the history
* Convert to JUnit 5

* Convert to JUnit 5

* Convert to JUnit 5

* Convert to JUnit 5

* Convert to JUnit 5

* Convert to JUnit 5

* rebase
  • Loading branch information
elharo authored Nov 7, 2024
1 parent c98c851 commit a1bb14f
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 111 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ under the License.
<artifactId>maven-reporting-impl</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.17.0</version>
<scope>test</scope>
</dependency>

<!-- plexus -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -49,15 +50,17 @@ protected void setUp(String testDirStr, boolean createFiles) throws Exception {
protected void setUp(String testDirStr, boolean createFiles, boolean flattenedPath) throws Exception {
// required for mojo lookups to work
super.setUp();

testDir = new File(
getBasedir(),
"target" + File.separatorChar + "unit-tests" + File.separatorChar + testDirStr + File.separatorChar);
FileUtils.deleteDirectory(testDir);
assertFalse(testDir.exists());
testDir = Files.createTempDirectory("testDirStr").toFile();
testDir.deleteOnExit();

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

@Override
protected void tearDown() {
if (testDir != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,37 @@
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.SilentLog;
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author brianf
*/
public class TestDestFileFilter extends TestCase {
public class TestDestFileFilter {
Set<Artifact> artifacts = new HashSet<>();

Log log = new SilentLog();

@TempDir
File outputFolder;

DependencyArtifactStubFactory fact;

@BeforeEach
protected void setUp() throws Exception {
super.setUp();

outputFolder = new File("target/markers/");
FileUtils.deleteDirectory(outputFolder);
assertFalse(outputFolder.exists());

this.fact = new DependencyArtifactStubFactory(outputFolder, false);
artifacts = fact.getReleaseAndSnapshotArtifacts();
}

protected void tearDown() throws IOException {
FileUtils.deleteDirectory(outputFolder);
}

public void createFile(Artifact artifact) throws IOException {
createFile(artifact, false, false, false);
}
Expand Down Expand Up @@ -91,6 +85,7 @@ public File createFile(
return destFile;
}

@Test
public void testDestFileRelease() throws IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);
Artifact artifact = fact.getReleaseArtifact();
Expand All @@ -103,6 +98,7 @@ public void testDestFileRelease() throws IOException, ArtifactFilterException {
assertTrue(filter.isArtifactIncluded(artifact));
}

@Test
public void testDestFileSnapshot() throws IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);
Artifact artifact = fact.getSnapshotArtifact();
Expand All @@ -115,6 +111,7 @@ public void testDestFileSnapshot() throws IOException, ArtifactFilterException {
assertTrue(filter.isArtifactIncluded(artifact));
}

@Test
public void testDestFileStripVersion() throws IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);
Artifact artifact = fact.getSnapshotArtifact();
Expand All @@ -128,6 +125,7 @@ public void testDestFileStripVersion() throws IOException, ArtifactFilterExcepti
assertTrue(filter.isArtifactIncluded(artifact));
}

@Test
public void testDestFileStripClassifier() throws IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);
Artifact artifact = fact.getSnapshotArtifact();
Expand All @@ -141,6 +139,7 @@ public void testDestFileStripClassifier() throws IOException, ArtifactFilterExce
assertTrue(filter.isArtifactIncluded(artifact));
}

@Test
public void testDestFileSubPerArtifact() throws IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);
Artifact artifact = fact.getSnapshotArtifact();
Expand All @@ -154,6 +153,7 @@ public void testDestFileSubPerArtifact() throws IOException, ArtifactFilterExcep
assertTrue(filter.isArtifactIncluded(artifact));
}

@Test
public void testDestFileSubPerType() throws MojoExecutionException, IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);
Artifact artifact = fact.getSnapshotArtifact();
Expand All @@ -167,6 +167,7 @@ public void testDestFileSubPerType() throws MojoExecutionException, IOException,
assertTrue(filter.isArtifactIncluded(artifact));
}

@Test
public void testDestFileOverwriteIfNewer() throws MojoExecutionException, IOException, ArtifactFilterException {
DestFileFilter filter = new DestFileFilter(outputFolder);

Expand All @@ -192,6 +193,7 @@ public void testDestFileOverwriteIfNewer() throws MojoExecutionException, IOExce
assertFalse(filter.isArtifactIncluded(artifact));
}

@Test
public void testGettersSetters() {
DestFileFilter filter = new DestFileFilter(null);
assertNull(filter.getOutputFileDirectory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,38 @@
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.SilentLog;
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author brianf
*/
public class TestMarkerFileFilter extends TestCase {
public class TestMarkerFileFilter {
Set<Artifact> artifacts = new HashSet<>();

Log log = new SilentLog();

@TempDir
File outputFolder;

DependencyArtifactStubFactory fact;

@BeforeEach
protected void setUp() throws Exception {
super.setUp();

outputFolder = new File("target/markers/");
FileUtils.deleteDirectory(outputFolder);
assertFalse(outputFolder.exists());

this.fact = new DependencyArtifactStubFactory(outputFolder, false);
artifacts = fact.getReleaseAndSnapshotArtifacts();
}

protected void tearDown() throws IOException {
FileUtils.deleteDirectory(outputFolder);
}

@Test
public void testMarkerFile() throws ArtifactFilterException {

MarkerFileFilter filter = new MarkerFileFilter(true, true, false, new DefaultFileMarkerHandler(outputFolder));
Set<Artifact> result = filter.filter(artifacts);
assertEquals(2, result.size());
Expand All @@ -73,7 +66,6 @@ public void testMarkerFile() throws ArtifactFilterException {
}

public void testMarkerSnapshots() throws ArtifactFilterException, MojoExecutionException, IOException {

DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(fact.getSnapshotArtifact(), outputFolder);
handler.setMarker();

Expand All @@ -85,8 +77,6 @@ public void testMarkerSnapshots() throws ArtifactFilterException, MojoExecutionE
result = filter.filter(artifacts);
assertEquals(2, result.size());
assertTrue(handler.clearMarker());
FileUtils.deleteDirectory(outputFolder);
assertFalse(outputFolder.exists());
}

public void testMarkerRelease() throws IOException, ArtifactFilterException, MojoExecutionException {
Expand All @@ -102,10 +92,9 @@ public void testMarkerRelease() throws IOException, ArtifactFilterException, Moj
assertEquals(2, result.size());

assertTrue(handler.clearMarker());
FileUtils.deleteDirectory(outputFolder);
assertFalse(outputFolder.exists());
}

@Test
public void testMarkerTimestamp() throws IOException, MojoExecutionException, ArtifactFilterException {
// filter includes release artifact because no marker present
// filter includes snapshot artifact because it is newer than marker
Expand Down Expand Up @@ -137,10 +126,9 @@ public void testMarkerTimestamp() throws IOException, MojoExecutionException, Ar
assertFalse(handler.isMarkerSet());
snap.getFile().delete();
release.getFile().delete();
FileUtils.deleteDirectory(outputFolder);
assertFalse(outputFolder.exists());
}

@Test
public void testGettersSetters() {
MarkerFileFilter filter = new MarkerFileFilter(true, false, true, new DefaultFileMarkerHandler(outputFolder));
assertTrue(filter.isOverWriteReleases());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,36 @@

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.testing.SilentLog;
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
import org.apache.maven.plugins.dependency.utils.markers.SourcesFileMarkerHandler;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author brianf
*/
public class TestResolveMarkerFileFilter extends TestCase {
Set<Artifact> artifacts = new HashSet<>();

Log log = new SilentLog();
public class TestResolveMarkerFileFilter {

@TempDir
File outputFolder;

DependencyArtifactStubFactory fact;

protected void setUp() throws Exception {
super.setUp();

outputFolder = new File("target/markers/");
FileUtils.deleteDirectory(outputFolder);
assertFalse(outputFolder.exists());

this.fact = new DependencyArtifactStubFactory(outputFolder, false);
artifacts = fact.getReleaseAndSnapshotArtifacts();
}

protected void tearDown() throws IOException {
FileUtils.deleteDirectory(outputFolder);
@BeforeEach
protected void setUp() throws IOException {
fact = new DependencyArtifactStubFactory(outputFolder, false);
fact.getReleaseAndSnapshotArtifacts();
}

@Test
public void testResolveFile() throws IOException, ArtifactFilterException, MojoExecutionException {
SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(outputFolder);

Expand Down
Loading

0 comments on commit a1bb14f

Please sign in to comment.