Skip to content
Draft
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
17 changes: 1 addition & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<!-- exclude old version with different artifactId -->
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand All @@ -227,7 +212,7 @@ under the License.
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.6.1</version>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@
import org.codehaus.plexus.archiver.zip.ZipArchiver;
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
Expand All @@ -66,10 +68,11 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@MockitoSettings(strictness = Strictness.WARN)
@ExtendWith(MockitoExtension.class)
public class DefaultAssemblyArchiverTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@TempDir
public File temporaryFolder;

private ArchiverManager archiverManager;

Expand All @@ -90,17 +93,19 @@ public static void setupInterpolators(AssemblerConfigurationSource configSource,
.thenReturn(AbstractAssemblyMojo.mainProjectInterpolator(mavenProject));
}

@Before
@BeforeEach
public void setup() throws PlexusContainerException {
this.archiverManager = mock(ArchiverManager.class);
this.container = new DefaultPlexusContainer();
this.configurator = new BasicComponentConfigurator();
}

@Test(expected = InvalidAssemblerConfigurationException.class)
@Test
public void failWhenAssemblyIdIsNull() throws Exception {
final DefaultAssemblyArchiver archiver = createSubject(Collections.emptyList());
archiver.createArchive(new Assembly(), "full-name", "zip", null, null);
assertThrows(InvalidAssemblerConfigurationException.class, () -> {
final DefaultAssemblyArchiver archiver = createSubject(Collections.emptyList());
archiver.createArchive(new Assembly(), "full-name", "zip", null, null);
});
}

@Test
Expand All @@ -111,10 +116,10 @@ public void testCreateArchive() throws Exception {

final AssemblyArchiverPhase phase = mock(AssemblyArchiverPhase.class);

final File outDir = temporaryFolder.newFolder("out");
final File outDir = newFolder(temporaryFolder, "out");

final AssemblerConfigurationSource configSource = mock(AssemblerConfigurationSource.class);
when(configSource.getTemporaryRootDirectory()).thenReturn(new File(temporaryFolder.getRoot(), "temp"));
when(configSource.getTemporaryRootDirectory()).thenReturn(new File(temporaryFolder, "temp"));
when(configSource.getOverrideUid()).thenReturn(0);
when(configSource.getOverrideUserName()).thenReturn("root");
when(configSource.getOverrideGid()).thenReturn(0);
Expand Down Expand Up @@ -397,4 +402,13 @@ public String getDuplicateBehavior() {
return Archiver.DUPLICATES_ADD;
}
}

private static File newFolder(File root, String... subDirs) throws IOException {
String subFolder = String.join("/", subDirs);
File result = new File(root, subFolder);
if (!result.mkdirs()) {
throw new IOException("Couldn't create folders " + root);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

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

@RunWith(MockitoJUnitRunner.class)
@MockitoSettings(strictness = Strictness.WARN)
@ExtendWith(MockitoExtension.class)
public class ManifestCreationFinalizerTest {

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@TempDir
public File temporaryFolder;

@Test
public void testShouldDoNothingWhenArchiveConfigIsNull() throws Exception {
Expand All @@ -66,7 +68,7 @@ public void testShouldAddManifestWhenArchiverIsJarArchiver() throws Exception {
MavenProject project = new MavenProject(new Model());
MavenArchiveConfiguration config = new MavenArchiveConfiguration();

File tempDir = temporaryFolder.getRoot();
File tempDir = temporaryFolder;

Path manifestFile = tempDir.toPath().resolve("MANIFEST.MF");

Expand All @@ -78,7 +80,7 @@ public void testShouldAddManifestWhenArchiverIsJarArchiver() throws Exception {

archiver.setArchiveFinalizers(Collections.singletonList(new ManifestCreationFinalizer(null, project, config)));

File file = temporaryFolder.newFile();
File file = File.createTempFile("junit", null, temporaryFolder);

archiver.setDestFile(file);

Expand Down Expand Up @@ -112,7 +114,7 @@ public void testShouldAddManifestEntriesWhenArchiverIsJarArchiver() throws Excep

archiver.setArchiveFinalizers(Collections.singletonList(new ManifestCreationFinalizer(null, project, config)));

File file = temporaryFolder.newFile();
File file = File.createTempFile("junit", null, temporaryFolder);

archiver.setDestFile(file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
Expand All @@ -35,30 +36,34 @@
import org.codehaus.plexus.components.io.fileselectors.FileInfo;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@MockitoSettings(strictness = Strictness.WARN)
@ExtendWith(MockitoExtension.class)
public class AssemblyProxyArchiverTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@TempDir
public File temporaryFolder;

@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void addFileSetSkipWhenSourceIsAssemblyWorkDir() throws IOException, ArchiverException {
final File sources = temporaryFolder.getRoot();
final File sources = temporaryFolder;

final File workdir = new File(sources, "workdir");

Expand All @@ -75,9 +80,10 @@ public void addFileSetSkipWhenSourceIsAssemblyWorkDir() throws IOException, Arch
assertTrue(tracker.added.isEmpty());
}

@Test(timeout = 5000)
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void addFileSetAddExcludeWhenSourceContainsAssemblyWorkDir() throws IOException, ArchiverException {
final File sources = temporaryFolder.getRoot();
final File sources = temporaryFolder;

final File workdir = new File(sources, "workdir");
workdir.mkdir();
Expand Down Expand Up @@ -121,7 +127,7 @@ public void addFileNoPermsCallAcceptFilesOnlyOnce() throws IOException, Archiver
new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."));
archiver.setForced(true);

final File inputFile = temporaryFolder.newFile();
final File inputFile = File.createTempFile("junit", null, temporaryFolder);
archiver.addFile(inputFile, "file.txt");

assertEquals(1, counter.getCount());
Expand All @@ -134,7 +140,7 @@ public void addFileNoPermsCallAcceptFilesOnlyOnce() throws IOException, Archiver
public void addDirectoryNoPermsCallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
final Archiver delegate = new JarArchiver();

final File output = temporaryFolder.newFile();
final File output = File.createTempFile("junit", null, temporaryFolder);

delegate.setDestFile(output);

Expand All @@ -147,7 +153,7 @@ public void addDirectoryNoPermsCallAcceptFilesOnlyOnce() throws IOException, Arc

archiver.setForced(true);

final File dir = temporaryFolder.newFolder();
final File dir = newFolder(temporaryFolder, "junit");
Files.write(
dir.toPath().resolve("file.txt"), Collections.singletonList("This is a test."), StandardCharsets.UTF_8);

Expand All @@ -164,10 +170,10 @@ public void assemblyWorkDir() {
final List<FileSelector> selectors = new ArrayList<>();

final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver(
"prefix", delegate, null, selectors, null, new File(temporaryFolder.getRoot(), "module1"));
"prefix", delegate, null, selectors, null, new File(temporaryFolder, "module1"));

FileSet fileSet = mock(FileSet.class);
when(fileSet.getDirectory()).thenReturn(temporaryFolder.getRoot());
when(fileSet.getDirectory()).thenReturn(temporaryFolder);
when(fileSet.getStreamTransformer()).thenReturn(mock(InputStreamTransformer.class));

archiver.addFileSet(fileSet);
Expand All @@ -176,7 +182,7 @@ public void assemblyWorkDir() {
verify(delegate).addFileSet(delFileSet.capture());

assertThat(delFileSet.getValue().getDirectory(), is(fileSet.getDirectory()));
assertThat(delFileSet.getValue().getExcludes(), is(new String[] {"module1"}));
assertThat(delFileSet.getValue().getExcludes(), is(new String[]{"module1"}));
assertThat(delFileSet.getValue().getFileMappers(), is(fileSet.getFileMappers()));
assertThat(delFileSet.getValue().getFileSelectors(), is(fileSet.getFileSelectors()));
assertThat(delFileSet.getValue().getIncludes(), is(new String[0]));
Expand Down Expand Up @@ -207,4 +213,13 @@ public boolean isSelected(final FileInfo fileInfo) throws IOException {
return answer;
}
}

private static File newFolder(File root, String... subDirs) throws IOException {
String subFolder = String.join("/", subDirs);
File result = new File(root, subFolder);
if (!result.mkdirs()) {
throw new IOException("Couldn't create folders " + root);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.Assembly;
import org.codehaus.plexus.archiver.Archiver;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertSame;

public class AssemblyArchiverPhaseComparatorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
import org.apache.maven.plugins.assembly.model.DependencySet;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -45,13 +47,14 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
@MockitoSettings(strictness = Strictness.WARN)
@ExtendWith(MockitoExtension.class)
public class DependencySetAssemblyPhaseTest {
private DependencySetAssemblyPhase phase;

private DependencyResolver dependencyResolver;

@Before
@BeforeEach
public void setUp() {
this.dependencyResolver = mock(DependencyResolver.class);

Expand All @@ -61,7 +64,7 @@ public void setUp() {
@Test
public void testExecuteShouldAddOneDependencyFromProject()
throws AssemblyFormattingException, ArchiveCreationException, IOException,
InvalidAssemblerConfigurationException, DependencyResolutionException {
InvalidAssemblerConfigurationException, DependencyResolutionException {
final String outputLocation = "/out";

final MavenProject project = newMavenProject("group", "project", "0");
Expand Down
Loading
Loading