You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2010/09/21 22:34:53 UTC
svn commit: r999612 [9/10] - in /maven/plugins/trunk/maven-assembly-plugin:
./ src/main/java/org/apache/maven/plugin/assembly/
src/main/java/org/apache/maven/plugin/assembly/archive/
src/main/java/org/apache/maven/plugin/assembly/archive/archiver/ src/...
Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java?rev=999612&r1=999611&r2=999612&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/io/DefaultAssemblyReaderTest.java Tue Sep 21 20:34:50 2010
@@ -19,20 +19,6 @@ package org.apache.maven.plugin.assembly
* under the License.
*/
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
@@ -53,6 +39,20 @@ import org.apache.maven.project.MavenPro
import org.codehaus.plexus.util.IOUtil;
import org.easymock.MockControl;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
public class DefaultAssemblyReaderTest
extends TestCase
{
@@ -65,6 +65,7 @@ public class DefaultAssemblyReaderTest
private AssemblerConfigurationSource configSource;
+ @Override
public void setUp()
{
fileManager = new TestFileManager( "assembly-reader.test.", ".xml" );
@@ -75,8 +76,8 @@ public class DefaultAssemblyReaderTest
configSource = (AssemblerConfigurationSource) configSourceControl.getMock();
- MockControl localRepoControl = MockControl.createControl( ArtifactRepository.class );
- ArtifactRepository localRepo = (ArtifactRepository) localRepoControl.getMock();
+ final MockControl localRepoControl = MockControl.createControl( ArtifactRepository.class );
+ final ArtifactRepository localRepo = (ArtifactRepository) localRepoControl.getMock();
mockManager.add( localRepoControl );
@@ -85,27 +86,26 @@ public class DefaultAssemblyReaderTest
configSource.getRemoteRepositories();
configSourceControl.setReturnValue( Collections.EMPTY_LIST, MockControl.ZERO_OR_MORE );
-
+
configSource.getMavenSession();
configSourceControl.setReturnValue( null, MockControl.ZERO_OR_MORE );
}
- public void tearDown()
- throws IOException
+ @Override
+ public void tearDown() throws IOException
{
fileManager.cleanUp();
}
- public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent()
- throws IOException
+ public void testIncludeSiteInAssembly_ShouldFailIfSiteDirectoryNonExistent() throws IOException
{
- File siteDir = File.createTempFile( "assembly-reader.", ".test" );
+ final File siteDir = File.createTempFile( "assembly-reader.", ".test" );
siteDir.delete();
configSource.getSiteDirectory();
configSourceControl.setReturnValue( siteDir, MockControl.ZERO_OR_MORE );
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
mockManager.replayAll();
@@ -115,7 +115,7 @@ public class DefaultAssemblyReaderTest
fail( "Should fail when site directory is non-existent." );
}
- catch ( InvalidAssemblerConfigurationException e )
+ catch ( final InvalidAssemblerConfigurationException e )
{
// this should happen.
}
@@ -126,109 +126,109 @@ public class DefaultAssemblyReaderTest
public void testIncludeSiteInAssembly_ShouldAddSiteDirFileSetWhenDirExists()
throws IOException, InvalidAssemblerConfigurationException
{
- File siteDir = fileManager.createTempDir();
+ final File siteDir = fileManager.createTempDir();
configSource.getSiteDirectory();
configSourceControl.setReturnValue( siteDir, MockControl.ZERO_OR_MORE );
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
mockManager.replayAll();
new DefaultAssemblyReader().includeSiteInAssembly( assembly, configSource );
- List fileSets = assembly.getFileSets();
+ final List<FileSet> fileSets = assembly.getFileSets();
assertNotNull( fileSets );
assertEquals( 1, fileSets.size() );
- FileSet fs = (FileSet) fileSets.get( 0 );
+ final FileSet fs = fileSets.get( 0 );
assertEquals( siteDir.getPath(), fs.getDirectory() );
mockManager.verifyAll();
}
-// 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 fileSets = result.getFileSets();
-//
-// assertNotNull( fileSets );
-// assertEquals( 1, fileSets.size() );
-//
-// FileSet fs = (FileSet) fileSets.get( 0 );
-//
-// assertEquals( "/dir", fs.getDirectory() );
-// }
-//
-// 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 fileSets = result.getFileSets();
-//
-// assertNotNull( fileSets );
-// assertEquals( 1, fileSets.size() );
-//
-// FileSet fs = (FileSet) fileSets.get( 0 );
-//
-// assertEquals( "/dir", fs.getDirectory() );
-//
-// mockManager.verifyAll();
-// }
+ // 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() );
+ // }
+ //
+ // 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();
+ // }
public void testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo()
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
FileSet fs = new FileSet();
fs.setDirectory( "/dir" );
@@ -242,31 +242,31 @@ public class DefaultAssemblyReaderTest
fs = new FileSet();
fs.setDirectory( "/third-dir" );
- Component component = new Component();
+ final Component component = new Component();
component.addFileSet( fs );
new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
- List fileSets = assembly.getFileSets();
+ final List<FileSet> fileSets = assembly.getFileSets();
assertNotNull( fileSets );
assertEquals( 3, fileSets.size() );
- FileSet rfs1 = (FileSet) fileSets.get( 0 );
+ final FileSet rfs1 = fileSets.get( 0 );
assertEquals( "/dir", rfs1.getDirectory() );
- FileSet rfs2 = (FileSet) fileSets.get( 1 );
+ final FileSet rfs2 = fileSets.get( 1 );
assertEquals( "/other-dir", rfs2.getDirectory() );
- FileSet rfs3 = (FileSet) fileSets.get( 2 );
+ final FileSet rfs3 = fileSets.get( 2 );
assertEquals( "/third-dir", rfs3.getDirectory() );
}
public void testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo()
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
FileItem fi = new FileItem();
fi.setSource( "file" );
@@ -281,31 +281,31 @@ public class DefaultAssemblyReaderTest
fi = new FileItem();
fi.setSource( "file3" );
- Component component = new Component();
+ final Component component = new Component();
component.addFile( fi );
new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
- List fileItems = assembly.getFiles();
+ final List<FileItem> fileItems = assembly.getFiles();
assertNotNull( fileItems );
assertEquals( 3, fileItems.size() );
- FileItem rf1 = (FileItem) fileItems.get( 0 );
+ final FileItem rf1 = fileItems.get( 0 );
assertEquals( "file", rf1.getSource() );
- FileItem rf2 = (FileItem) fileItems.get( 1 );
+ final FileItem rf2 = fileItems.get( 1 );
assertEquals( "file2", rf2.getSource() );
- FileItem rf3 = (FileItem) fileItems.get( 2 );
+ final FileItem rf3 = fileItems.get( 2 );
assertEquals( "file3", rf3.getSource() );
}
public void testMergeComponentWithAssembly_ShouldAddOneDependencySetToExistingListOfTwo()
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
DependencySet ds = new DependencySet();
ds.setScope( Artifact.SCOPE_RUNTIME );
@@ -317,7 +317,7 @@ public class DefaultAssemblyReaderTest
assembly.addDependencySet( ds );
- Component component = new Component();
+ final Component component = new Component();
ds = new DependencySet();
ds.setScope( Artifact.SCOPE_SYSTEM );
@@ -326,19 +326,22 @@ public class DefaultAssemblyReaderTest
new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
- List depSets = assembly.getDependencySets();
+ final List<DependencySet> depSets = assembly.getDependencySets();
assertNotNull( depSets );
assertEquals( 3, depSets.size() );
- assertEquals( Artifact.SCOPE_RUNTIME, ( (DependencySet) depSets.get( 0 ) ).getScope() );
- assertEquals( Artifact.SCOPE_COMPILE, ( (DependencySet) depSets.get( 1 ) ).getScope() );
- assertEquals( Artifact.SCOPE_SYSTEM, ( (DependencySet) depSets.get( 2 ) ).getScope() );
+ assertEquals( Artifact.SCOPE_RUNTIME, depSets.get( 0 )
+ .getScope() );
+ assertEquals( Artifact.SCOPE_COMPILE, depSets.get( 1 )
+ .getScope() );
+ assertEquals( Artifact.SCOPE_SYSTEM, depSets.get( 2 )
+ .getScope() );
}
public void testMergeComponentWithAssembly_ShouldAddOneRepositoryToExistingListOfTwo()
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
Repository repo = new Repository();
repo.setScope( Artifact.SCOPE_RUNTIME );
@@ -350,7 +353,7 @@ public class DefaultAssemblyReaderTest
assembly.addRepository( repo );
- Component component = new Component();
+ final Component component = new Component();
repo = new Repository();
repo.setScope( Artifact.SCOPE_SYSTEM );
@@ -359,19 +362,22 @@ public class DefaultAssemblyReaderTest
new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
- List depSets = assembly.getRepositories();
+ final List<Repository> depSets = assembly.getRepositories();
assertNotNull( depSets );
assertEquals( 3, depSets.size() );
- assertEquals( Artifact.SCOPE_RUNTIME, ( (Repository) depSets.get( 0 ) ).getScope() );
- assertEquals( Artifact.SCOPE_COMPILE, ( (Repository) depSets.get( 1 ) ).getScope() );
- assertEquals( Artifact.SCOPE_SYSTEM, ( (Repository) depSets.get( 2 ) ).getScope() );
+ assertEquals( Artifact.SCOPE_RUNTIME, depSets.get( 0 )
+ .getScope() );
+ assertEquals( Artifact.SCOPE_COMPILE, depSets.get( 1 )
+ .getScope() );
+ assertEquals( Artifact.SCOPE_SYSTEM, depSets.get( 2 )
+ .getScope() );
}
public void testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo()
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
ContainerDescriptorHandlerConfig cfg = new ContainerDescriptorHandlerConfig();
cfg.setHandlerName( "one" );
@@ -383,7 +389,7 @@ public class DefaultAssemblyReaderTest
assembly.addContainerDescriptorHandler( cfg );
- Component component = new Component();
+ final Component component = new Component();
cfg = new ContainerDescriptorHandlerConfig();
cfg.setHandlerName( "three" );
@@ -392,15 +398,18 @@ public class DefaultAssemblyReaderTest
new DefaultAssemblyReader().mergeComponentWithAssembly( component, assembly );
- List result = assembly.getContainerDescriptorHandlers();
+ final List<ContainerDescriptorHandlerConfig> result = assembly.getContainerDescriptorHandlers();
assertNotNull( result );
assertEquals( 3, result.size() );
- Iterator it = result.iterator();
- assertEquals( "one", ( (ContainerDescriptorHandlerConfig) it.next() ).getHandlerName() );
- assertEquals( "two", ( (ContainerDescriptorHandlerConfig) it.next() ).getHandlerName() );
- assertEquals( "three", ( (ContainerDescriptorHandlerConfig) it.next() ).getHandlerName() );
+ final Iterator<ContainerDescriptorHandlerConfig> it = result.iterator();
+ assertEquals( "one", it.next()
+ .getHandlerName() );
+ assertEquals( "two", it.next()
+ .getHandlerName() );
+ assertEquals( "three", it.next()
+ .getHandlerName() );
}
// FIXME: Deep merging should take place...
@@ -430,7 +439,7 @@ public class DefaultAssemblyReaderTest
// new DefaultAssemblyReader().mergeComponentWithAssembly( component,
// assembly );
//
- // List fileSets = assembly.getFileSets();
+ // List<FileSet> fileSets = assembly.getFileSets();
//
// assertNotNull( fileSets );
// assertEquals( 2, fileSets.size() );
@@ -453,14 +462,14 @@ public class DefaultAssemblyReaderTest
public void testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly()
throws IOException, AssemblyReadException
{
- Component component = new Component();
+ final Component component = new Component();
- FileSet fileSet = new FileSet();
+ final FileSet fileSet = new FileSet();
fileSet.setDirectory( "/dir" );
component.addFileSet( fileSet );
- File componentFile = fileManager.createTempFile();
+ final File componentFile = fileManager.createTempFile();
Writer writer = null;
@@ -468,7 +477,7 @@ public class DefaultAssemblyReaderTest
{
writer = new OutputStreamWriter( new FileOutputStream( componentFile ), "UTF-8" );
- ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
+ final ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
componentWriter.write( writer, component );
writer.flush();
@@ -478,19 +487,18 @@ public class DefaultAssemblyReaderTest
IOUtil.close( writer );
}
- String filename = componentFile.getName();
+ final String filename = componentFile.getName();
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.addComponentDescriptor( filename );
- File basedir = componentFile.getParentFile();
+ final File basedir = componentFile.getParentFile();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
-
-
- MavenProject project = new MavenProject();
-
+
+ final MavenProject project = new MavenProject();
+
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
@@ -498,12 +506,12 @@ public class DefaultAssemblyReaderTest
new DefaultAssemblyReader().mergeComponentsWithMainAssembly( assembly, configSource );
- List fileSets = assembly.getFileSets();
+ final List<FileSet> fileSets = assembly.getFileSets();
assertNotNull( fileSets );
assertEquals( 1, fileSets.size() );
- FileSet fs = (FileSet) fileSets.get( 0 );
+ final FileSet fs = fileSets.get( 0 );
assertEquals( "/dir", fs.getDirectory() );
@@ -513,27 +521,27 @@ public class DefaultAssemblyReaderTest
public void testReadAssembly_ShouldReadAssemblyWithoutComponentsInterpolationOrSiteDirInclusion()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
- StringWriter sw = new StringWriter();
- AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+ final StringWriter sw = new StringWriter();
+ final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
assemblyWriter.write( sw, assembly );
- StringReader sr = new StringReader( sw.toString() );
+ final StringReader sr = new StringReader( sw.toString() );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "version" );
- MavenProject project = new MavenProject( model );
+ final MavenProject project = new MavenProject( model );
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
@@ -543,9 +551,7 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().readAssembly( sr,
- "testLocation",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
assertEquals( assembly.getId(), result.getId() );
@@ -555,34 +561,34 @@ public class DefaultAssemblyReaderTest
public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
assembly.setIncludeSiteDirectory( true );
- StringWriter sw = new StringWriter();
- AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+ final StringWriter sw = new StringWriter();
+ final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
assemblyWriter.write( sw, assembly );
- StringReader sr = new StringReader( sw.toString() );
+ final StringReader sr = new StringReader( sw.toString() );
- File siteDir = fileManager.createTempDir();
+ final File siteDir = fileManager.createTempDir();
configSource.getSiteDirectory();
configSourceControl.setReturnValue( siteDir, MockControl.ZERO_OR_MORE );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "version" );
- MavenProject project = new MavenProject( model );
+ final MavenProject project = new MavenProject( model );
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
@@ -592,17 +598,16 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().readAssembly( sr,
- "testLocation",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
assertEquals( assembly.getId(), result.getId() );
- List fileSets = result.getFileSets();
+ final List<FileSet> fileSets = result.getFileSets();
assertEquals( 1, fileSets.size() );
- assertEquals( "/site", ( (FileSet) fileSets.get( 0 ) ).getOutputDirectory() );
+ assertEquals( "/site", fileSets.get( 0 )
+ .getOutputDirectory() );
mockManager.verifyAll();
}
@@ -610,32 +615,32 @@ public class DefaultAssemblyReaderTest
public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromConfigWithoutComponentsOrInterpolation()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
- StringWriter sw = new StringWriter();
- AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+ final StringWriter sw = new StringWriter();
+ final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
assemblyWriter.write( sw, assembly );
- StringReader sr = new StringReader( sw.toString() );
+ final StringReader sr = new StringReader( sw.toString() );
- File siteDir = fileManager.createTempDir();
+ final File siteDir = fileManager.createTempDir();
configSource.getSiteDirectory();
configSourceControl.setReturnValue( siteDir, MockControl.ZERO_OR_MORE );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "version" );
- MavenProject project = new MavenProject( model );
+ final MavenProject project = new MavenProject( model );
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
@@ -645,17 +650,16 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().readAssembly( sr,
- "testLocation",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
assertEquals( assembly.getId(), result.getId() );
- List fileSets = result.getFileSets();
+ final List<FileSet> fileSets = result.getFileSets();
assertEquals( 1, fileSets.size() );
- assertEquals( "/site", ( (FileSet) fileSets.get( 0 ) ).getOutputDirectory() );
+ assertEquals( "/site", fileSets.get( 0 )
+ .getOutputDirectory() );
mockManager.verifyAll();
}
@@ -663,14 +667,14 @@ public class DefaultAssemblyReaderTest
public void testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- File componentsFile = fileManager.createTempFile();
+ final File componentsFile = fileManager.createTempFile();
- File basedir = componentsFile.getParentFile();
- String componentsFilename = componentsFile.getName();
+ final File basedir = componentsFile.getParentFile();
+ final String componentsFilename = componentsFile.getName();
- Component component = new Component();
+ final Component component = new Component();
- FileSet fs = new FileSet();
+ final FileSet fs = new FileSet();
fs.setDirectory( "/dir" );
component.addFileSet( fs );
@@ -687,27 +691,27 @@ public class DefaultAssemblyReaderTest
IOUtil.close( fw );
}
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
assembly.addComponentDescriptor( componentsFilename );
- StringWriter sw = new StringWriter();
- AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+ final StringWriter sw = new StringWriter();
+ final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
assemblyWriter.write( sw, assembly );
- StringReader sr = new StringReader( sw.toString() );
+ final StringReader sr = new StringReader( sw.toString() );
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "version" );
- MavenProject project = new MavenProject( model );
+ final MavenProject project = new MavenProject( model );
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
@@ -716,17 +720,16 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().readAssembly( sr,
- "testLocation",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
assertEquals( assembly.getId(), result.getId() );
- List fileSets = result.getFileSets();
+ final List<FileSet> fileSets = result.getFileSets();
assertEquals( 1, fileSets.size() );
- assertEquals( "/dir", ( (FileSet) fileSets.get( 0 ) ).getDirectory() );
+ assertEquals( "/dir", fileSets.get( 0 )
+ .getDirectory() );
mockManager.verifyAll();
}
@@ -734,14 +737,14 @@ public class DefaultAssemblyReaderTest
public void testReadAssembly_ShouldReadAssemblyWithComponentInterpolationWithoutSiteDirInclusionOrAssemblyInterpolation()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- File componentsFile = fileManager.createTempFile();
+ final File componentsFile = fileManager.createTempFile();
- File basedir = componentsFile.getParentFile();
- String componentsFilename = componentsFile.getName();
+ final File basedir = componentsFile.getParentFile();
+ final String componentsFilename = componentsFile.getName();
- Component component = new Component();
+ final Component component = new Component();
- FileSet fs = new FileSet();
+ final FileSet fs = new FileSet();
fs.setDirectory( "${groupId}-dir" );
component.addFileSet( fs );
@@ -758,27 +761,27 @@ public class DefaultAssemblyReaderTest
IOUtil.close( fw );
}
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
assembly.addComponentDescriptor( componentsFilename );
- StringWriter sw = new StringWriter();
- AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+ final StringWriter sw = new StringWriter();
+ final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
assemblyWriter.write( sw, assembly );
- StringReader sr = new StringReader( sw.toString() );
+ final StringReader sr = new StringReader( sw.toString() );
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ONE_OR_MORE );
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "version" );
- MavenProject project = new MavenProject( model );
+ final MavenProject project = new MavenProject( model );
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ONE_OR_MORE );
@@ -788,17 +791,16 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().readAssembly( sr,
- "testLocation",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
assertEquals( assembly.getId(), result.getId() );
- List fileSets = result.getFileSets();
+ final List<FileSet> fileSets = result.getFileSets();
assertEquals( 1, fileSets.size() );
- assertEquals( "group-dir", ( (FileSet) fileSets.get( 0 ) ).getDirectory() );
+ assertEquals( "group-dir", fileSets.get( 0 )
+ .getDirectory() );
mockManager.verifyAll();
}
@@ -806,27 +808,27 @@ public class DefaultAssemblyReaderTest
public void testReadAssembly_ShouldReadAssemblyWithInterpolationWithoutComponentsOrSiteDirInclusion()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "${groupId}-assembly" );
- StringWriter sw = new StringWriter();
- AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
+ final StringWriter sw = new StringWriter();
+ final AssemblyXpp3Writer assemblyWriter = new AssemblyXpp3Writer();
assemblyWriter.write( sw, assembly );
- StringReader sr = new StringReader( sw.toString() );
+ final StringReader sr = new StringReader( sw.toString() );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "version" );
- MavenProject project = new MavenProject( model );
+ final MavenProject project = new MavenProject( model );
configSource.getProject();
configSourceControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
@@ -836,9 +838,7 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().readAssembly( sr,
- "testLocation",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().readAssembly( sr, "testLocation", configSource );
assertEquals( "group-assembly", result.getId() );
@@ -848,24 +848,23 @@ public class DefaultAssemblyReaderTest
public void testGetAssemblyFromDescriptorFile_ShouldReadAssembly()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
- FileSet fs = new FileSet();
+ final FileSet fs = new FileSet();
fs.setDirectory( "/dir" );
assembly.addFileSet( fs );
- File assemblyFile = fileManager.createTempFile();
+ final File assemblyFile = fileManager.createTempFile();
- File basedir = assemblyFile.getParentFile();
+ final File basedir = assemblyFile.getParentFile();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
configSource.getProject();
- configSourceControl.setReturnValue( new MavenProject( new Model() ),
- MockControl.ZERO_OR_MORE );
+ configSourceControl.setReturnValue( new MavenProject( new Model() ), MockControl.ZERO_OR_MORE );
configSource.isSiteIncluded();
configSourceControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
@@ -883,8 +882,7 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().getAssemblyFromDescriptorFile( assemblyFile,
- configSource );
+ final Assembly result = new DefaultAssemblyReader().getAssemblyFromDescriptorFile( assemblyFile, configSource );
assertEquals( assembly.getId(), result.getId() );
@@ -894,25 +892,23 @@ public class DefaultAssemblyReaderTest
public void testGetAssemblyForDescriptorReference_ShouldReadBinaryAssemblyRef()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
configSource.getBasedir();
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
configSource.getProject();
- configSourceControl.setReturnValue( new MavenProject( new Model() ),
- MockControl.ZERO_OR_MORE );
+ configSourceControl.setReturnValue( new MavenProject( new Model() ), MockControl.ZERO_OR_MORE );
configSource.isSiteIncluded();
configSourceControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
-
+
configSource.isIgnoreMissingDescriptor();
configSourceControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
mockManager.replayAll();
- Assembly result = new DefaultAssemblyReader().getAssemblyForDescriptorReference( "bin",
- configSource );
+ final Assembly result = new DefaultAssemblyReader().getAssemblyForDescriptorReference( "bin", configSource );
assertEquals( "bin", result.getId() );
@@ -922,26 +918,26 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldGetAssemblyDescriptorFromSingleFile()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly = new Assembly();
+ final Assembly assembly = new Assembly();
assembly.setId( "test" );
- FileSet fs = new FileSet();
+ final FileSet fs = new FileSet();
fs.setDirectory( "/dir" );
assembly.addFileSet( fs );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
- List files = writeAssembliesToFile( Collections.singletonList( assembly ), basedir );
+ final List<String> files = writeAssembliesToFile( Collections.singletonList( assembly ), basedir );
- String assemblyFile = (String) files.get( 0 );
+ final String assemblyFile = files.get( 0 );
- List assemblies = performReadAssemblies( basedir, assemblyFile, null, null, null, null );
+ final List<Assembly> assemblies = performReadAssemblies( basedir, assemblyFile, null, null, null, null );
assertNotNull( assemblies );
assertEquals( 1, assemblies.size() );
- Assembly result = (Assembly) assemblies.get( 0 );
+ final Assembly result = assemblies.get( 0 );
assertEquals( assembly.getId(), result.getId() );
}
@@ -949,24 +945,18 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldFailWhenSingleDescriptorFileMissing()
throws IOException, InvalidAssemblerConfigurationException
{
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
- File assemblyFile = new File( basedir, "test.xml" );
+ final File assemblyFile = new File( basedir, "test.xml" );
assemblyFile.delete();
try
{
- performReadAssemblies( basedir,
- assemblyFile.getAbsolutePath(),
- null,
- null,
- null,
- null,
- false );
+ performReadAssemblies( basedir, assemblyFile.getAbsolutePath(), null, null, null, null, false );
fail( "Should fail when descriptor file is missing and ignoreDescriptors == false" );
}
- catch ( AssemblyReadException e )
+ catch ( final AssemblyReadException e )
{
// expected.
}
@@ -975,22 +965,16 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldIgnoreMissingSingleDescriptorFileWhenIgnoreIsConfigured()
throws IOException, InvalidAssemblerConfigurationException
{
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
- File assemblyFile = new File( basedir, "test.xml" );
+ final File assemblyFile = new File( basedir, "test.xml" );
assemblyFile.delete();
try
{
- performReadAssemblies( basedir,
- assemblyFile.getAbsolutePath(),
- null,
- null,
- null,
- null,
- true );
+ performReadAssemblies( basedir, assemblyFile.getAbsolutePath(), null, null, null, null, true );
}
- catch ( AssemblyReadException e )
+ catch ( final AssemblyReadException e )
{
e.printStackTrace();
fail( "Setting ignoreMissingDescriptor == true (true flag in performReadAssemblies, above) should NOT produce an exception." );
@@ -1000,14 +984,14 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldGetAssemblyDescriptorFromSingleRef()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
- List assemblies = performReadAssemblies( basedir, null, "bin", null, null, null );
+ final List<Assembly> assemblies = performReadAssemblies( basedir, null, "bin", null, null, null );
assertNotNull( assemblies );
assertEquals( 1, assemblies.size() );
- Assembly result = (Assembly) assemblies.get( 0 );
+ final Assembly result = assemblies.get( 0 );
assertEquals( "bin", result.getId() );
}
@@ -1015,35 +999,31 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldGetAssemblyDescriptorFromFileArray()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly1 = new Assembly();
+ final Assembly assembly1 = new Assembly();
assembly1.setId( "test" );
- Assembly assembly2 = new Assembly();
+ final Assembly assembly2 = new Assembly();
assembly2.setId( "test2" );
- List assemblies = new ArrayList();
+ final List<Assembly> assemblies = new ArrayList<Assembly>();
assemblies.add( assembly1 );
assemblies.add( assembly2 );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
- List files = writeAssembliesToFile( assemblies, basedir );
+ final List<String> files = writeAssembliesToFile( assemblies, basedir );
- List results = performReadAssemblies( basedir,
- null,
- null,
- (String[]) files.toArray( new String[0] ),
- null,
- null );
+ final List<Assembly> results =
+ performReadAssemblies( basedir, null, null, files.toArray( new String[0] ), null, null );
assertNotNull( results );
assertEquals( 2, results.size() );
- Assembly result1 = (Assembly) assemblies.get( 0 );
+ final Assembly result1 = assemblies.get( 0 );
assertEquals( assembly1.getId(), result1.getId() );
- Assembly result2 = (Assembly) assemblies.get( 1 );
+ final Assembly result2 = assemblies.get( 1 );
assertEquals( assembly2.getId(), result2.getId() );
}
@@ -1051,21 +1031,19 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldGetAssemblyDescriptorFromMultipleRefs()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
- List assemblies = performReadAssemblies( basedir, null, null, null, new String[] {
- "bin",
- "src"
- }, null );
+ final List<Assembly> assemblies =
+ performReadAssemblies( basedir, null, null, null, new String[] { "bin", "src" }, null );
assertNotNull( assemblies );
assertEquals( 2, assemblies.size() );
- Assembly result = (Assembly) assemblies.get( 0 );
+ final Assembly result = assemblies.get( 0 );
assertEquals( "bin", result.getId() );
- Assembly result2 = (Assembly) assemblies.get( 1 );
+ final Assembly result2 = assemblies.get( 1 );
assertEquals( "src", result2.getId() );
}
@@ -1073,30 +1051,30 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldGetAssemblyDescriptorFromDirectory()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly1 = new Assembly();
+ final Assembly assembly1 = new Assembly();
assembly1.setId( "test" );
- Assembly assembly2 = new Assembly();
+ final Assembly assembly2 = new Assembly();
assembly2.setId( "test2" );
- List assemblies = new ArrayList();
+ final List<Assembly> assemblies = new ArrayList<Assembly>();
assemblies.add( assembly1 );
assemblies.add( assembly2 );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
writeAssembliesToFile( assemblies, basedir );
- List results = performReadAssemblies( basedir, null, null, null, null, basedir );
+ final List<Assembly> results = performReadAssemblies( basedir, null, null, null, null, basedir );
assertNotNull( results );
assertEquals( 2, results.size() );
- Assembly result1 = (Assembly) assemblies.get( 0 );
+ final Assembly result1 = assemblies.get( 0 );
assertEquals( assembly1.getId(), result1.getId() );
- Assembly result2 = (Assembly) assemblies.get( 1 );
+ final Assembly result2 = assemblies.get( 1 );
assertEquals( assembly2.getId(), result2.getId() );
}
@@ -1104,49 +1082,45 @@ public class DefaultAssemblyReaderTest
public void testReadAssemblies_ShouldGetTwoAssemblyDescriptorsFromDirectoryWithThreeFiles()
throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException
{
- Assembly assembly1 = new Assembly();
+ final Assembly assembly1 = new Assembly();
assembly1.setId( "test" );
- Assembly assembly2 = new Assembly();
+ final Assembly assembly2 = new Assembly();
assembly2.setId( "test2" );
- List assemblies = new ArrayList();
+ final List<Assembly> assemblies = new ArrayList<Assembly>();
assemblies.add( assembly1 );
assemblies.add( assembly2 );
- File basedir = fileManager.createTempDir();
+ final File basedir = fileManager.createTempDir();
writeAssembliesToFile( assemblies, basedir );
- fileManager.createFile( basedir,
- "readme.txt",
- "This is just a readme file, not a descriptor." );
+ fileManager.createFile( basedir, "readme.txt", "This is just a readme file, not a descriptor." );
- List results = performReadAssemblies( basedir, null, null, null, null, basedir );
+ final List<Assembly> results = performReadAssemblies( basedir, null, null, null, null, basedir );
assertNotNull( results );
assertEquals( 2, results.size() );
- Assembly result1 = (Assembly) assemblies.get( 0 );
+ final Assembly result1 = assemblies.get( 0 );
assertEquals( assembly1.getId(), result1.getId() );
- Assembly result2 = (Assembly) assemblies.get( 1 );
+ final Assembly result2 = assemblies.get( 1 );
assertEquals( assembly2.getId(), result2.getId() );
}
- private List writeAssembliesToFile( List assemblies,
- File dir )
- throws IOException
+ private List<String> writeAssembliesToFile( final List<Assembly> assemblies, final File dir ) throws IOException
{
- List files = new ArrayList();
+ final List<String> files = new ArrayList<String>();
- for ( Iterator it = assemblies.iterator(); it.hasNext(); )
+ for ( final Iterator<Assembly> it = assemblies.iterator(); it.hasNext(); )
{
- Assembly assembly = (Assembly) it.next();
+ final Assembly assembly = it.next();
- File assemblyFile = new File( dir, assembly.getId() + ".xml" );
+ final File assemblyFile = new File( dir, assembly.getId() + ".xml" );
Writer writer = null;
try
@@ -1165,30 +1139,19 @@ public class DefaultAssemblyReaderTest
return files;
}
- private List performReadAssemblies( File basedir,
- String descriptor,
- String descriptorRef,
- String[] descriptors,
- String[] descriptorRefs,
- File descriptorDir )
+ private List<Assembly> performReadAssemblies( final File basedir, final String descriptor,
+ final String descriptorRef, final String[] descriptors,
+ final String[] descriptorRefs, final File descriptorDir )
throws AssemblyReadException, InvalidAssemblerConfigurationException
{
- return performReadAssemblies( basedir,
- descriptor,
- descriptorRef,
- descriptors,
- descriptorRefs,
- descriptorDir,
+ return performReadAssemblies( basedir, descriptor, descriptorRef, descriptors, descriptorRefs, descriptorDir,
false );
}
- private List performReadAssemblies( File basedir,
- String descriptor,
- String descriptorRef,
- String[] descriptors,
- String[] descriptorRefs,
- File descriptorDir,
- boolean ignoreMissing )
+ private List<Assembly> performReadAssemblies( final File basedir, final String descriptor,
+ final String descriptorRef, final String[] descriptors,
+ final String[] descriptorRefs, final File descriptorDir,
+ final boolean ignoreMissing )
throws AssemblyReadException, InvalidAssemblerConfigurationException
{
configSource.getDescriptor();
@@ -1210,8 +1173,7 @@ public class DefaultAssemblyReaderTest
configSourceControl.setReturnValue( basedir, MockControl.ZERO_OR_MORE );
configSource.getProject();
- configSourceControl.setReturnValue( new MavenProject( new Model() ),
- MockControl.ZERO_OR_MORE );
+ configSourceControl.setReturnValue( new MavenProject( new Model() ), MockControl.ZERO_OR_MORE );
configSource.isSiteIncluded();
configSourceControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
@@ -1221,7 +1183,7 @@ public class DefaultAssemblyReaderTest
mockManager.replayAll();
- List assemblies = new DefaultAssemblyReader().readAssemblies( configSource );
+ final List<Assembly> assemblies = new DefaultAssemblyReader().readAssemblies( configSource );
mockManager.verifyAll();
Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/ConfigSourceStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/ConfigSourceStub.java?rev=999612&r1=999611&r2=999612&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/ConfigSourceStub.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/ConfigSourceStub.java Tue Sep 21 20:34:50 2010
@@ -1,8 +1,5 @@
package org.apache.maven.plugin.assembly.testutils;
-import java.io.File;
-import java.util.List;
-
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
@@ -10,11 +7,15 @@ import org.apache.maven.plugin.assembly.
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.filtering.MavenFileFilter;
+import java.io.File;
+import java.util.List;
+
public class ConfigSourceStub
implements AssemblerConfigurationSource
{
private String archiverConfig;
+
private MavenProject project;
public File getArchiveBaseDirectory()
@@ -57,7 +58,7 @@ public class ConfigSourceStub
return null;
}
- public List getFilters()
+ public List<String> getFilters()
{
return null;
}
@@ -92,12 +93,12 @@ public class ConfigSourceStub
return project;
}
- public List getReactorProjects()
+ public List<MavenProject> getReactorProjects()
{
return null;
}
- public List getRemoteRepositories()
+ public List<ArtifactRepository> getRemoteRepositories()
{
return null;
}
@@ -146,8 +147,8 @@ public class ConfigSourceStub
{
return false;
}
-
- public void setArchiverConfig( String archiverConfig )
+
+ public void setArchiverConfig( final String archiverConfig )
{
this.archiverConfig = archiverConfig;
}
@@ -157,13 +158,14 @@ public class ConfigSourceStub
return archiverConfig;
}
- public MavenFileFilter getMavenFileFilter() {
+ public MavenFileFilter getMavenFileFilter()
+ {
return null;
}
- public void setProject( MavenProject mavenProject )
+ public void setProject( final MavenProject mavenProject )
{
- this.project = mavenProject;
+ project = mavenProject;
}
}
Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/MockManager.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/MockManager.java?rev=999612&r1=999611&r2=999612&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/MockManager.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/MockManager.java Tue Sep 21 20:34:50 2010
@@ -19,18 +19,20 @@ package org.apache.maven.plugin.assembly
* under the License.
*/
+import org.easymock.MockControl;
+
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import org.easymock.MockControl;
+import junit.framework.AssertionFailedError;
public class MockManager
{
- private Set mockControls = new HashSet();
+ private final Set<MockControl> mockControls = new HashSet<MockControl>();
- public void add( MockControl control )
+ public void add( final MockControl control )
{
mockControls.add( control );
}
@@ -42,9 +44,9 @@ public class MockManager
public void replayAll()
{
- for ( Iterator it = mockControls.iterator(); it.hasNext(); )
+ for ( final Iterator<MockControl> it = mockControls.iterator(); it.hasNext(); )
{
- MockControl control = (MockControl) it.next();
+ final MockControl control = it.next();
control.replay();
}
@@ -52,11 +54,23 @@ public class MockManager
public void verifyAll()
{
- for ( Iterator it = mockControls.iterator(); it.hasNext(); )
+ for ( final Iterator<MockControl> it = mockControls.iterator(); it.hasNext(); )
{
- MockControl control = (MockControl) it.next();
+ final MockControl control = it.next();
+
+ try
+ {
+ control.verify();
+ }
+ catch ( final AssertionFailedError err )
+ {
+ final String message =
+ "MockControl: " + control + " of: " + control.getMock() + " failed.\n" + err.getMessage();
+ final AssertionFailedError e = new AssertionFailedError( message );
+ e.initCause( err );
- control.verify();
+ throw e;
+ }
}
}
Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java?rev=999612&r1=999611&r2=999612&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/testutils/TestFileManager.java Tue Sep 21 20:34:50 2010
@@ -37,7 +37,7 @@ public class TestFileManager
public static final String TEMP_DIR_PATH = System.getProperty( "java.io.tmpdir" );
- private List filesToDelete = new ArrayList();
+ private final List<File> filesToDelete = new ArrayList<File>();
private final String baseFilename;
@@ -49,7 +49,7 @@ public class TestFileManager
private boolean warnAboutCleanup = false;
- public TestFileManager( String baseFilename, String fileSuffix )
+ public TestFileManager( final String baseFilename, final String fileSuffix )
{
this.baseFilename = baseFilename;
this.fileSuffix = fileSuffix;
@@ -61,7 +61,7 @@ public class TestFileManager
{
callerInfo = new NullPointerException().getStackTrace()[2];
- Runnable warning = new Runnable()
+ final Runnable warning = new Runnable()
{
public void run()
@@ -73,7 +73,8 @@ public class TestFileManager
cleanupWarning = new Thread( warning );
- Runtime.getRuntime().addShutdownHook( cleanupWarning );
+ Runtime.getRuntime()
+ .addShutdownHook( cleanupWarning );
}
private void maybeWarnAboutCleanUp()
@@ -84,7 +85,7 @@ public class TestFileManager
}
}
- public void markForDeletion( File toDelete )
+ public void markForDeletion( final File toDelete )
{
filesToDelete.add( toDelete );
warnAboutCleanup = true;
@@ -96,11 +97,11 @@ public class TestFileManager
{
Thread.sleep( 20 );
}
- catch ( InterruptedException e )
+ catch ( final InterruptedException e )
{
}
- File dir = new File( TEMP_DIR_PATH, baseFilename + System.currentTimeMillis() );
+ final File dir = new File( TEMP_DIR_PATH, baseFilename + System.currentTimeMillis() );
dir.mkdirs();
markForDeletion( dir );
@@ -108,10 +109,9 @@ public class TestFileManager
return dir;
}
- public synchronized File createTempFile()
- throws IOException
+ public synchronized File createTempFile() throws IOException
{
- File tempFile = File.createTempFile( baseFilename, fileSuffix );
+ final File tempFile = File.createTempFile( baseFilename, fileSuffix );
tempFile.deleteOnExit();
markForDeletion( tempFile );
@@ -120,9 +120,9 @@ public class TestFileManager
public void cleanUp()
{
- for ( Iterator it = filesToDelete.iterator(); it.hasNext(); )
+ for ( final Iterator<File> it = filesToDelete.iterator(); it.hasNext(); )
{
- File file = ( File ) it.next();
+ final File file = it.next();
if ( file.exists() )
{
@@ -130,7 +130,7 @@ public class TestFileManager
{
FileUtils.forceDelete( file );
}
- catch ( Exception e )
+ catch ( final Exception e )
{
System.err.println( "Error while deleting test file/dir: " + file + "; ignoring." );
}
@@ -142,9 +142,9 @@ public class TestFileManager
warnAboutCleanup = false;
}
- public void assertFileExistence( File dir, String filename, boolean shouldExist )
+ public void assertFileExistence( final File dir, final String filename, final boolean shouldExist )
{
- File file = new File( dir, filename );
+ final File file = new File( dir, filename );
if ( shouldExist )
{
@@ -156,12 +156,12 @@ public class TestFileManager
}
}
- public void assertFileContents( File dir, String filename, String contentsTest )
+ public void assertFileContents( final File dir, final String filename, final String contentsTest )
throws IOException
{
assertFileExistence( dir, filename, true );
- File file = new File( dir, filename );
+ final File file = new File( dir, filename );
Assert.assertEquals( contentsTest, getFileContents( file ) );
}
@@ -169,12 +169,12 @@ public class TestFileManager
/**
* NOTE: the file content is written using platform encoding.
*/
- public File createFile( File dir, String filename, String contents )
- throws IOException
+ public File createFile( final File dir, final String filename, final String contents ) throws IOException
{
- File file = new File( dir, filename );
+ final File file = new File( dir, filename );
- file.getParentFile().mkdirs();
+ file.getParentFile()
+ .mkdirs();
FileWriter writer = null;
@@ -197,8 +197,7 @@ public class TestFileManager
/**
* NOTE: the file content is read using platform encoding.
*/
- public String getFileContents( File file )
- throws IOException
+ public String getFileContents( final File file ) throws IOException
{
String result = null;
@@ -217,18 +216,17 @@ public class TestFileManager
return result;
}
- protected void finalize()
- throws Throwable
+ @Override
+ protected void finalize() throws Throwable
{
maybeWarnAboutCleanUp();
super.finalize();
}
- public File createFile( String filename, String content )
- throws IOException
+ public File createFile( final String filename, final String content ) throws IOException
{
- File dir = createTempDir();
+ final File dir = createTempDir();
return createFile( dir, filename, content );
}
Modified: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/FilterUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/FilterUtilsTest.java?rev=999612&r1=999611&r2=999612&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/FilterUtilsTest.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/FilterUtilsTest.java Tue Sep 21 20:34:50 2010
@@ -39,13 +39,14 @@ import java.util.Set;
import junit.framework.TestCase;
public class FilterUtilsTest
-extends TestCase
+ extends TestCase
{
- private MockManager mockManager = new MockManager();
+ private final MockManager mockManager = new MockManager();
private Logger logger;
+ @Override
public void setUp()
{
clearAll();
@@ -60,8 +61,8 @@ extends TestCase
public void testFilterArtifacts_ShouldThrowExceptionUsingStrictModeWithUnmatchedInclude()
{
- MockControl artifactCtl = MockControl.createControl( Artifact.class );
- Artifact artifact = (Artifact) artifactCtl.getMock();
+ final MockControl artifactCtl = MockControl.createControl( Artifact.class );
+ final Artifact artifact = (Artifact) artifactCtl.getMock();
mockManager.add( artifactCtl );
@@ -77,24 +78,24 @@ extends TestCase
artifact.getDependencyConflictId();
artifactCtl.setReturnValue( "group:artifact:type", MockControl.ONE_OR_MORE );
- List includes = new ArrayList();
+ final List<String> includes = new ArrayList<String>();
includes.add( "other.group:other-artifact:type:version" );
- List excludes = Collections.EMPTY_LIST;
+ final List<String> excludes = Collections.emptyList();
- Set artifacts = new HashSet();
+ final Set<Artifact> artifacts = new HashSet<Artifact>();
artifacts.add( artifact );
mockManager.replayAll();
try
{
- FilterUtils.filterArtifacts( artifacts, includes, excludes, true, false, Collections.EMPTY_LIST, logger );
+ FilterUtils.filterArtifacts( artifacts, includes, excludes, true, false, logger );
fail( "Should fail because of unmatched include." );
}
- catch ( InvalidAssemblerConfigurationException e )
+ catch ( final InvalidAssemblerConfigurationException e )
{
// expected.
}
@@ -103,36 +104,36 @@ extends TestCase
}
public void testFilterArtifacts_ShouldNotRemoveArtifactDirectlyIncluded()
- throws InvalidAssemblerConfigurationException
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactInclusion( "group", "artifact", "group:artifact", null, null, null );
verifyArtifactInclusion( "group", "artifact", "group:artifact:jar", null, null, null );
}
public void testFilterArtifacts_ShouldNotRemoveArtifactTransitivelyIncluded()
- throws InvalidAssemblerConfigurationException
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactInclusion( "group",
"artifact",
"group:dependentArtifact",
null,
Arrays.asList( new String[] { "current:project:jar:1.0",
- "group:dependentArtifact:jar:version" } ), null );
+ "group:dependentArtifact:jar:version" } ), null );
}
public void testFilterArtifacts_ShouldRemoveArtifactTransitivelyExcluded()
- throws InvalidAssemblerConfigurationException
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactExclusion( "group",
"artifact",
null,
"group:dependentArtifact",
Arrays.asList( new String[] { "current:project:jar:1.0",
- "group:dependentArtifact:jar:version" } ), null );
+ "group:dependentArtifact:jar:version" } ), null );
}
public void testFilterArtifacts_ShouldRemoveArtifactDirectlyExcluded()
- throws InvalidAssemblerConfigurationException
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactExclusion( "group", "artifact", null, "group:artifact", null, null );
@@ -142,19 +143,19 @@ extends TestCase
}
public void testFilterArtifacts_ShouldNotRemoveArtifactNotIncludedAndNotExcluded()
- throws InvalidAssemblerConfigurationException
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactInclusion( "group", "artifact", null, null, null, null );
verifyArtifactInclusion( "group", "artifact", null, null, null, null );
}
public void testFilterArtifacts_ShouldRemoveArtifactExcludedByAdditionalFilter()
- throws InvalidAssemblerConfigurationException
+ throws InvalidAssemblerConfigurationException
{
- ArtifactFilter filter = new ArtifactFilter()
+ final ArtifactFilter filter = new ArtifactFilter()
{
- public boolean include( Artifact artifact )
+ public boolean include( final Artifact artifact )
{
return false;
}
@@ -177,7 +178,7 @@ extends TestCase
"group:dependentArtifact",
null,
Arrays.asList( new String[] { "current:project:jar:1.0",
- "group:dependentArtifact:jar:version" } ) );
+ "group:dependentArtifact:jar:version" } ) );
}
public void testFilterProjects_ShouldRemoveProjectTransitivelyExcluded()
@@ -202,71 +203,65 @@ extends TestCase
verifyProjectInclusion( "group", "artifact", null, null, null );
}
- private void verifyArtifactInclusion( String groupId, String artifactId, String inclusionPattern,
- String exclusionPattern, List depTrail, ArtifactFilter additionalFilter )
- throws InvalidAssemblerConfigurationException
+ private void verifyArtifactInclusion( final String groupId, final String artifactId, final String inclusionPattern,
+ final String exclusionPattern, final List<String> depTrail,
+ final ArtifactFilter additionalFilter )
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactFiltering( groupId, artifactId, inclusionPattern, exclusionPattern, depTrail, true,
additionalFilter );
}
- private void verifyArtifactExclusion( String groupId, String artifactId, String inclusionPattern,
- String exclusionPattern, List depTrail, ArtifactFilter additionalFilter )
- throws InvalidAssemblerConfigurationException
+ private void verifyArtifactExclusion( final String groupId, final String artifactId, final String inclusionPattern,
+ final String exclusionPattern, final List<String> depTrail,
+ final ArtifactFilter additionalFilter )
+ throws InvalidAssemblerConfigurationException
{
verifyArtifactFiltering( groupId, artifactId, inclusionPattern, exclusionPattern, depTrail, false,
additionalFilter );
}
- private void verifyArtifactFiltering( String groupId, String artifactId, String inclusionPattern,
- String exclusionPattern, List depTrail, boolean verifyInclusion,
- ArtifactFilter additionalFilter )
- throws InvalidAssemblerConfigurationException
+ private void verifyArtifactFiltering( final String groupId, final String artifactId, final String inclusionPattern,
+ final String exclusionPattern, final List<String> depTrail,
+ final boolean verifyInclusion, final ArtifactFilter additionalFilter )
+ throws InvalidAssemblerConfigurationException
{
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, depTrail );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, depTrail );
mockManager.replayAll();
- List inclusions;
+ List<String> inclusions;
if ( inclusionPattern != null )
{
inclusions = Collections.singletonList( inclusionPattern );
}
else
{
- inclusions = Collections.EMPTY_LIST;
+ inclusions = Collections.emptyList();
}
- List exclusions;
+ List<String> exclusions;
if ( exclusionPattern != null )
{
exclusions = Collections.singletonList( exclusionPattern );
}
else
{
- exclusions = Collections.EMPTY_LIST;
- }
-
- List filters;
- if ( additionalFilter != null )
- {
- filters = Collections.singletonList( additionalFilter );
- }
- else
- {
- filters = Collections.EMPTY_LIST;
+ exclusions = Collections.emptyList();
}
- Set artifacts = new HashSet();
+ final Set<Artifact> artifacts = new HashSet<Artifact>();
artifacts.add( mac.artifact );
- FilterUtils.filterArtifacts( artifacts, inclusions, exclusions, false, depTrail != null, filters, logger );
+ FilterUtils.filterArtifacts( artifacts, inclusions, exclusions, false, depTrail != null, logger,
+ additionalFilter );
if ( verifyInclusion )
{
assertEquals( 1, artifacts.size() );
- assertEquals( mac.artifact.getDependencyConflictId(), ( (Artifact) artifacts.iterator().next() )
- .getDependencyConflictId() );
+ assertEquals( mac.artifact.getDependencyConflictId(), artifacts.iterator()
+ .next()
+ .getDependencyConflictId() );
}
else
{
@@ -282,59 +277,62 @@ extends TestCase
mockManager.clear();
}
- private void verifyProjectInclusion( String groupId, String artifactId, String inclusionPattern,
- String exclusionPattern, List depTrail )
+ private void verifyProjectInclusion( final String groupId, final String artifactId, final String inclusionPattern,
+ final String exclusionPattern, final List<String> depTrail )
{
verifyProjectFiltering( groupId, artifactId, inclusionPattern, exclusionPattern, depTrail, true );
}
- private void verifyProjectExclusion( String groupId, String artifactId, String inclusionPattern,
- String exclusionPattern, List depTrail )
+ private void verifyProjectExclusion( final String groupId, final String artifactId, final String inclusionPattern,
+ final String exclusionPattern, final List<String> depTrail )
{
verifyProjectFiltering( groupId, artifactId, inclusionPattern, exclusionPattern, depTrail, false );
}
- private void verifyProjectFiltering( String groupId, String artifactId, String inclusionPattern,
- String exclusionPattern, List depTrail, boolean verifyInclusion )
+ private void verifyProjectFiltering( final String groupId, final String artifactId, final String inclusionPattern,
+ final String exclusionPattern, final List<String> depTrail,
+ final boolean verifyInclusion )
{
- ProjectWithArtifactMockControl pmac = new ProjectWithArtifactMockControl( groupId, artifactId, depTrail );
+ final ProjectWithArtifactMockControl pmac = new ProjectWithArtifactMockControl( groupId, artifactId, depTrail );
mockManager.replayAll();
// make sure the mock is satisfied...you can't disable this expectation.
pmac.mac.artifact.getDependencyConflictId();
- Set projects = new HashSet();
+ final Set<MavenProject> projects = new HashSet<MavenProject>();
projects.add( pmac );
- List inclusions;
+ List<String> inclusions;
if ( inclusionPattern != null )
{
inclusions = Collections.singletonList( inclusionPattern );
}
else
{
- inclusions = Collections.EMPTY_LIST;
+ inclusions = Collections.emptyList();
}
- List exclusions;
+ List<String> exclusions;
if ( exclusionPattern != null )
{
exclusions = Collections.singletonList( exclusionPattern );
}
else
{
- exclusions = Collections.EMPTY_LIST;
+ exclusions = Collections.emptyList();
}
- Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
+ final Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
FilterUtils.filterProjects( projects, inclusions, exclusions, depTrail != null, logger );
if ( verifyInclusion )
{
assertEquals( 1, projects.size() );
- assertEquals( pmac.getId(), ( (MavenProject) projects.iterator().next() ).getId() );
+ assertEquals( pmac.getId(), projects.iterator()
+ .next()
+ .getId() );
}
else
{
@@ -347,9 +345,9 @@ extends TestCase
mockManager.clear();
}
- private static Model buildModel( String groupId, String artifactId )
+ private static Model buildModel( final String groupId, final String artifactId )
{
- Model model = new Model();
+ final Model model = new Model();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
@@ -357,11 +355,11 @@ extends TestCase
}
private final class ProjectWithArtifactMockControl
- extends MavenProject
+ extends MavenProject
{
ArtifactMockAndControl mac;
- ProjectWithArtifactMockControl( String groupId, String artifactId, List depTrail )
+ ProjectWithArtifactMockControl( final String groupId, final String artifactId, final List<String> depTrail )
{
super( buildModel( groupId, artifactId ) );
@@ -382,9 +380,9 @@ extends TestCase
String artifactId;
- List dependencyTrail;
+ List<String> dependencyTrail;
- ArtifactMockAndControl( String groupId, String artifactId, List dependencyTrail )
+ ArtifactMockAndControl( final String groupId, final String artifactId, final List<String> dependencyTrail )
{
this.groupId = groupId;
this.artifactId = artifactId;