Author: khmarbaise Date: Mon Dec 28 23:30:24 2015 New Revision: 1722035 URL: http://svn.apache.org/viewvc?rev=1722035&view=rev Log: Cleaning up Test code / Improved Test Code
Modified: maven/plugins/trunk/maven-ejb-plugin/pom.xml maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ArtifactStub.java maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java Modified: maven/plugins/trunk/maven-ejb-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/pom.xml?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-ejb-plugin/pom.xml Mon Dec 28 23:30:24 2015 @@ -120,6 +120,12 @@ under the License. <scope>test</scope> </dependency> <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>1.7.1</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-compat</artifactId> <version>${mavenVersion}</version> Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbHelperTest.java Mon Dec 28 23:30:24 2015 @@ -19,8 +19,7 @@ package org.apache.maven.plugins.ejb; * under the License. */ -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; @@ -32,61 +31,62 @@ public class EjbHelperTest @Test public void validClassifier() { - assertThat( EjbHelper.isClassifierValid( "anton" ), is( Boolean.TRUE ) ); + assertThat( EjbHelper.isClassifierValid( "anton" ) ).isTrue(); } @Test public void anOtherValidClassifier() { - assertThat( EjbHelper.isClassifierValid( "jdk15" ), is( Boolean.TRUE ) ); + assertThat( EjbHelper.isClassifierValid( "jdk15" ) ).isTrue(); } @Test public void moreValidClassifier() { - assertThat( EjbHelper.isClassifierValid( "client-classifier" ), is( Boolean.TRUE ) ); + assertThat( EjbHelper.isClassifierValid( "client-classifier" ) ).isTrue(); } @Test public void isClassifierValidShouldReturnFalseIfClassifierIsPrefixedByDash() { - assertThat( EjbHelper.isClassifierValid( "-anton" ), is( Boolean.FALSE ) ); + assertThat( EjbHelper.isClassifierValid( "-anton" ) ).isFalse(); } @Test public void isClassifierValidShouldReturnFalseIfClassifierIsNull() { - assertThat( EjbHelper.isClassifierValid( null ), is( Boolean.FALSE ) ); + assertThat( EjbHelper.isClassifierValid( null ) ).isFalse(); } @Test public void hasClassifierShouldReturnFalseForNull() { - assertThat( EjbHelper.hasClassifier( null ), is( Boolean.FALSE ) ); + assertThat( EjbHelper.hasClassifier( null ) ).isFalse(); } @Test public void hasClassifierShouldReturnFalseForEmptyString() { - assertThat( EjbHelper.hasClassifier( "" ), is( Boolean.FALSE ) ); + assertThat( EjbHelper.hasClassifier( "" ) ).isFalse(); } @Test public void hasClassifierShouldReturnTrueForNonEmptyString() { - assertThat( EjbHelper.hasClassifier( "x" ), is( Boolean.TRUE ) ); + assertThat( EjbHelper.hasClassifier( "x" ) ).isTrue(); } @Test public void getJarFileNameShouldReturnFileNameWithoutClassifier() { - assertThat( EjbHelper.getJarFileName( new File( "base" ), "test", null ).getPath(), is( "base/test.jar" ) ); + assertThat( EjbHelper.getJarFileName( new File( "base" ), "test", + null ) ).isEqualTo( new File( "base/test.jar" ) ); } @Test public void getJarFileNameShouldReturnFileNameWithClassifier() { - assertThat( EjbHelper.getJarFileName( new File( "base" ), "test", "alpha" ).getPath(), - is( "base/test-alpha.jar" ) ); + assertThat( EjbHelper.getJarFileName( new File( "base" ), "test", + "alpha" ) ).isEqualTo( new File( "base/test-alpha.jar" ) ); } } Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/EjbMojoTest.java Mon Dec 28 23:30:24 2015 @@ -50,12 +50,6 @@ public class EjbMojoTest super.setUp(); } - public void tearDown() - throws Exception - { - - } - /** * check test environment * @@ -185,10 +179,13 @@ public class EjbMojoTest mojo.execute(); assertJarCreation( project, true, false ); - assertJarContent( project, new String[] { "META-INF/MANIFEST.MF", "META-INF/ejb-jar.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", "org/sample/ejb/AppBean.class", - "org/sample/ejb/AppCMP.class", "org/sample/ejb/AppSession.class" }, null ); + assertJarContent( project, + new String[] { "META-INF/MANIFEST.MF", "META-INF/ejb-jar.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", + "org/sample/ejb/AppBean.class", "org/sample/ejb/AppCMP.class", + "org/sample/ejb/AppSession.class" }, + null ); } /** @@ -222,7 +219,8 @@ public class EjbMojoTest mojo.execute(); assertJarCreation( project, true, true ); - assertClientJarContent( project, new String[] { "META-INF/MANIFEST.MF", + assertClientJarContent( project, + new String[] { "META-INF/MANIFEST.MF", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", "org/sample/ejb/AppStub.class" }, @@ -265,8 +263,8 @@ public class EjbMojoTest new String[] { "META-INF/MANIFEST.MF", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppInclude.class" }, new String[] { "META-INF/ejb-jar.xml", - "org/sample/ejb/AppExclude.class" } ); + "org/sample/ejb/AppInclude.class" }, + new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class" } ); } /** @@ -305,8 +303,8 @@ public class EjbMojoTest new String[] { "META-INF/MANIFEST.MF", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppInclude.class" }, new String[] { "META-INF/ejb-jar.xml", - "org/sample/ejb/AppExclude.class" } ); + "org/sample/ejb/AppInclude.class" }, + new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class" } ); } @@ -346,8 +344,8 @@ public class EjbMojoTest new String[] { "META-INF/MANIFEST.MF", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", - "org/sample/ejb/AppInclude.class" }, new String[] { "META-INF/ejb-jar.xml", - "org/sample/ejb/AppExclude.class" } ); + "org/sample/ejb/AppInclude.class" }, + new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class" } ); } @@ -383,7 +381,8 @@ public class EjbMojoTest mojo.execute(); assertJarCreation( project, true, true ); - assertClientJarContent( project, new String[] { "META-INF/MANIFEST.MF", + assertClientJarContent( project, + new String[] { "META-INF/MANIFEST.MF", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", "org/sample/ejb/App.class" }, @@ -430,7 +429,8 @@ public class EjbMojoTest "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", "org/sample/ejb2/AppTwo.class" }, - new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppOne.class", "org/sample/ejb" } ); + new String[] { "META-INF/ejb-jar.xml", "org/sample/ejb/AppOne.class", + "org/sample/ejb" } ); } @@ -554,7 +554,7 @@ public class EjbMojoTest protected EjbMojo lookupMojoWithSettings( final MavenProject project, List<String> clientIncludes, List<String> clientExcludes, List<String> excludes ) - throws Exception + throws Exception { final EjbMojo mojo = lookupMojo(); setVariableValueToObject( mojo, "project", project ); @@ -565,7 +565,7 @@ public class EjbMojoTest setVariableValueToObject( mojo, "clientExcludes", clientExcludes ); setVariableValueToObject( mojo, "clientIncludes", clientIncludes ); setVariableValueToObject( mojo, "excludes", excludes ); - setVariableValueToObject( mojo, "clientClassifier", EjbMojo.DEFAULT_CLIENT_CLASSIFIER); + setVariableValueToObject( mojo, "clientClassifier", EjbMojo.DEFAULT_CLIENT_CLASSIFIER ); return mojo; } @@ -608,7 +608,7 @@ public class EjbMojoTest private void doAssertJarContent( final MavenProject project, final String fileName, final String[] expectedFiles, final String[] unexpectedFiles ) - throws IOException + throws IOException { String checkedJarFile = project.getBuild().getDirectory() + "/" + fileName; if ( expectedFiles != null ) @@ -636,7 +636,7 @@ public class EjbMojoTest protected void assertJarContent( final MavenProject project, final String[] expectedFiles, final String[] unexpectedFiles ) - throws IOException + throws IOException { doAssertJarContent( project, DEFAULT_JAR_NAME + ".jar", expectedFiles, unexpectedFiles ); @@ -644,7 +644,7 @@ public class EjbMojoTest protected void assertClientJarContent( final MavenProject project, final String[] expectedFiles, final String[] unexpectedFiles ) - throws IOException + throws IOException { doAssertJarContent( project, DEFAULT_JAR_NAME + "-client.jar", expectedFiles, unexpectedFiles ); Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/IncludesExcludesTest.java Mon Dec 28 23:30:24 2015 @@ -19,13 +19,14 @@ package org.apache.maven.plugins.ejb; * under the License. */ -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Collections; import org.junit.Test; +import com.google.inject.internal.util.Lists; + public class IncludesExcludesTest { @@ -35,8 +36,8 @@ public class IncludesExcludesTest IncludesExcludes ie = new IncludesExcludes( Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList() ); - assertThat( ie.resultingIncludes(), is( new String[0] ) ); - assertThat( ie.resultingExcludes(), is( new String[0] ) ); + assertThat( ie.resultingIncludes() ).isEqualTo( new String[0] ); + assertThat( ie.resultingExcludes() ).isEqualTo( new String[0] ); } @Test @@ -45,8 +46,8 @@ public class IncludesExcludesTest IncludesExcludes ie = new IncludesExcludes( null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList() ); - assertThat( ie.resultingIncludes(), is( new String[0] ) ); - assertThat( ie.resultingExcludes(), is( new String[0] ) ); + assertThat( ie.resultingIncludes() ).isEqualTo( new String[0] ); + assertThat( ie.resultingExcludes() ).isEqualTo( new String[0] ); } @Test @@ -55,7 +56,28 @@ public class IncludesExcludesTest IncludesExcludes ie = new IncludesExcludes( Collections.<String>emptyList(), null, Collections.<String>emptyList(), Collections.<String>emptyList() ); - assertThat( ie.resultingIncludes(), is( new String[0] ) ); - assertThat( ie.resultingExcludes(), is( new String[0] ) ); + assertThat( ie.resultingIncludes() ).isEqualTo( new String[0] ); + assertThat( ie.resultingExcludes() ).isEqualTo( new String[0] ); + } + + @Test + public void nonNullForDefaultExcludesShouldResultInExcludesWithDefaultExcludes() + { + IncludesExcludes ie = new IncludesExcludes( null, null, Collections.<String>emptyList(), + Lists.newArrayList( "**/package.html" ) ); + + assertThat( ie.resultingIncludes() ).isEqualTo( new String[0] ); + assertThat( ie.resultingExcludes() ).isEqualTo( new String[] { "**/package.html" } ); } + + @Test + public void nonNullForDefaultIncludesShouldResultInExcludesWithDefaultIncludes() + { + IncludesExcludes ie = new IncludesExcludes( null, null, Lists.newArrayList( "**/package.html" ), + Collections.<String>emptyList() ); + + assertThat( ie.resultingIncludes() ).isEqualTo( new String[] { "**/package.html" } ); + assertThat( ie.resultingExcludes() ).isEqualTo( new String[0] ); + } + } Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ArtifactStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ArtifactStub.java?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ArtifactStub.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ArtifactStub.java Mon Dec 28 23:30:24 2015 @@ -20,7 +20,6 @@ package org.apache.maven.plugins.ejb.stu */ import java.io.File; -import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -167,17 +166,17 @@ public class ArtifactStub public void addMetadata( ArtifactMetadata metadata ) { - + // intentionally empty } - public Collection getMetadataList() + public List<ArtifactMetadata> getMetadataList() { - return new LinkedList(); + return new LinkedList<ArtifactMetadata>(); } public void setRepository( ArtifactRepository remoteRepository ) { - + // intentionally empty } public ArtifactRepository getRepository() @@ -187,7 +186,7 @@ public class ArtifactStub public void updateVersion( String version, ArtifactRepository localRepository ) { - + //Intentionally empty. } public String getDownloadUrl() @@ -207,7 +206,7 @@ public class ArtifactStub public void setDependencyFilter( ArtifactFilter artifactFilter ) { - + //Intentionally empty. } public ArtifactHandler getArtifactHandler() @@ -215,14 +214,14 @@ public class ArtifactStub return artifactHandler; } - public List getDependencyTrail() + public List<String> getDependencyTrail() { - return new LinkedList(); + return new LinkedList<String>(); } - public void setDependencyTrail( List dependencyTrail ) + public void setDependencyTrail( List<String> dependencyTrail ) { - + //Intentionally empty. } public void setScope( String _scope ) @@ -237,7 +236,7 @@ public class ArtifactStub public void setVersionRange( VersionRange newRange ) { - + //Intentionally empty. } public void selectVersion( String version ) @@ -277,7 +276,7 @@ public class ArtifactStub public void setArtifactHandler( ArtifactHandler handler ) { - + //Intentionally empty. } public boolean isRelease() @@ -290,14 +289,14 @@ public class ArtifactStub release = _release; } - public List getAvailableVersions() + public List<ArtifactVersion> getAvailableVersions() { - return new LinkedList(); + return new LinkedList<ArtifactVersion>(); } - public void setAvailableVersions( List versions ) + public void setAvailableVersions( List<ArtifactVersion> versions ) { - + //Intentionally empty. } public boolean isOptional() Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/MavenProjectBuildStub.java Mon Dec 28 23:30:24 2015 @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.maven.model.Build; import org.codehaus.plexus.util.FileUtils; @@ -63,30 +64,30 @@ public class MavenProjectBuildStub protected String targetTestResourcesDirectory; - protected ArrayList targetClassesList; + protected List<String> targetClassesList; - protected ArrayList sourceFileList; + protected List<String> sourceFileList; - protected ArrayList resourcesFileList; + protected List<String> resourcesFileList; - protected ArrayList rootFileList; + protected List<String> rootFileList; - protected ArrayList directoryList; + protected List<String> directoryList; - protected HashMap dataMap; + protected Map<String, String> dataMap; public MavenProjectBuildStub( String key ) throws Exception { super( key ); - build = new Build(); - resourcesFileList = new ArrayList(); - sourceFileList = new ArrayList(); - rootFileList = new ArrayList(); - directoryList = new ArrayList(); - targetClassesList = new ArrayList(); - dataMap = new HashMap(); + this.build = new Build(); + this.resourcesFileList = new ArrayList<String>(); + this.sourceFileList = new ArrayList<String>(); + this.rootFileList = new ArrayList<String>(); + this.directoryList = new ArrayList<String>(); + this.targetClassesList = new ArrayList<String>(); + this.dataMap = new HashMap<String, String>(); setupBuild(); model.setBuild( build ); @@ -110,7 +111,7 @@ public class MavenProjectBuildStub { if ( isValidPath( name ) ) { - List list = getList( type ); + List<String> list = getList( type ); list.add( name ); } @@ -241,9 +242,9 @@ public class MavenProjectBuildStub } } - private List getList( int type ) + private List<String> getList( int type ) { - ArrayList retVal = null; + List<String> retVal = null; switch ( type ) { @@ -267,7 +268,7 @@ public class MavenProjectBuildStub private void createFiles( String parent, int type ) { File currentFile; - ArrayList list = (ArrayList) getList( type ); + List<String> list = getList( type ); // guard if ( list == null ) @@ -275,9 +276,9 @@ public class MavenProjectBuildStub return; } - for ( Object aList : list ) + for ( String aList : list ) { - currentFile = new File( parent, (String) aList ); + currentFile = new File( parent, aList ); // create the necessary parent directories // before we create the files @@ -311,11 +312,6 @@ public class MavenProjectBuildStub createFiles( getOutputDirectory(), OUTPUT_FILE ); } - private void setupSourceFiles() - { - createFiles( srcDirectory, SOURCE_FILE ); - } - private void createFiles( String parent, String testparent ) { createFiles( parent, RESOURCES_FILE ); Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java?rev=1722035&r1=1722034&r2=1722035&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugins/ejb/stub/ModelStub.java Mon Dec 28 23:30:24 2015 @@ -25,6 +25,7 @@ import java.util.Properties; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; +import org.apache.maven.model.Profile; /** * Stub @@ -32,6 +33,11 @@ import org.apache.maven.model.Parent; public class ModelStub extends Model { + /** + * + */ + private static final long serialVersionUID = -6823174384695495659L; + public ModelStub() { @@ -78,13 +84,8 @@ public class ModelStub return new Properties(); } - public List getPackages() - { - return new LinkedList(); - } - - public List getProfiles() + public List<Profile> getProfiles() { - return new LinkedList(); + return new LinkedList<Profile>(); } }