You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/04/21 19:28:22 UTC
[maven-assembly-plugin] branch setupInterpolators created (now
4d4e217)
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a change to branch setupInterpolators
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git.
at 4d4e217 use mockito for setupInterpolators
This branch includes the following new commits:
new 56d283f First set of tests migrated
new 3f43bd6 Inline configSource
new 4d4e217 use mockito for setupInterpolators
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven-assembly-plugin] 01/03: First set of tests migrated
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch setupInterpolators
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
commit 56d283fdbc89d45e3720a667b1081a12e1b51a4a
Author: rfscholte <rf...@apache.org>
AuthorDate: Mon Apr 20 22:11:08 2020 +0200
First set of tests migrated
---
.../archive/DefaultAssemblyArchiverTest.java | 57 ++++++++++------------
.../assembly/utils/AssemblyFormatUtilsTest.java | 20 ++------
2 files changed, 29 insertions(+), 48 deletions(-)
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java
index 4294b66..b92397b 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java
@@ -25,7 +25,6 @@ import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase;
import org.apache.maven.plugins.assembly.artifact.DependencyResolutionException;
-import org.apache.maven.plugins.assembly.artifact.DependencyResolver;
import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.plugins.assembly.mojos.AbstractAssemblyMojo;
@@ -59,6 +58,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.anyInt;
import static org.easymock.EasyMock.anyObject;
@@ -90,14 +94,10 @@ public class DefaultAssemblyArchiverTest
public static void setupInterpolators( AssemblerConfigurationSource configSource, MavenProject mavenProject )
{
- expect( configSource.getRepositoryInterpolator() ).andReturn(
- FixedStringSearchInterpolator.create() ).anyTimes();
- expect( configSource.getCommandLinePropsInterpolator() ).andReturn(
- FixedStringSearchInterpolator.create() ).anyTimes();
- expect( configSource.getEnvInterpolator() ).andReturn( FixedStringSearchInterpolator.create() ).anyTimes();
- expect( configSource.getMainProjectInterpolator() ).andReturn(
- AbstractAssemblyMojo.mainProjectInterpolator( mavenProject ) ).anyTimes();
-
+ when( configSource.getRepositoryInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
+ when( configSource.getCommandLinePropsInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
+ when( configSource.getEnvInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
+ when( configSource.getMainProjectInterpolator() ).thenReturn( AbstractAssemblyMojo.mainProjectInterpolator( mavenProject ) );
}
@Before
@@ -210,37 +210,30 @@ public class DefaultAssemblyArchiverTest
macArchiverManager.expectGetArchiver( "dummy", archiver );
- final AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
final String simpleConfig = "value";
- expect( configSource.getArchiverConfig() ).andReturn(
- "<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>" ).anyTimes();
+ when( configSource.getArchiverConfig() ).thenReturn(
+ "<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>" );
final MavenProject project = new MavenProject( new Model() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
-
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
- expect( configSource.isDryRun() ).andReturn( false ).anyTimes();
-
- expect( configSource.getWorkingDirectory() ).andReturn( new File( "." ) ).anyTimes();
-
- expect( configSource.isUpdateOnly() ).andReturn( false ).anyTimes();
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getWorkingDirectory() ).thenReturn( new File( "." ) );
final ArtifactRepository lr = mm.createMock( ArtifactRepository.class );
expect( lr.getBasedir() ).andReturn( "/path/to/local/repo" ).anyTimes();
- expect( configSource.getLocalRepository() ).andReturn( lr ).anyTimes();
- expect( configSource.isIgnorePermissions() ).andReturn( true );
+ when( configSource.getLocalRepository() ).thenReturn( lr );
+ when( configSource.isIgnorePermissions() ).thenReturn( true );
setupInterpolators( configSource, project );
- expect( configSource.getOverrideUid() ).andReturn( 0 ).atLeastOnce();
- expect( configSource.getOverrideUserName() ).andReturn( "root" ).atLeastOnce();
- expect( configSource.getOverrideGid() ).andReturn( 0 ).atLeastOnce();
- expect( configSource.getOverrideGroupName() ).andReturn( "root" ).atLeastOnce();
+ when( configSource.getOverrideUid() ).thenReturn( 0 );
+ when( configSource.getOverrideUserName() ).thenReturn( "root" );
+ when( configSource.getOverrideGid() ).thenReturn( 0 );
+ when( configSource.getOverrideGroupName() ).thenReturn( "root" );
mm.replayAll();
@@ -251,6 +244,11 @@ public class DefaultAssemblyArchiverTest
assertEquals( simpleConfig, archiver.getSimpleConfig() );
+ verify( configSource, times( 2 ) ).getOverrideUid();
+ verify( configSource, times( 2 ) ).getOverrideUserName();
+ verify( configSource, times( 2 ) ).getOverrideGid();
+ verify( configSource, times( 2 ) ).getOverrideGroupName();
+
mm.verifyAll();
}
@@ -634,8 +632,6 @@ public class DefaultAssemblyArchiverTest
{
final ArchiverManager archiverManager;
- final DependencyResolver dependencyResolver;
-
private final EasyMockSupport mm;
Archiver archiver;
@@ -644,9 +640,6 @@ public class DefaultAssemblyArchiverTest
{
this.mm = mm;
archiverManager = mm.createControl().createMock( ArchiverManager.class );
-
- dependencyResolver = mm.createControl().createMock( DependencyResolver.class );
-
}
void expectGetDestFile( final File file )
diff --git a/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java b/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
index af34c81..8d72694 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
@@ -685,12 +685,10 @@ public class AssemblyFormatUtilsTest
when( session.getExecutionProperties() ).thenReturn( System.getProperties() );
when( session.getUserProperties() ).thenReturn( new Properties() );
- final AssemblerConfigurationSource cs = mockManager.createMock( AssemblerConfigurationSource.class );
- expect( cs.getMavenSession() ).andReturn( session ).anyTimes();
+ final AssemblerConfigurationSource cs = mock( AssemblerConfigurationSource.class );
+ when( cs.getMavenSession() ).thenReturn( session );
DefaultAssemblyArchiverTest.setupInterpolators( cs, mainProject );
- mockManager.replayAll();
-
final String result =
AssemblyFormatUtils.evaluateFileNameMapping( expression, artifactMock, mainProject,
moduleArtifactMock, cs,
@@ -698,11 +696,6 @@ public class AssemblyFormatUtilsTest
AssemblyFormatUtils.artifactProjectInterpolator( artifactProject ) );
assertEquals( checkValue, result );
-
- mockManager.verifyAll();
-
- // clear out for next call.
- mockManager.resetAll();
}
private void verifyOutputDir( final String outDir, final String finalName, final String projectFinalName,
@@ -788,23 +781,18 @@ public class AssemblyFormatUtilsTest
when( session.getExecutionProperties() ).thenReturn( System.getProperties() );
when( session.getUserProperties() ).thenReturn( new Properties() );
- final AssemblerConfigurationSource cs = mockManager.createMock( AssemblerConfigurationSource.class );
- expect( cs.getMavenSession() ).andReturn( session ).anyTimes();
+ final AssemblerConfigurationSource cs = mock( AssemblerConfigurationSource.class );
+ when( cs.getMavenSession() ).thenReturn( session );
DefaultAssemblyArchiverTest.setupInterpolators( cs, mainProject );
String result;
- mockManager.replayAll();
result =
AssemblyFormatUtils.getOutputDirectory( outDir, finalName, cs,
AssemblyFormatUtils.moduleProjectInterpolator( moduleProject ),
AssemblyFormatUtils.artifactProjectInterpolator( artifactProject ) );
assertEquals( checkValue, result );
-
- mockManager.verifyAll();
-
- mockManager.resetAll();
}
private void verifyDistroName( final String assemblyId, final String finalName, final boolean appendAssemblyId,
[maven-assembly-plugin] 02/03: Inline configSource
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch setupInterpolators
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
commit 3f43bd6250d26592c160c5c2b8ecc64c6c9665c5
Author: rfscholte <rf...@apache.org>
AuthorDate: Tue Apr 21 19:58:56 2020 +0200
Inline configSource
---
.../phase/DependencySetAssemblyPhaseTest.java | 37 ++++-
.../archive/phase/FileSetAssemblyPhaseTest.java | 33 ++--
.../archive/phase/ModuleSetAssemblyPhaseTest.java | 182 +++++++++++++++------
.../assembly/archive/task/AddArtifactTaskTest.java | 31 ++--
.../archive/task/AddDependencySetsTaskTest.java | 79 +++++++--
.../assembly/archive/task/AddFileSetsTaskTest.java | 33 ++--
.../MockAndControlForAddArtifactTask.java | 32 ----
.../MockAndControlForAddDependencySetsTask.java | 50 +-----
.../MockAndControlForAddFileSetsTask.java | 45 +----
9 files changed, 293 insertions(+), 229 deletions(-)
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/DependencySetAssemblyPhaseTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/DependencySetAssemblyPhaseTest.java
index c37b404..5b4e0ad 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/DependencySetAssemblyPhaseTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/DependencySetAssemblyPhaseTest.java
@@ -1,5 +1,7 @@
package org.apache.maven.plugins.assembly.archive.phase;
+import static org.easymock.EasyMock.expect;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,13 +22,17 @@ package org.apache.maven.plugins.assembly.archive.phase;
*/
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
+import java.util.Properties;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
+import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask;
@@ -36,6 +42,7 @@ import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.plugins.assembly.model.DependencySet;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.classextension.EasyMockSupport;
@@ -75,14 +82,26 @@ public class DependencySetAssemblyPhaseTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mm, project );
- macTask.expectCSGetRepositories( null, null );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
+ expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
+ expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
macTask.expectGetDestFile( new File( "junk" ) );
// macTask.expectAddFile( artifactFile, "out/dep", 10 );
project.setArtifacts( Collections.singleton( artifact ) );
- macTask.expectCSGetFinalName( "final-name" );
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).anyTimes();
final Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
@@ -95,7 +114,7 @@ public class DependencySetAssemblyPhaseTest
mm.replayAll();
createPhase( macTask, logger, macTask.dependencyResolver ).execute( assembly, macTask.archiver,
- macTask.configSource );
+ configSource );
mm.verifyAll();
}
@@ -123,12 +142,22 @@ public class DependencySetAssemblyPhaseTest
final Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask( mm, null );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
macTask.expectResolveDependencySets();
mm.replayAll();
- createPhase( macTask, logger, macTask.dependencyResolver ).execute( assembly, null, macTask.configSource );
+ createPhase( macTask, logger, macTask.dependencyResolver ).execute( assembly, null, configSource );
mm.verifyAll();
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java
index eb43fb5..03c1544 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java
@@ -19,14 +19,16 @@ package org.apache.maven.plugins.assembly.archive.phase;
* under the License.
*/
+import static org.mockito.Mockito.mock;
+
import org.apache.maven.model.Model;
-import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
+import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
import org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask;
-import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.plugins.assembly.model.FileSet;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.logging.Logger;
import org.easymock.EasyMock;
import org.easymock.classextension.EasyMockSupport;
@@ -48,17 +50,16 @@ public class FileSetAssemblyPhaseTest
assembly.setId( "test" );
final MockAndControlForLogger macLogger = new MockAndControlForLogger();
- final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask( mm );
-
- mm.replayAll();
+
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
+ Archiver archiver = mock( Archiver.class );
- createPhase( macLogger ).execute( assembly, macTask.archiver, macTask.configSource );
-
- mm.verifyAll();
+ createPhase( macLogger ).execute( assembly, archiver, configSource );
}
- @Test public void testShouldAddOneFileSet()
- throws ArchiveCreationException, AssemblyFormattingException
+ @Test
+ public void testShouldAddOneFileSet()
+ throws Exception
{
final Assembly assembly = new Assembly();
@@ -75,8 +76,10 @@ public class FileSetAssemblyPhaseTest
final MockAndControlForLogger macLogger = new MockAndControlForLogger();
final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask( mm );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
- macTask.expectGetArchiveBaseDirectory();
+ expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
final MavenProject project = new MavenProject( new Model() );
@@ -87,13 +90,15 @@ public class FileSetAssemblyPhaseTest
final int[] modes = { -1, -1, dirMode, fileMode };
- macTask.expectAdditionOfSingleFileSet( project, "final-name", false, modes, 1, true );
+ macTask.expectAdditionOfSingleFileSet( project, false, modes, 1, true );
+ expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
- createPhase( macLogger ).execute( assembly, macTask.archiver, macTask.configSource );
+ createPhase( macLogger ).execute( assembly, macTask.archiver, configSource );
mm.verifyAll();
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
index 297ac95..beefbb9 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.assembly.archive.phase;
*/
import static java.util.Collections.singleton;
+import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -34,10 +35,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
+import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
@@ -53,6 +57,7 @@ import org.apache.maven.plugins.assembly.model.ModuleSources;
import org.apache.maven.plugins.assembly.utils.TypeConversionUtils;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.classextension.EasyMock;
@@ -134,9 +139,11 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = new MavenProject( model );
- final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
- macTask.expectGetFinalName( null );
+ expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
final FileSet fs = new FileSet();
@@ -153,14 +160,14 @@ public class ModuleSetAssemblyPhaseTest
artifactProject.setArtifact( artifact );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
final FileSet result =
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).createFileSet( fs, sources,
artifactProject,
- macTask.configSource );
+ configSource );
assertEquals( "artifact/", result.getOutputDirectory() );
@@ -178,9 +185,11 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = new MavenProject( model );
- final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
- macTask.expectGetFinalName( null );
+ expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
final FileSet fs = new FileSet();
fs.setOutputDirectory( "out" );
@@ -198,14 +207,14 @@ public class ModuleSetAssemblyPhaseTest
when( artifact.getArtifactId() ).thenReturn( "artifact" );
artifactProject.setArtifact( artifact );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
final FileSet result =
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).createFileSet( fs, sources,
artifactProject,
- macTask.configSource );
+ configSource );
assertEquals( "artifact/out/", result.getOutputDirectory() );
@@ -218,9 +227,12 @@ public class ModuleSetAssemblyPhaseTest
{
final EasyMockSupport mm = new EasyMockSupport();
- final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, null );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
- macTask.expectGetFinalName( null );
+
+ expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
final FileSet fs = new FileSet();
@@ -241,13 +253,13 @@ public class ModuleSetAssemblyPhaseTest
Artifact artifact = mock( Artifact.class );
project.setArtifact( artifact );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
final FileSet result =
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).createFileSet( fs, sources, project,
- macTask.configSource );
+ configSource );
assertEquals( 1, result.getExcludes().size() );
assertEquals( "submodule/**", result.getExcludes().get( 0 ) );
@@ -274,6 +286,9 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
final MavenProject module = createProject( "group", "module", "version", project );
@@ -286,8 +301,8 @@ public class ModuleSetAssemblyPhaseTest
projects.add( module );
- macTask.expectGetReactorProjects( projects );
- macTask.expectGetFinalName( "final-name" );
+ expect( configSource.getReactorProjects() ).andReturn( projects ).atLeastOnce();
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectGetMode( 0777, 0777 );
@@ -315,12 +330,12 @@ public class ModuleSetAssemblyPhaseTest
final Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
macTask.expectResolveDependencySets();
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
final ModuleSetAssemblyPhase phase = createPhase( logger, macTask.dependencyResolver, null );
- phase.execute( assembly, macTask.archiver, macTask.configSource );
+ phase.execute( assembly, macTask.archiver, configSource );
mm.verifyAll();
}
@@ -339,6 +354,9 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
final ModuleBinaries binaries = new ModuleBinaries();
@@ -360,7 +378,7 @@ public class ModuleSetAssemblyPhaseTest
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).addModuleBinaries( null, null, binaries,
projects,
macTask.archiver,
- macTask.configSource );
+ configSource );
mm.verifyAll();
}
@@ -372,13 +390,17 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, null );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+
Artifact artifact = mock( Artifact.class );
when( artifact.getClassifier() ).thenReturn( "test" );
final File artifactFile = temporaryFolder.newFile();
when( artifact.getFile() ).thenReturn( artifactFile );
- macTask.expectGetFinalName( "final-name" );
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectGetMode( 0222, 0222 );
macTask.expectAddFile( artifactFile, "out/artifact",
@@ -400,7 +422,7 @@ public class ModuleSetAssemblyPhaseTest
final Set<MavenProject> projects = singleton( project );
macTask.expectResolveDependencySets();
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
@@ -408,7 +430,7 @@ public class ModuleSetAssemblyPhaseTest
createPhase( logger, macTask.dependencyResolver, null ).addModuleBinaries( null, null, binaries, projects,
macTask.archiver,
- macTask.configSource );
+ configSource );
mm.verifyAll();
}
@@ -420,6 +442,9 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
Artifact artifact = mock( Artifact.class );
when( artifact.getClassifier() ).thenReturn( "test" );
@@ -444,7 +469,7 @@ public class ModuleSetAssemblyPhaseTest
try
{
createPhase( logger, null ).addModuleBinaries( null, null, binaries, projects, macTask.archiver,
- macTask.configSource );
+ configSource );
fail( "Should throw an invalid configuration exception because of module with missing attachment." );
}
@@ -465,12 +490,15 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
Artifact artifact = mock( Artifact.class );
final File artifactFile = temporaryFolder.newFile();
when( artifact.getFile() ).thenReturn( artifactFile );
- macTask.expectGetFinalName( "final-name" );
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectAddFile( artifactFile, "out/artifact",
TypeConversionUtils.modeToInt( "777",
@@ -491,7 +519,7 @@ public class ModuleSetAssemblyPhaseTest
final Set<MavenProject> projects = singleton( project );
macTask.expectResolveDependencySets();
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
@@ -499,7 +527,7 @@ public class ModuleSetAssemblyPhaseTest
createPhase( logger, macTask.dependencyResolver, null ).addModuleBinaries( null, null, binaries, projects,
macTask.archiver,
- macTask.configSource );
+ configSource );
mm.verifyAll();
}
@@ -529,6 +557,9 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
Artifact artifact = mock( Artifact.class );
final File artifactFile = temporaryFolder.newFile();
@@ -537,7 +568,7 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
project.setArtifact( artifact );
- macTask.expectGetFinalName( "final-name" );
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectGetMode( 0222, 0222 );
@@ -550,13 +581,13 @@ public class ModuleSetAssemblyPhaseTest
binaries.setOutputFileNameMapping( "artifact" );
binaries.setUnpack( false );
binaries.setFileMode( "777" );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ),
null ).addModuleArtifact( artifact, project, macTask.archiver,
- macTask.configSource, binaries );
+ configSource, binaries );
mm.verifyAll();
}
@@ -576,10 +607,12 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask( mm );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
final MavenProject project = createProject( "group", "artifact", "version", null );
- macTask.expectGetProject( project );
+ expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
project.setArtifact( mock( Artifact.class ) );
@@ -594,20 +627,21 @@ public class ModuleSetAssemblyPhaseTest
sources.addFileSet( fs );
- macTask.expectGetArchiveBaseDirectory();
+ expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
final int mode = TypeConversionUtils.modeToInt( "777", new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
final int[] modes = { -1, -1, mode, mode };
- macTask.expectAdditionOfSingleFileSet( project, "final-name", false, modes, 1, true, false );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ macTask.expectAdditionOfSingleFileSet( project, false, modes, 1, true );
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
final Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
createPhase( logger, null ).addModuleSourceFileSets( sources, projects, macTask.archiver,
- macTask.configSource );
+ configSource );
mm.verifyAll();
}
@@ -620,12 +654,21 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
- final MockAndControlForAddDependencySetsTask macTask =
- new MockAndControlForAddDependencySetsTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
final List<MavenProject> projects = Collections.singletonList( project );
- macTask.expectGetReactorProjects( projects );
+ expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
@@ -633,7 +676,7 @@ public class ModuleSetAssemblyPhaseTest
mm.replayAll();
final Set<MavenProject> moduleProjects =
- ModuleSetAssemblyPhase.getModuleProjects( moduleSet, macTask.configSource, logger );
+ ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertTrue( moduleProjects.isEmpty() );
@@ -648,8 +691,16 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
- final MockAndControlForAddDependencySetsTask macTask =
- new MockAndControlForAddDependencySetsTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
final MavenProject project2 = createProject( "group", "artifact2", "version", null );
@@ -657,7 +708,7 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project );
projects.add( project2 );
- macTask.expectGetReactorProjects( projects );
+ expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
@@ -665,7 +716,7 @@ public class ModuleSetAssemblyPhaseTest
mm.replayAll();
final Set<MavenProject> moduleProjects =
- ModuleSetAssemblyPhase.getModuleProjects( moduleSet, macTask.configSource, logger );
+ ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertTrue( moduleProjects.isEmpty() );
@@ -680,8 +731,17 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
- final MockAndControlForAddDependencySetsTask macTask =
- new MockAndControlForAddDependencySetsTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
final MavenProject project2 = createProject( "group", "artifact2", "version", project );
@@ -689,7 +749,7 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project );
projects.add( project2 );
- macTask.expectGetReactorProjects( projects );
+ expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
@@ -697,7 +757,7 @@ public class ModuleSetAssemblyPhaseTest
mm.replayAll();
final Set<MavenProject> moduleProjects =
- ModuleSetAssemblyPhase.getModuleProjects( moduleSet, macTask.configSource, logger );
+ ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertFalse( moduleProjects.isEmpty() );
@@ -716,8 +776,17 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
- final MockAndControlForAddDependencySetsTask macTask =
- new MockAndControlForAddDependencySetsTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
final MavenProject project2 = createProject( "group", "artifact2", "version", project );
final MavenProject project3 = createProject( "group", "artifact3", "version", project2 );
@@ -727,7 +796,7 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project2 );
projects.add( project3 );
- macTask.expectGetReactorProjects( projects );
+ expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
@@ -735,7 +804,7 @@ public class ModuleSetAssemblyPhaseTest
mm.replayAll();
final Set<MavenProject> moduleProjects =
- ModuleSetAssemblyPhase.getModuleProjects( moduleSet, macTask.configSource, logger );
+ ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertEquals( 2, moduleProjects.size() );
@@ -756,8 +825,17 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
- final MockAndControlForAddDependencySetsTask macTask =
- new MockAndControlForAddDependencySetsTask( mm, project );
+ AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
Artifact artifact1 = mock( Artifact.class );
project.setArtifact( artifact1 );
@@ -784,7 +862,7 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project2 );
projects.add( project3 );
- macTask.expectGetReactorProjects( projects );
+ expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
@@ -794,7 +872,7 @@ public class ModuleSetAssemblyPhaseTest
mm.replayAll();
final Set<MavenProject> moduleProjects =
- ModuleSetAssemblyPhase.getModuleProjects( moduleSet, macTask.configSource, logger );
+ ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertTrue( moduleProjects.isEmpty() );
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
index 32d13fa..fa7d867 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.assembly.archive.task;
*/
import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.Assert.fail;
@@ -32,7 +33,9 @@ import java.util.Arrays;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.model.Model;
+import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
+import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
import org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask;
import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.DependencySet;
@@ -56,6 +59,8 @@ public class AddArtifactTaskTest
private EasyMockSupport mockManager;
private MockAndControlForAddArtifactTask mac;
+
+ private AssemblerConfigurationSource configSource;
@Before
public void setUp()
@@ -71,7 +76,11 @@ public class AddArtifactTaskTest
MavenProject mainProject = new MavenProject( model );
mac = new MockAndControlForAddArtifactTask( mockManager, mainProject );
- mac.expectGetFinalName( "final-name" );
+ configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getProject() ).andReturn( mainProject ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
}
@Test
@@ -87,13 +96,13 @@ public class AddArtifactTaskTest
mac.expectGetMode( 0222, 0222 );
mac.expectGetDestFile( new File( "junk" ) );
mac.expectAddFile( artifactFile, outputLocation );
- mac.expectInterpolators();
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
AddArtifactTask task = createTask( artifact );
- task.execute( mac.archiver, mac.configSource );
+ task.execute( mac.archiver, configSource );
mockManager.verifyAll();
}
@@ -118,7 +127,7 @@ public class AddArtifactTaskTest
mac.expectGetDestFile( new File( "junk" ) );
mac.expectAddFile( artifactFile, outputDir + artifactId + "-" + version + "." + ext );
- mac.expectInterpolators();
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
AddArtifactTask task =
@@ -133,7 +142,7 @@ public class AddArtifactTaskTest
MavenProject project = new MavenProject( model );
task.setProject( project );
- task.execute( mac.archiver, mac.configSource );
+ task.execute( mac.archiver, configSource );
mockManager.verifyAll();
}
@@ -152,7 +161,7 @@ public class AddArtifactTaskTest
throws ArchiveCreationException, AssemblyFormattingException, IOException
{
mac.expectModeChange( -1, -1, -1, -1, 1 );
- mac.expectInterpolators();
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
Artifact artifact = mock( Artifact.class );
when( artifact.getFile() ).thenReturn( temporaryFolder.newFile() );
@@ -173,7 +182,7 @@ public class AddArtifactTaskTest
task.setUnpack( true );
- task.execute( mac.archiver, mac.configSource );
+ task.execute( mac.archiver, configSource );
mockManager.verifyAll();
}
@@ -186,7 +195,7 @@ public class AddArtifactTaskTest
int fileMode = TypeConversionUtils.modeToInt( "777", new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
mac.expectModeChange( -1, -1, directoryMode, fileMode, 2 );
- mac.expectInterpolators();
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
Artifact artifact = mock( Artifact.class );
when( artifact.getFile() ).thenReturn( temporaryFolder.newFile() );
@@ -210,7 +219,7 @@ public class AddArtifactTaskTest
task.setDirectoryMode( directoryMode );
task.setFileMode( fileMode );
- task.execute( mac.archiver, mac.configSource );
+ task.execute( mac.archiver, configSource );
mockManager.verifyAll();
}
@@ -229,7 +238,7 @@ public class AddArtifactTaskTest
mac.expectGetDestFile( new File( "junk" ) );
mac.expectAddArchivedFileSet();
- mac.expectInterpolators();
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
@@ -239,7 +248,7 @@ public class AddArtifactTaskTest
task.setIncludes( Arrays.asList( includes ) );
task.setExcludes( Arrays.asList( excludes ) );
- task.execute( mac.archiver, mac.configSource );
+ task.execute( mac.archiver, configSource );
mockManager.verifyAll();
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
index 464de0a..0c5ad4f 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
@@ -1,5 +1,7 @@
package org.apache.maven.plugins.assembly.archive.task;
+import static org.easymock.EasyMock.expect;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -27,7 +29,9 @@ import static org.mockito.Mockito.when;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
+import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
@@ -36,6 +40,7 @@ import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.DependencySet;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.classextension.EasyMockSupport;
@@ -47,6 +52,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Properties;
import java.util.Set;
public class AddDependencySetsTaskTest
@@ -103,18 +109,30 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager, mainProject );
+ AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( mainProject ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
macTask.expectBuildFromRepository( depProject );
- macTask.expectCSGetFinalName( mainAid + "-" + mainVer );
+ expect( configSource.getFinalName() ).andReturn( mainAid + "-" + mainVer ).anyTimes();
- macTask.expectCSGetRepositories( null, null );
+ expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
+ expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectAddFile( newFile, outDir + depAid + "-" + depVer + "." + depExt, 10 );
macTask.expectGetMode( 0222, 0222 );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
@@ -124,7 +142,7 @@ public class AddDependencySetsTaskTest
new AddDependencySetsTask( Collections.singletonList( ds ), Collections.singleton( depArtifact ),
depProject, macTask.projectBuilder, logger );
- task.addDependencySet( ds, macTask.archiver, macTask.configSource );
+ task.addDependencySet( ds, macTask.archiver, configSource );
mockManager.verifyAll();
}
@@ -137,6 +155,17 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager );
+
+ AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( null ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
final DependencySet ds = new DependencySet();
ds.setOutputDirectory( "/out" );
@@ -148,7 +177,7 @@ public class AddDependencySetsTaskTest
final AddDependencySetsTask task =
new AddDependencySetsTask( Collections.singletonList( ds ), null, project, macTask.projectBuilder, logger );
- task.addDependencySet( ds, null, macTask.configSource );
+ task.addDependencySet( ds, null, configSource );
mockManager.verifyAll();
}
@@ -164,6 +193,17 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager, new MavenProject( new Model() ) );
+ AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
final String aid = "test-dep";
final String version = "2.0-SNAPSHOT";
@@ -183,15 +223,16 @@ public class AddDependencySetsTaskTest
macTask.expectGetDestFile( destFile );
macTask.expectBuildFromRepository( pbe );
- macTask.expectCSGetRepositories( null, null );
- macTask.expectCSGetFinalName( "final-name" );
+ expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
+ expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).anyTimes();
macTask.expectAddFile( file, "out/" + aid + "-" + version + "." + type );
macTask.expectGetMode( 0222, 0222 );
final DependencySet ds = new DependencySet();
ds.setOutputDirectory( "/out" );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
@@ -201,7 +242,7 @@ public class AddDependencySetsTaskTest
new AddDependencySetsTask( Collections.singletonList( ds ), Collections.singleton( depArtifact ),
project, macTask.projectBuilder, logger );
- task.addDependencySet( ds, macTask.archiver, macTask.configSource );
+ task.addDependencySet( ds, macTask.archiver, configSource );
mockManager.verifyAll();
}
@@ -238,6 +279,17 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager, new MavenProject( new Model() ) );
+ AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ MavenSession session = mock( MavenSession.class );
+
+ when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
+ when( session.getSystemProperties() ).thenReturn( new Properties() );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ when( session.getExecutionProperties() ).thenReturn( new Properties() );
+
+ expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+
Artifact artifact = mock( Artifact.class );
final File artifactFile = temporaryFolder.newFile();
@@ -253,8 +305,9 @@ public class AddDependencySetsTaskTest
}
macTask.expectGetDestFile( new File( "junk" ) );
- macTask.expectCSGetFinalName( "final-name" );
- macTask.expectCSGetRepositories( null, null );
+ expect( configSource.getFinalName() ).andReturn( "final-name" ).anyTimes();
+ expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
+ expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
final MavenProject depProject = new MavenProject( new Model() );
@@ -267,11 +320,11 @@ public class AddDependencySetsTaskTest
Collections.singleton(
artifact ), project,
macTask.projectBuilder, logger );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
- task.addDependencySet( ds, macTask.archiver, macTask.configSource );
+ task.addDependencySet( ds, macTask.archiver, configSource );
mockManager.verifyAll();
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java
index 98d861f..2d4d461 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.assembly.archive.task;
*/
import org.apache.maven.model.Model;
+import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
import org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask;
@@ -48,6 +49,8 @@ public class AddFileSetsTaskTest
private EasyMockSupport mockManager;
private MockAndControlForAddFileSetsTask macTask;
+
+ private AssemblerConfigurationSource configSource;
@Before
public void setUp()
@@ -55,6 +58,8 @@ public class AddFileSetsTaskTest
mockManager = new EasyMockSupport();
macTask = new MockAndControlForAddFileSetsTask( mockManager );
+ configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
}
@Test
@@ -140,13 +145,14 @@ public class AddFileSetsTaskTest
final int[] modes = { -1, -1, -1, -1 };
- macTask.expectAdditionOfSingleFileSet( null, null, true, modes, 1, true, false );
+ macTask.expectAdditionOfSingleFileSet( null, true, modes, 1, true );
+ expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
// macTask.expectGetProject( null );
final MavenProject project = new MavenProject( new Model() );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
final AddFileSetsTask task = new AddFileSetsTask( new ArrayList<FileSet>() );
@@ -154,7 +160,7 @@ public class AddFileSetsTaskTest
task.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
task.setProject( project );
- task.addFileSet( fs, macTask.archiver, macTask.configSource, macTask.archiveBaseDir );
+ task.addFileSet( fs, macTask.archiver, configSource, macTask.archiveBaseDir );
mockManager.verifyAll();
}
@@ -177,12 +183,13 @@ public class AddFileSetsTaskTest
final int[] modes = { -1, -1, -1, -1 };
- macTask.expectAdditionOfSingleFileSet( null, null, true, modes, 1, true, false );
+ macTask.expectAdditionOfSingleFileSet( null, true, modes, 1, true );
+ expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
//macTask.expectGetProject( null );
final MavenProject project = new MavenProject( new Model() );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
@@ -191,7 +198,7 @@ public class AddFileSetsTaskTest
task.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
task.setProject( project );
- task.addFileSet( fs, macTask.archiver, macTask.configSource, archiveBaseDir );
+ task.addFileSet( fs, macTask.archiver, configSource, archiveBaseDir );
mockManager.verifyAll();
}
@@ -208,7 +215,7 @@ public class AddFileSetsTaskTest
final File archiveBaseDir = temporaryFolder.newFolder();
- macTask.expectGetFinalName( "finalName" );
+ expect( configSource.getFinalName() ).andReturn( "finalName" ).atLeastOnce();
//macTask.expectGetProject( null );
@@ -216,7 +223,7 @@ public class AddFileSetsTaskTest
expect( macTask.archiver.getOverrideFileMode() ).andReturn( -1 );
final MavenProject project = new MavenProject( new Model() );
- DefaultAssemblyArchiverTest.setupInterpolators( macTask.configSource );
+ DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mockManager.replayAll();
@@ -225,7 +232,7 @@ public class AddFileSetsTaskTest
task.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
task.setProject( project );
- task.addFileSet( fs, macTask.archiver, macTask.configSource, archiveBaseDir );
+ task.addFileSet( fs, macTask.archiver, configSource, archiveBaseDir );
mockManager.verifyAll();
}
@@ -235,7 +242,7 @@ public class AddFileSetsTaskTest
throws Exception
{
macTask.archiveBaseDir = new File( temporaryFolder.getRoot(), "archive");
- macTask.expectGetArchiveBaseDirectory();
+ expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
mockManager.replayAll();
@@ -243,7 +250,7 @@ public class AddFileSetsTaskTest
try
{
- task.execute( macTask.archiver, macTask.configSource );
+ task.execute( macTask.archiver, configSource );
fail( "Should throw exception due to non-existent archiveBasedir location that was provided." );
}
@@ -260,7 +267,7 @@ public class AddFileSetsTaskTest
throws Exception
{
macTask.archiveBaseDir = temporaryFolder.newFile();
- macTask.expectGetArchiveBaseDirectory();
+ expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
mockManager.replayAll();
@@ -268,7 +275,7 @@ public class AddFileSetsTaskTest
try
{
- task.execute( macTask.archiver, macTask.configSource );
+ task.execute( macTask.archiver, configSource );
fail( "Should throw exception due to non-directory archiveBasedir location that was provided." );
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddArtifactTask.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddArtifactTask.java
index d5c8f51..2719adf 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddArtifactTask.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddArtifactTask.java
@@ -50,12 +50,8 @@ public class MockAndControlForAddArtifactTask
public final Archiver archiver;
- public final AssemblerConfigurationSource configSource;
-
public final DependencyResolver dependencyResolver;
- private MavenProject project = null;
-
public MockAndControlForAddArtifactTask( final EasyMockSupport mockManager )
{
this( mockManager, null );
@@ -63,24 +59,8 @@ public class MockAndControlForAddArtifactTask
public MockAndControlForAddArtifactTask( final EasyMockSupport mockManager, final MavenProject project )
{
- this.project = project;
-
archiver = mockManager.createMock( Archiver.class );
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
dependencyResolver = mockManager.createMock( DependencyResolver.class );
-
- enableDefaultExpectations();
- }
-
- private void enableDefaultExpectations()
- {
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
- }
-
- public void expectGetFinalName( final String finalName )
- {
- expect( configSource.getFinalName() ).andReturn( finalName ).atLeastOnce();
}
public void expectGetDestFile( final File destFile )
@@ -175,12 +155,6 @@ public class MockAndControlForAddArtifactTask
}
}
- public void expectGetReactorProjects( final List<MavenProject> projects )
- {
- expect( configSource.getReactorProjects() ).andReturn( projects ).atLeastOnce();
- }
-
-
public void expectResolveDependencySets()
throws DependencyResolutionException
{
@@ -190,10 +164,4 @@ public class MockAndControlForAddArtifactTask
new LinkedHashMap<DependencySet, Set<Artifact>>() ).anyTimes();
}
-
- public void expectInterpolators()
- {
- DefaultAssemblyArchiverTest.setupInterpolators( configSource );
-
- }
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java
index 4989f0b..d801d62 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddDependencySetsTask.java
@@ -21,8 +21,6 @@ package org.apache.maven.plugins.assembly.archive.task.testutils;
import junit.framework.Assert;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.artifact.DependencyResolutionException;
@@ -46,20 +44,18 @@ import java.io.File;
import java.nio.charset.Charset;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Properties;
import java.util.Set;
import static org.easymock.EasyMock.anyInt;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.expect;
+
public class MockAndControlForAddDependencySetsTask
{
public final Archiver archiver;
- public final AssemblerConfigurationSource configSource;
-
public final ProjectBuilder projectBuilder;
public final ArchiverManager archiverManager;
@@ -68,9 +64,6 @@ public class MockAndControlForAddDependencySetsTask
private final MavenProject project;
- private final MavenSession session;
-
- private final ProjectBuildingRequest projectBuildingRequest;
public MockAndControlForAddDependencySetsTask( final EasyMockSupport mockManager )
{
@@ -81,32 +74,13 @@ public class MockAndControlForAddDependencySetsTask
{
this.project = project;
- this.session = mockManager.createMock( MavenSession.class );
-
- this.projectBuildingRequest = mockManager.createMock( ProjectBuildingRequest.class );
-
archiver = mockManager.createMock( Archiver.class );
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
-
projectBuilder = mockManager.createMock( ProjectBuilder.class );
archiverManager = mockManager.createMock( ArchiverManager.class );
dependencyResolver = mockManager.createMock( DependencyResolver.class );
-
- enableDefaultExpectations();
- }
-
- private void enableDefaultExpectations()
- {
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( session.getProjectBuildingRequest() ).andReturn( projectBuildingRequest ).anyTimes();
- expect( session.getSystemProperties() ).andReturn( new Properties() ).anyTimes();
- expect( session.getUserProperties() ).andReturn( new Properties() ).anyTimes();
- expect( session.getExecutionProperties() ).andReturn( new Properties() ).anyTimes();
-
- expectGetSession( session );
}
public void expectAddArchivedFileSet()
@@ -191,28 +165,11 @@ public class MockAndControlForAddDependencySetsTask
}
}
- public void expectGetReactorProjects( final List<MavenProject> projects )
- {
- expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
- }
-
- public void expectCSGetFinalName( final String finalName )
- {
- expect( configSource.getFinalName() ).andReturn( finalName ).anyTimes();
- }
-
public void expectGetDestFile( final File destFile )
{
expect( archiver.getDestFile() ).andReturn( destFile ).anyTimes();
}
- public void expectCSGetRepositories( final ArtifactRepository localRepo,
- final List<ArtifactRepository> remoteRepos )
- {
- expect( configSource.getLocalRepository() ).andReturn( localRepo ).anyTimes();
- expect( configSource.getRemoteRepositories() ).andReturn( remoteRepos ).anyTimes();
- }
-
public void expectBuildFromRepository( final ProjectBuildingException error )
{
try
@@ -273,11 +230,6 @@ public class MockAndControlForAddDependencySetsTask
}
}
- public void expectGetSession( final MavenSession session )
- {
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
- }
-
public void expectResolveDependencySets()
throws DependencyResolutionException
{
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddFileSetsTask.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddFileSetsTask.java
index 3d4b573..1f3247d 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddFileSetsTask.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/testutils/MockAndControlForAddFileSetsTask.java
@@ -20,7 +20,6 @@ package org.apache.maven.plugins.assembly.archive.task.testutils;
*/
import junit.framework.Assert;
-import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
@@ -35,24 +34,13 @@ import static org.easymock.EasyMock.expect;
public class MockAndControlForAddFileSetsTask
{
-
- public final AssemblerConfigurationSource configSource;
-
public final Archiver archiver;
public File archiveBaseDir;
public MockAndControlForAddFileSetsTask( EasyMockSupport mockManager )
{
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
archiver = mockManager.createMock( Archiver.class );
-
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
- }
-
- public void expectGetArchiveBaseDirectory()
- {
- expect( configSource.getArchiveBaseDirectory() ).andReturn( archiveBaseDir ).anyTimes();
}
void expectModeChanges( int[] modes, int modeChangeCount )
@@ -87,16 +75,8 @@ public class MockAndControlForAddFileSetsTask
}
}
- public void expectAdditionOfSingleFileSet( MavenProject project, String finalName, boolean shouldAddDir,
- int[] modes, int modeChangeCount, boolean isDebugEnabled )
- {
- expectAdditionOfSingleFileSet( project, finalName, shouldAddDir, modes, modeChangeCount, isDebugEnabled, true );
-
- }
-
- public void expectAdditionOfSingleFileSet( MavenProject project, String finalName, boolean shouldAddDir,
- int[] modes, int modeChangeCount, boolean isDebugEnabled,
- boolean isProjectUsed )
+ public void expectAdditionOfSingleFileSet( MavenProject project, boolean shouldAddDir, int[] modes,
+ int modeChangeCount, boolean isDebugEnabled )
{
// the logger sends a debug message with this info inside the addFileSet(..) method..
if ( isDebugEnabled )
@@ -104,18 +84,11 @@ public class MockAndControlForAddFileSetsTask
expect( archiver.getOverrideDirectoryMode() ).andReturn( modes[0] );
expect( archiver.getOverrideFileMode() ).andReturn( modes[1] );
}
-
- if ( isProjectUsed )
- {
- expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
- }
-
- expect( configSource.getFinalName() ).andReturn( finalName ).atLeastOnce();
-
+
if ( shouldAddDir )
{
expectModeChanges( modes, modeChangeCount );
-
+
try
{
archiver.addFileSet( (FileSet) anyObject() );
@@ -129,14 +102,4 @@ public class MockAndControlForAddFileSetsTask
}
- public void expectGetProject( MavenProject project )
- {
- expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
- }
-
- public void expectGetFinalName( String finalName )
- {
- expect( configSource.getFinalName() ).andReturn( finalName ).atLeastOnce();
- }
-
}
[maven-assembly-plugin] 03/03: use mockito for setupInterpolators
Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch setupInterpolators
in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
commit 4d4e2175f8a05ec4a65684085de29278c700a1cf
Author: rfscholte <rf...@apache.org>
AuthorDate: Tue Apr 21 21:28:11 2020 +0200
use mockito for setupInterpolators
---
.../archive/DefaultAssemblyArchiverTest.java | 23 +-
.../archive/phase/FileSetAssemblyPhaseTest.java | 11 +-
.../archive/phase/ModuleSetAssemblyPhaseTest.java | 153 ++++--------
.../assembly/archive/task/AddArtifactTaskTest.java | 9 +-
.../archive/task/AddDependencySetsTaskTest.java | 36 ++-
.../assembly/archive/task/AddFileSetsTaskTest.java | 16 +-
.../assembly/io/DefaultAssemblyReaderTest.java | 259 +++------------------
.../assembly/utils/AssemblyFormatUtilsTest.java | 61 +----
8 files changed, 113 insertions(+), 455 deletions(-)
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java
index b92397b..93a7401 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/DefaultAssemblyArchiverTest.java
@@ -82,14 +82,10 @@ public class DefaultAssemblyArchiverTest
public static void setupInterpolators( AssemblerConfigurationSource configSource )
{
- expect( configSource.getRepositoryInterpolator() ).andReturn(
- FixedStringSearchInterpolator.create() ).anyTimes();
- expect( configSource.getCommandLinePropsInterpolator() ).andReturn(
- FixedStringSearchInterpolator.create() ).anyTimes();
- expect( configSource.getEnvInterpolator() ).andReturn( FixedStringSearchInterpolator.create() ).anyTimes();
- expect( configSource.getMainProjectInterpolator() ).andReturn(
- FixedStringSearchInterpolator.create() ).anyTimes();
-
+ when( configSource.getRepositoryInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
+ when( configSource.getCommandLinePropsInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
+ when( configSource.getEnvInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
+ when( configSource.getMainProjectInterpolator() ).thenReturn( FixedStringSearchInterpolator.create() );
}
public static void setupInterpolators( AssemblerConfigurationSource configSource, MavenProject mavenProject )
@@ -178,17 +174,6 @@ public class DefaultAssemblyArchiverTest
final Assembly assembly = new Assembly();
assembly.setId( "id" );
- // try
- // {
- // expect( macMgr.dependencyResolver.resolve( (Assembly) anyObject(), (AssemblerConfigurationSource)
- // anyObject() )).andReturn( new HashSet<Artifact>( ) );
-// macMgr.dependencyResolverControl.setMatcher( MockControl.ALWAYS_MATCHER );
- // }
- // catch ( final DependencyResolutionException e )
- // {
- // fail( "Should never happen" );
- // }
-
mm.replayAll();
final DefaultAssemblyArchiver subject = createSubject( macMgr, Collections.singletonList( phase ), null );
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java
index 03c1544..9b83f47 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/FileSetAssemblyPhaseTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.assembly.archive.phase;
*/
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.apache.maven.model.Model;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
@@ -76,10 +77,8 @@ public class FileSetAssemblyPhaseTest
final MockAndControlForLogger macLogger = new MockAndControlForLogger();
final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask( mm );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
- expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
+ when( configSource.getArchiveBaseDirectory() ).thenReturn( macTask.archiveBaseDir );
final MavenProject project = new MavenProject( new Model() );
@@ -91,8 +90,8 @@ public class FileSetAssemblyPhaseTest
final int[] modes = { -1, -1, dirMode, fileMode };
macTask.expectAdditionOfSingleFileSet( project, false, modes, 1, true );
- expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
index beefbb9..ddee59a 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhaseTest.java
@@ -132,18 +132,13 @@ public class ModuleSetAssemblyPhaseTest
public void testCreateFileSet_ShouldUseModuleDirOnlyWhenOutDirIsNull()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final Model model = new Model();
model.setArtifactId( "artifact" );
final MavenProject project = new MavenProject( model );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
- expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
+ when( configSource.getProject() ).thenReturn( project );
final FileSet fs = new FileSet();
@@ -162,35 +157,26 @@ public class ModuleSetAssemblyPhaseTest
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mm.replayAll();
-
final FileSet result =
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).createFileSet( fs, sources,
artifactProject,
configSource );
assertEquals( "artifact/", result.getOutputDirectory() );
-
- mm.verifyAll();
}
@Test
public void testCreateFileSet_ShouldPrependModuleDirWhenOutDirIsProvided()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final Model model = new Model();
model.setArtifactId( "artifact" );
final MavenProject project = new MavenProject( model );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
- expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
-
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
+ when( configSource.getProject() ).thenReturn( project );
+
final FileSet fs = new FileSet();
fs.setOutputDirectory( "out" );
@@ -209,30 +195,19 @@ public class ModuleSetAssemblyPhaseTest
artifactProject.setArtifact( artifact );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mm.replayAll();
-
final FileSet result =
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).createFileSet( fs, sources,
artifactProject,
configSource );
assertEquals( "artifact/out/", result.getOutputDirectory() );
-
- mm.verifyAll();
}
@Test
public void testCreateFileSet_ShouldAddExcludesForSubModulesWhenExcludeSubModDirsIsTrue()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( null ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
-
- expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
final FileSet fs = new FileSet();
@@ -255,16 +230,12 @@ public class ModuleSetAssemblyPhaseTest
project.setArtifact( artifact );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mm.replayAll();
-
final FileSet result =
createPhase( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ), null ).createFileSet( fs, sources, project,
configSource );
assertEquals( 1, result.getExcludes().size() );
assertEquals( "submodule/**", result.getExcludes().get( 0 ) );
-
- mm.verifyAll();
}
@Test
@@ -286,9 +257,8 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, project );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
+ when( configSource.getProject() ).thenReturn( project );
final MavenProject module = createProject( "group", "module", "version", project );
@@ -301,8 +271,8 @@ public class ModuleSetAssemblyPhaseTest
projects.add( module );
- expect( configSource.getReactorProjects() ).andReturn( projects ).atLeastOnce();
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ when( configSource.getReactorProjects() ).thenReturn( projects );
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectGetMode( 0777, 0777 );
@@ -390,17 +360,14 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm, null );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( null ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
Artifact artifact = mock( Artifact.class );
when( artifact.getClassifier() ).thenReturn( "test" );
final File artifactFile = temporaryFolder.newFile();
when( artifact.getFile() ).thenReturn( artifactFile );
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectGetMode( 0222, 0222 );
macTask.expectAddFile( artifactFile, "out/artifact",
@@ -490,15 +457,13 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( null ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
Artifact artifact = mock( Artifact.class );
final File artifactFile = temporaryFolder.newFile();
when( artifact.getFile() ).thenReturn( artifactFile );
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectAddFile( artifactFile, "out/artifact",
TypeConversionUtils.modeToInt( "777",
@@ -557,9 +522,7 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask( mm );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( null ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
Artifact artifact = mock( Artifact.class );
final File artifactFile = temporaryFolder.newFile();
@@ -568,7 +531,7 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject project = createProject( "group", "artifact", "version", null );
project.setArtifact( artifact );
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectGetMode( 0222, 0222 );
@@ -607,12 +570,10 @@ public class ModuleSetAssemblyPhaseTest
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask( mm );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
final MavenProject project = createProject( "group", "artifact", "version", null );
-
- expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
+ when( configSource.getProject() ).thenReturn( project );
project.setArtifact( mock( Artifact.class ) );
@@ -627,13 +588,13 @@ public class ModuleSetAssemblyPhaseTest
sources.addFileSet( fs );
- expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
+ when( configSource.getArchiveBaseDirectory() ).thenReturn( macTask.archiveBaseDir );
final int mode = TypeConversionUtils.modeToInt( "777", new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
final int[] modes = { -1, -1, mode, mode };
macTask.expectAdditionOfSingleFileSet( project, false, modes, 1, true );
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
mm.replayAll();
@@ -650,11 +611,9 @@ public class ModuleSetAssemblyPhaseTest
public void testGetModuleProjects_ShouldReturnNothingWhenReactorContainsOnlyCurrentProject()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final MavenProject project = createProject( "group", "artifact", "version", null );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -662,36 +621,29 @@ public class ModuleSetAssemblyPhaseTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
final List<MavenProject> projects = Collections.singletonList( project );
- expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
+ when( configSource.getReactorProjects() ).thenReturn( projects );
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
- mm.replayAll();
-
final Set<MavenProject> moduleProjects =
ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertTrue( moduleProjects.isEmpty() );
-
- mm.verifyAll();
}
@Test
public void testGetModuleProjects_ShouldReturnNothingWhenReactorContainsTwoSiblingProjects()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final MavenProject project = createProject( "group", "artifact", "version", null );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -699,8 +651,8 @@ public class ModuleSetAssemblyPhaseTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
final MavenProject project2 = createProject( "group", "artifact2", "version", null );
@@ -708,30 +660,24 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project );
projects.add( project2 );
- expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
+ when( configSource.getReactorProjects() ).thenReturn( projects );
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
- mm.replayAll();
-
final Set<MavenProject> moduleProjects =
ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertTrue( moduleProjects.isEmpty() );
-
- mm.verifyAll();
}
@Test
public void testGetModuleProjects_ShouldReturnModuleOfCurrentProject()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final MavenProject project = createProject( "group", "artifact", "version", null );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -739,9 +685,8 @@ public class ModuleSetAssemblyPhaseTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
final MavenProject project2 = createProject( "group", "artifact2", "version", project );
@@ -749,13 +694,11 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project );
projects.add( project2 );
- expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
+ when( configSource.getReactorProjects() ).thenReturn( projects );
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
- mm.replayAll();
-
final Set<MavenProject> moduleProjects =
ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
@@ -764,19 +707,15 @@ public class ModuleSetAssemblyPhaseTest
final MavenProject result = moduleProjects.iterator().next();
assertEquals( "artifact2", result.getArtifactId() );
-
- mm.verifyAll();
}
@Test
public void testGetModuleProjects_ShouldReturnDescendentModulesOfCurrentProject()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final MavenProject project = createProject( "group", "artifact", "version", null );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -784,9 +723,8 @@ public class ModuleSetAssemblyPhaseTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
final MavenProject project2 = createProject( "group", "artifact2", "version", project );
final MavenProject project3 = createProject( "group", "artifact3", "version", project2 );
@@ -796,13 +734,11 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project2 );
projects.add( project3 );
- expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
+ when( configSource.getReactorProjects() ).thenReturn( projects );
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
- mm.replayAll();
-
final Set<MavenProject> moduleProjects =
ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
@@ -813,19 +749,15 @@ public class ModuleSetAssemblyPhaseTest
check.add( project3 );
verifyResultIs( check, moduleProjects );
-
- mm.verifyAll();
}
@Test
public void testGetModuleProjects_ShouldExcludeModuleAndDescendentsTransitively()
throws Exception
{
- final EasyMockSupport mm = new EasyMockSupport();
-
final MavenProject project = createProject( "group", "artifact", "version", null );
- AssemblerConfigurationSource configSource = mm.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -833,9 +765,8 @@ public class ModuleSetAssemblyPhaseTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
Artifact artifact1 = mock( Artifact.class );
project.setArtifact( artifact1 );
@@ -862,21 +793,17 @@ public class ModuleSetAssemblyPhaseTest
projects.add( project2 );
projects.add( project3 );
- expect( configSource.getReactorProjects() ).andReturn( projects ).anyTimes();
+ when( configSource.getReactorProjects() ).thenReturn( projects );
final ModuleSet moduleSet = new ModuleSet();
moduleSet.setIncludeSubModules( true );
moduleSet.addExclude( "group:artifact2" );
- mm.replayAll();
-
final Set<MavenProject> moduleProjects =
ModuleSetAssemblyPhase.getModuleProjects( moduleSet, configSource, logger );
assertTrue( moduleProjects.isEmpty() );
-
- mm.verifyAll();
}
private void verifyResultIs( final List<MavenProject> check, final Set<MavenProject> moduleProjects )
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
index fa7d867..eaa2ef3 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddArtifactTaskTest.java
@@ -20,7 +20,6 @@ package org.apache.maven.plugins.assembly.archive.task;
*/
import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.expect;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.Assert.fail;
@@ -76,11 +75,9 @@ public class AddArtifactTaskTest
MavenProject mainProject = new MavenProject( model );
mac = new MockAndControlForAddArtifactTask( mockManager, mainProject );
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getProject() ).andReturn( mainProject ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
-
- expect( configSource.getFinalName() ).andReturn( "final-name" ).atLeastOnce();
+ configSource = mock( AssemblerConfigurationSource.class );
+ when( configSource.getProject() ).thenReturn( mainProject );
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
}
@Test
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
index 0c5ad4f..d25da20 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java
@@ -109,7 +109,7 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager, mainProject );
- AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -117,15 +117,11 @@ public class AddDependencySetsTaskTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( mainProject ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( mainProject );
+ when( configSource.getMavenSession() ).thenReturn( session );
macTask.expectBuildFromRepository( depProject );
- expect( configSource.getFinalName() ).andReturn( mainAid + "-" + mainVer ).anyTimes();
-
- expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
- expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
+ when( configSource.getFinalName() ).thenReturn( mainAid + "-" + mainVer );
macTask.expectGetDestFile( new File( "junk" ) );
macTask.expectAddFile( newFile, outDir + depAid + "-" + depVer + "." + depExt, 10 );
@@ -193,7 +189,7 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager, new MavenProject( new Model() ) );
- AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -201,9 +197,8 @@ public class AddDependencySetsTaskTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
final String aid = "test-dep";
final String version = "2.0-SNAPSHOT";
@@ -223,11 +218,9 @@ public class AddDependencySetsTaskTest
macTask.expectGetDestFile( destFile );
macTask.expectBuildFromRepository( pbe );
- expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
- expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
- expect( configSource.getFinalName() ).andReturn( "final-name" ).anyTimes();
- macTask.expectAddFile( file, "out/" + aid + "-" + version + "." + type );
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
+ macTask.expectAddFile( file, "out/" + aid + "-" + version + "." + type );
macTask.expectGetMode( 0222, 0222 );
final DependencySet ds = new DependencySet();
@@ -279,7 +272,7 @@ public class AddDependencySetsTaskTest
final MockAndControlForAddDependencySetsTask macTask =
new MockAndControlForAddDependencySetsTask( mockManager, new MavenProject( new Model() ) );
- AssemblerConfigurationSource configSource = mockManager.createMock( AssemblerConfigurationSource.class );
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
MavenSession session = mock( MavenSession.class );
when( session.getProjectBuildingRequest() ).thenReturn( mock( ProjectBuildingRequest.class ) );
@@ -287,9 +280,8 @@ public class AddDependencySetsTaskTest
when( session.getUserProperties() ).thenReturn( new Properties() );
when( session.getExecutionProperties() ).thenReturn( new Properties() );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( session ).anyTimes();
-
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getMavenSession() ).thenReturn( session );
Artifact artifact = mock( Artifact.class );
final File artifactFile = temporaryFolder.newFile();
@@ -305,9 +297,7 @@ public class AddDependencySetsTaskTest
}
macTask.expectGetDestFile( new File( "junk" ) );
- expect( configSource.getFinalName() ).andReturn( "final-name" ).anyTimes();
- expect( configSource.getLocalRepository() ).andReturn( null ).anyTimes();
- expect( configSource.getRemoteRepositories() ).andReturn( null ).anyTimes();
+ when( configSource.getFinalName() ).thenReturn( "final-name" );
final MavenProject depProject = new MavenProject( new Model() );
diff --git a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java
index 2d4d461..0826bf9 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/archive/task/AddFileSetsTaskTest.java
@@ -19,6 +19,9 @@ package org.apache.maven.plugins.assembly.archive.task;
* under the License.
*/
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.maven.model.Model;
import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugins.assembly.archive.ArchiveCreationException;
@@ -58,8 +61,7 @@ public class AddFileSetsTaskTest
mockManager = new EasyMockSupport();
macTask = new MockAndControlForAddFileSetsTask( mockManager );
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+ configSource = mock( AssemblerConfigurationSource.class );
}
@Test
@@ -146,9 +148,6 @@ public class AddFileSetsTaskTest
final int[] modes = { -1, -1, -1, -1 };
macTask.expectAdditionOfSingleFileSet( null, true, modes, 1, true );
- expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
-
-// macTask.expectGetProject( null );
final MavenProject project = new MavenProject( new Model() );
@@ -184,7 +183,6 @@ public class AddFileSetsTaskTest
final int[] modes = { -1, -1, -1, -1 };
macTask.expectAdditionOfSingleFileSet( null, true, modes, 1, true );
- expect( configSource.getFinalName() ).andReturn( null ).atLeastOnce();
//macTask.expectGetProject( null );
@@ -215,7 +213,7 @@ public class AddFileSetsTaskTest
final File archiveBaseDir = temporaryFolder.newFolder();
- expect( configSource.getFinalName() ).andReturn( "finalName" ).atLeastOnce();
+ when( configSource.getFinalName() ).thenReturn( "finalName" );
//macTask.expectGetProject( null );
@@ -242,7 +240,7 @@ public class AddFileSetsTaskTest
throws Exception
{
macTask.archiveBaseDir = new File( temporaryFolder.getRoot(), "archive");
- expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
+ when( configSource.getArchiveBaseDirectory() ).thenReturn( macTask.archiveBaseDir );
mockManager.replayAll();
@@ -267,7 +265,7 @@ public class AddFileSetsTaskTest
throws Exception
{
macTask.archiveBaseDir = temporaryFolder.newFile();
- expect( configSource.getArchiveBaseDirectory() ).andReturn( macTask.archiveBaseDir ).anyTimes();
+ when( configSource.getArchiveBaseDirectory() ).thenReturn( macTask.archiveBaseDir );
mockManager.replayAll();
diff --git a/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java b/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java
index f29e73d..5e3eefd 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/io/DefaultAssemblyReaderTest.java
@@ -19,10 +19,11 @@ package org.apache.maven.plugins.assembly.io;
* under the License.
*/
-import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileOutputStream;
@@ -61,7 +62,6 @@ import org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator;
import org.codehaus.plexus.interpolation.fixed.InterpolationState;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
-import org.easymock.classextension.EasyMockSupport;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -72,8 +72,6 @@ public class DefaultAssemblyReaderTest
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
- private EasyMockSupport mockManager;
-
private AssemblerConfigurationSource configSource;
public static StringReader writeToStringReader( Assembly assembly )
@@ -90,33 +88,23 @@ public class DefaultAssemblyReaderTest
@Before
public void setUp()
{
-// fileManager = new TestFileManager( "assembly-reader.test.", ".xml" );
- mockManager = new EasyMockSupport();
-
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
-
- ArtifactRepository localRepo = mockManager.createMock( ArtifactRepository.class );
+ configSource = mock( AssemblerConfigurationSource.class );
- expect( localRepo.getBasedir() ).andReturn( "/path/to/local/repo" ).anyTimes();
- expect( configSource.getLocalRepository() ).andReturn( localRepo ).anyTimes();
- expect( configSource.getRemoteRepositories() ).andReturn(
- Collections.<ArtifactRepository>emptyList() ).anyTimes();
- expect( configSource.getMavenSession() ).andReturn( null ).anyTimes();
+ ArtifactRepository localRepo = mock( ArtifactRepository.class );
+ when( localRepo.getBasedir() ).thenReturn( "/path/to/local/repo" );
+ when( configSource.getLocalRepository() ).thenReturn( localRepo );
+ when( configSource.getRemoteRepositories() ).thenReturn( Collections.<ArtifactRepository>emptyList() );
}
@Test
public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent()
throws Exception
{
- final File siteDir = File.createTempFile( "assembly-reader.", ".test" );
- siteDir.delete();
-
- expect( configSource.getSiteDirectory() ).andReturn( siteDir ).anyTimes();
+ final File siteDir = new File( temporaryFolder.getRoot(), "assembly-readertest" );
+ when( configSource.getSiteDirectory() ).thenReturn( siteDir );
final Assembly assembly = new Assembly();
- mockManager.replayAll();
-
try
{
new DefaultAssemblyReader().includeSiteInAssembly( assembly, configSource );
@@ -127,111 +115,25 @@ public class DefaultAssemblyReaderTest
{
// this should happen.
}
-
- mockManager.verifyAll();
}
- // @Test public void testReadComponent_ShouldReadComponentFromXml()
- // throws IOException, AssemblyReadException
- // {
- // Component component = new Component();
- //
- // FileSet fileSet = new FileSet();
- // fileSet.setDirectory( "/dir" );
- //
- // component.addFileSet( fileSet );
- //
- // StringWriter sw = new StringWriter();
- //
- // ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
- //
- // componentWriter.write( sw, component );
- //
- // Component result = new DefaultAssemblyReader().readComponent( new StringReader( sw.toString() ) );
- //
- // List<FileSet> fileSets = result.getFileSets();
- //
- // assertNotNull( fileSets );
- // assertEquals( 1, fileSets.size() );
- //
- // FileSet fs = (FileSet) fileSets.get( 0 );
- //
- // assertEquals( "/dir", fs.getDirectory() );
- // }
- //
- // @Test public void testGetComponentFromFile_ShouldReadComponent()
- // throws IOException, AssemblyReadException
- // {
- // Component component = new Component();
- //
- // FileSet fileSet = new FileSet();
- // fileSet.setDirectory( "/dir" );
- //
- // component.addFileSet( fileSet );
- //
- // File componentFile = fileManager.createTempFile();
- //
- // FileWriter writer = null;
- //
- // try
- // {
- // writer = new FileWriter( componentFile );
- //
- // ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
- //
- // componentWriter.write( writer, component );
- // }
- // finally
- // {
- // IOUtil.close( writer );
- // }
- //
- // File basedir = componentFile.getParentFile();
- // String filename = componentFile.getName();
- //
- // configSource.getBasedir();
- // configSourceControl.setReturnValue( basedir );
- //
- // mockManager.replayAll();
- //
- // Component result = new DefaultAssemblyReader().getComponentFromFile( filename, configSource );
- //
- // List<FileSet> fileSets = result.getFileSets();
- //
- // assertNotNull( fileSets );
- // assertEquals( 1, fileSets.size() );
- //
- // FileSet fs = (FileSet) fileSets.get( 0 );
- //
- // assertEquals( "/dir", fs.getDirectory() );
- //
- // mockManager.verifyAll();
- // }
-
@Test
public void testIncludeSiteInAssembly_ShouldAddSiteDirFileSetWhenDirExists()
throws Exception
{
final File siteDir = temporaryFolder.getRoot();
-
- expect( configSource.getSiteDirectory() ).andReturn( siteDir ).anyTimes();
+ when( configSource.getSiteDirectory() ).thenReturn( siteDir );
final Assembly assembly = new Assembly();
- mockManager.replayAll();
-
new DefaultAssemblyReader().includeSiteInAssembly( assembly, configSource );
final List<FileSet> fileSets = assembly.getFileSets();
-
assertNotNull( fileSets );
assertEquals( 1, fileSets.size() );
final FileSet fs = fileSets.get( 0 );
-
assertEquals( siteDir.getPath(), fs.getDirectory() );
-
- mockManager.verifyAll();
}
@Test
@@ -381,53 +283,6 @@ public class DefaultAssemblyReaderTest
assertEquals( Artifact.SCOPE_SYSTEM, depSets.get( 2 ).getScope() );
}
- // FIXME: Deep merging should take place...
- // public void
- // testMergeComponentWithAssembly_ShouldMergeOneFileSetToOneOfExistingTwo()
- // {
- // Assembly assembly = new Assembly();
- //
- // FileSet fs = new FileSet();
- // fs.setDirectory( "/dir" );
- // fs.addInclude( "**/test.txt" );
- //
- // assembly.addFileSet( fs );
- //
- // fs = new FileSet();
- // fs.setDirectory( "/other-dir" );
- // assembly.addFileSet( fs );
- //
- // fs = new FileSet();
- // fs.setDirectory( "/dir" );
- // fs.addInclude( "**/components.txt" );
- //
- // Component component = new Component();
- //
- // component.addFileSet( fs );
- //
- // new DefaultAssemblyReader().mergeComponentWithAssembly( component,
- // assembly );
- //
- // List<FileSet> fileSets = assembly.getFileSets();
- //
- // assertNotNull( fileSets );
- // assertEquals( 2, fileSets.size() );
- //
- // FileSet rfs1 = (FileSet) fileSets.get( 0 );
- // assertEquals( "/dir", rfs1.getDirectory() );
- //
- // List includes = rfs1.getIncludes();
- //
- // assertNotNull( includes );
- // assertEquals( 2, includes.size() );
- // assertTrue( includes.contains( "**/test.txt" ) );
- // assertTrue( includes.contains( "**/components.txt" ) );
- //
- // FileSet rfs2 = (FileSet) fileSets.get( 1 );
- // assertEquals( "/other-dir", rfs2.getDirectory() );
- //
- // }
-
@Test
public void testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo()
{
@@ -492,16 +347,14 @@ public class DefaultAssemblyReaderTest
final MavenProject project = new MavenProject();
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
+ when( configSource.getProject() ).thenReturn( project );
+ when( configSource.getBasedir() ).thenReturn( basedir );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
InterpolationState is = new InterpolationState();
ComponentXpp3Reader.ContentTransformer componentIp =
AssemblyInterpolator.componentInterpolator( FixedStringSearchInterpolator.create(), is,
new ConsoleLogger( Logger.LEVEL_DEBUG, "console" ) );
- mockManager.replayAll();
-
new DefaultAssemblyReader().mergeComponentsWithMainAssembly( assembly, null, configSource, componentIp );
final List<FileSet> fileSets = assembly.getFileSets();
@@ -512,8 +365,6 @@ public class DefaultAssemblyReaderTest
final FileSet fs = fileSets.get( 0 );
assertEquals( "/dir", fs.getDirectory() );
-
- mockManager.verifyAll();
}
@Test
@@ -526,8 +377,6 @@ public class DefaultAssemblyReaderTest
final Assembly result = doReadAssembly( assembly );
assertEquals( assembly.getId(), result.getId() );
-
- mockManager.verifyAll();
}
@Test
@@ -542,12 +391,10 @@ public class DefaultAssemblyReaderTest
final StringReader sr = writeToStringReader( assembly );
final File siteDir = temporaryFolder.newFolder( "site" );
-
- expect( configSource.getSiteDirectory() ).andReturn( siteDir ).anyTimes();
+ when( configSource.getSiteDirectory() ).thenReturn( siteDir );
final File basedir = temporaryFolder.getRoot();
-
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
+ when( configSource.getBasedir() ).thenReturn( basedir );
final Model model = new Model();
model.setGroupId( "group" );
@@ -555,13 +402,10 @@ public class DefaultAssemblyReaderTest
model.setVersion( "version" );
final MavenProject project = new MavenProject( model );
-
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ when( configSource.getProject() ).thenReturn( project );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mockManager.replayAll();
-
final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", null, configSource );
assertEquals( assembly.getId(), result.getId() );
@@ -571,8 +415,6 @@ public class DefaultAssemblyReaderTest
assertEquals( 1, fileSets.size() );
assertEquals( "/site", fileSets.get( 0 ).getOutputDirectory() );
-
- mockManager.verifyAll();
}
@Test
@@ -603,7 +445,7 @@ public class DefaultAssemblyReaderTest
final StringReader sr = writeToStringReader( assembly );
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
+ when( configSource.getBasedir() ).thenReturn( basedir );
final Model model = new Model();
model.setGroupId( "group" );
@@ -611,12 +453,10 @@ public class DefaultAssemblyReaderTest
model.setVersion( "version" );
final MavenProject project = new MavenProject( model );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ when( configSource.getProject() ).thenReturn( project );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mockManager.replayAll();
-
final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", null, configSource );
assertEquals( assembly.getId(), result.getId() );
@@ -626,8 +466,6 @@ public class DefaultAssemblyReaderTest
assertEquals( 1, fileSets.size() );
assertEquals( "/dir", fileSets.get( 0 ).getDirectory() );
-
- mockManager.verifyAll();
}
@Test
@@ -658,7 +496,7 @@ public class DefaultAssemblyReaderTest
final StringReader sr = writeToStringReader( assembly );
- expect( configSource.getBasedir() ).andReturn( basedir ).atLeastOnce();
+ when( configSource.getBasedir() ).thenReturn( basedir );
final Model model = new Model();
model.setGroupId( "group" );
@@ -667,12 +505,10 @@ public class DefaultAssemblyReaderTest
final MavenProject project = new MavenProject( model );
- expect( configSource.getProject() ).andReturn( project ).atLeastOnce();
+ when( configSource.getProject() ).thenReturn( project );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mockManager.replayAll();
-
final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", null, configSource );
assertEquals( assembly.getId(), result.getId() );
@@ -682,8 +518,6 @@ public class DefaultAssemblyReaderTest
assertEquals( 1, fileSets.size() );
assertEquals( "group-dir", fileSets.get( 0 ).getDirectory() );
-
- mockManager.verifyAll();
}
@Test
@@ -696,8 +530,6 @@ public class DefaultAssemblyReaderTest
final Assembly result = doReadAssembly( assembly );
assertEquals( "group-assembly", result.getId() );
-
- mockManager.verifyAll();
}
private Assembly doReadAssembly( Assembly assembly )
@@ -707,7 +539,7 @@ public class DefaultAssemblyReaderTest
final File basedir = temporaryFolder.getRoot();
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
+ when( configSource.getBasedir() ).thenReturn( basedir );
final Model model = new Model();
model.setGroupId( "group" );
@@ -716,12 +548,10 @@ public class DefaultAssemblyReaderTest
final MavenProject project = new MavenProject( model );
- expect( configSource.getProject() ).andReturn( project ).anyTimes();
+ when( configSource.getProject() ).thenReturn( project );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mockManager.replayAll();
-
return new DefaultAssemblyReader().readAssembly( sr, "testLocation", null, configSource );
}
@@ -741,9 +571,9 @@ public class DefaultAssemblyReaderTest
final File basedir = assemblyFile.getParentFile();
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
+ when( configSource.getBasedir() ).thenReturn( basedir );
- expect( configSource.getProject() ).andReturn( new MavenProject( new Model() ) ).anyTimes();
+ when( configSource.getProject() ).thenReturn( new MavenProject( new Model() ) );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
@@ -752,36 +582,23 @@ public class DefaultAssemblyReaderTest
new AssemblyXpp3Writer().write( writer, assembly );
}
- mockManager.replayAll();
-
final Assembly result = new DefaultAssemblyReader().getAssemblyFromDescriptorFile( assemblyFile, configSource );
assertEquals( assembly.getId(), result.getId() );
-
- mockManager.verifyAll();
}
@Test
public void testGetAssemblyForDescriptorReference_ShouldReadBinaryAssemblyRef()
throws Exception
{
- final File basedir = temporaryFolder.getRoot();
-
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
-
- expect( configSource.getProject() ).andReturn( new MavenProject( new Model() ) ).anyTimes();
-
- expect( configSource.isIgnoreMissingDescriptor() ).andReturn( false ).anyTimes();
-
+ when( configSource.getBasedir() ).thenReturn( temporaryFolder.getRoot() );
+ when( configSource.getProject() ).thenReturn( new MavenProject( new Model() ) );
+ when( configSource.isIgnoreMissingDescriptor() ).thenReturn( false );
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mockManager.replayAll();
-
final Assembly result = new DefaultAssemblyReader().getAssemblyForDescriptorReference( "bin", configSource );
assertEquals( "bin", result.getId() );
-
- mockManager.verifyAll();
}
@Test
@@ -1001,26 +818,16 @@ public class DefaultAssemblyReaderTest
final boolean ignoreMissing )
throws AssemblyReadException, InvalidAssemblerConfigurationException
{
- expect( configSource.getDescriptorReferences() ).andReturn( descriptorRefs );
-
- expect( configSource.getDescriptors() ).andReturn( descriptors );
-
- expect( configSource.getDescriptorSourceDirectory() ).andReturn( descriptorDir );
+ when( configSource.getDescriptorReferences() ).thenReturn( descriptorRefs );
+ when( configSource.getDescriptors() ).thenReturn( descriptors );
+ when( configSource.getDescriptorSourceDirectory() ).thenReturn( descriptorDir );
+ when( configSource.getBasedir() ).thenReturn( basedir );
+ when( configSource.getProject() ).thenReturn( new MavenProject( new Model() ) );
+ when( configSource.isIgnoreMissingDescriptor() ).thenReturn( ignoreMissing );
- expect( configSource.getBasedir() ).andReturn( basedir ).anyTimes();
-
- expect( configSource.getProject() ).andReturn( new MavenProject( new Model() ) ).anyTimes();
-
- expect( configSource.isIgnoreMissingDescriptor() ).andReturn( ignoreMissing ).anyTimes();
DefaultAssemblyArchiverTest.setupInterpolators( configSource );
- mockManager.replayAll();
-
- final List<Assembly> assemblies = new DefaultAssemblyReader().readAssemblies( configSource );
-
- mockManager.verifyAll();
-
- return assemblies;
+ return new DefaultAssemblyReader().readAssemblies( configSource );
}
}
diff --git a/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java b/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
index 8d72694..22307f2 100644
--- a/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
+++ b/src/test/java/org/apache/maven/plugins/assembly/utils/AssemblyFormatUtilsTest.java
@@ -1,8 +1,5 @@
package org.apache.maven.plugins.assembly.utils;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,6 +19,8 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
* under the License.
*/
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
@@ -30,7 +29,6 @@ import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
import org.apache.maven.plugins.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugins.assembly.model.Assembly;
import org.apache.maven.project.MavenProject;
-import org.easymock.classextension.EasyMockSupport;
import org.junit.Test;
import java.util.Properties;
@@ -40,13 +38,9 @@ import static org.mockito.Mockito.when;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.easymock.EasyMock.expect;
-
public class AssemblyFormatUtilsTest
{
- private final EasyMockSupport mockManager = new EasyMockSupport();
-
@Test
public void testFixRelativePathRefs_ShouldRemoveRelativeRefToCurrentDir()
throws Exception
@@ -347,12 +341,10 @@ public class AssemblyFormatUtilsTest
final MavenSession session = mock( MavenSession.class );
when( session.getUserProperties() ).thenReturn( new Properties() );
- final AssemblerConfigurationSource cs = mockManager.createMock( AssemblerConfigurationSource.class );
- expect( cs.getMavenSession() ).andReturn( session );
+ final AssemblerConfigurationSource cs = mock( AssemblerConfigurationSource.class );
+ when( cs.getMavenSession() ).thenReturn( session );
DefaultAssemblyArchiverTest.setupInterpolators( cs );
- mockManager.replayAll();
-
final String result =
AssemblyFormatUtils.evaluateFileNameMapping( "${artifact.artifactId}-${artifact.baseVersion}",
artifact, mainProject, null, cs,
@@ -360,11 +352,6 @@ public class AssemblyFormatUtilsTest
AssemblyFormatUtils.artifactProjectInterpolator( artifactProject ) );
assertEquals( "artifact-2-SNAPSHOT", result );
-
- mockManager.verifyAll();
-
- // clear out for next call.
- mockManager.resetAll();
}
@Test
@@ -798,21 +785,16 @@ public class AssemblyFormatUtilsTest
private void verifyDistroName( final String assemblyId, final String finalName, final boolean appendAssemblyId,
final String checkValue )
{
- final MockAndControlForGetDistroName mac = new MockAndControlForGetDistroName( finalName, appendAssemblyId );
-
- mockManager.replayAll();
+ AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
+ when( configSource.isAssemblyIdAppended() ).thenReturn( appendAssemblyId );
+ when( configSource.getFinalName() ).thenReturn( finalName );
final Assembly assembly = new Assembly();
assembly.setId( assemblyId );
- final String result = AssemblyFormatUtils.getDistributionName( assembly, mac.configSource );
+ final String result = AssemblyFormatUtils.getDistributionName( assembly, configSource );
assertEquals( checkValue, result );
-
- mockManager.verifyAll();
-
- // clear it out for the next call.
- mockManager.resetAll();
}
@Test
@@ -826,31 +808,4 @@ public class AssemblyFormatUtilsTest
{
assertTrue( AssemblyFormatUtils.isUnixRootReference( "/etc/home" ) );
}
-
- private final class MockAndControlForGetDistroName
- {
- final AssemblerConfigurationSource configSource;
-
- private final boolean isAssemblyIdAppended;
-
- private final String finalName;
-
- public MockAndControlForGetDistroName( final String finalName, final boolean isAssemblyIdAppended )
- {
- this.finalName = finalName;
- this.isAssemblyIdAppended = isAssemblyIdAppended;
-
- configSource = mockManager.createMock( AssemblerConfigurationSource.class );
-
- enableExpectations();
- }
-
- private void enableExpectations()
- {
- expect( configSource.isAssemblyIdAppended() ).andReturn( isAssemblyIdAppended ).atLeastOnce();
-
- expect( configSource.getFinalName() ).andReturn( finalName ).atLeastOnce();
- }
- }
-
}