remove deprecated methods by not stubbing value objects (#32)

* remove deprecated methods by not stubbing value objects

* code review
diff --git a/src/main/java/org/apache/maven/plugins/ear/util/ArtifactRepository.java b/src/main/java/org/apache/maven/plugins/ear/util/ArtifactRepository.java
index 81faf7a..558c19d 100644
--- a/src/main/java/org/apache/maven/plugins/ear/util/ArtifactRepository.java
+++ b/src/main/java/org/apache/maven/plugins/ear/util/ArtifactRepository.java
@@ -38,7 +38,7 @@
     private final ArtifactTypeMappingService artifactTypeMappingService;

 

     /**

-     * Creates a new repository wih the specified artifacts.

+     * Creates a new repository with the specified artifacts.

      * 

      * @param artifacts the artifacts

      * @param mainArtifactId the id to use for the main artifact (no classifier)

diff --git a/src/test/java/org/apache/maven/plugins/ear/AbstractEarTestBase.java b/src/test/java/org/apache/maven/plugins/ear/AbstractEarTestBase.java
index f4f0638..8c47ba5 100644
--- a/src/test/java/org/apache/maven/plugins/ear/AbstractEarTestBase.java
+++ b/src/test/java/org/apache/maven/plugins/ear/AbstractEarTestBase.java
@@ -1,10 +1,12 @@
 package org.apache.maven.plugins.ear;

 

+import java.util.Objects;

 import java.util.Set;

 import java.util.TreeSet;

 

 import org.apache.maven.artifact.Artifact;

-import org.apache.maven.plugins.ear.stub.ArtifactTestStub;

+import org.apache.maven.artifact.DefaultArtifact;

+import org.apache.maven.plugins.ear.stub.ArtifactHandlerTestStub;

 

 /*

  * Licensed to the Apache Software Foundation (ASF) under one

@@ -31,90 +33,41 @@
 public abstract class AbstractEarTestBase

 {

 

-    public static final String DEFAULT_GROUPID = "eartest";

+    protected static final String DEFAULT_GROUPID = "eartest";

 

-    public static final String DEFAULT_TYPE = "jar";

+    private static final String DEFAULT_TYPE = "jar";

 

     protected void setUri( EarModule module, String uri )

     {

         ( (AbstractEarModule) module ).setUri( uri );

     }

 

-    protected Set<Artifact> createArtifacts( String[] artifactsId )

+    protected Set<Artifact> createArtifacts( String[] artifactIds )

     {

-        return createArtifacts( artifactsId, null );

+        return createArtifacts( artifactIds, null );

     }

 

-    protected Set<Artifact> createArtifacts( String[] artifactsId, String[] types )

-    {

-        return createArtifacts( artifactsId, types, null );

-    }

-

-    protected Set<Artifact> createArtifacts( String[] artifactsId, String[] types, String[] groupsId )

-    {

-        return createArtifacts( artifactsId, types, groupsId, null );

-    }

-

-    protected Set<Artifact> createArtifacts( String[] artifactsId, String[] types, String[] groupsId,

-                                             String[] classifiers )

+    protected Set<Artifact> createArtifacts( String[] artifactIds, String[] classifiers )

     {

         Set<Artifact> result = new TreeSet<Artifact>();

-        if ( artifactsId == null || artifactsId.length == 0 )

+        ArtifactHandlerTestStub artifactHandler = new ArtifactHandlerTestStub( "jar" );

+        for ( int i = 0; i < artifactIds.length; i++ )

         {

-            return result;

-        }

-        for ( int i = 0; i < artifactsId.length; i++ )

-        {

-            String artifactId = artifactsId[i];

-            String type = getData( types, i, DEFAULT_TYPE );

-            String groupId = getData( groupsId, i, DEFAULT_GROUPID );

-            String classifier = getData( classifiers, i, null );

-            result.add( new ArtifactTestStub( groupId, artifactId, type, classifier ) );

-

+            String artifactId = artifactIds[i];

+            String classifier = classifiers == null ? null : classifiers[i];

+            Artifact artifactTestStub = new DefaultArtifact(

+                DEFAULT_GROUPID, artifactId, "1.0", "compile", DEFAULT_TYPE, classifier, artifactHandler );

+            result.add( artifactTestStub );

         }

         return result;

     }

 

-    protected String getData( String[] data, int i, String defaultValue )

-    {

-        if ( data == null || data[i] == null )

-        {

-            return defaultValue;

-        }

-        else

-        {

-            return data[i];

-

-        }

-    }

-

-    protected String getDefaultValue( String t, String defaultValue )

-    {

-        if ( t == null )

-        {

-            return defaultValue;

-        }

-        else

-        {

-            return t;

-        }

-    }

-

-    protected Artifact createArtifact( String artifactId, String type, String groupId, String classifier )

-    {

-        return new ArtifactTestStub( getDefaultValue( groupId, DEFAULT_GROUPID ), artifactId,

-                                     getDefaultValue( type, DEFAULT_TYPE ), classifier );

-    }

-

-    protected Artifact createArtifact( String artifactId, String type, String groupId )

-    {

-        return createArtifact( artifactId, type, groupId, null );

-

-    }

-

     protected Artifact createArtifact( String artifactId, String type )

     {

-        return createArtifact( artifactId, type, null );

-

+        Artifact artifactTestStub = new DefaultArtifact(

+            DEFAULT_GROUPID, artifactId, "1.0", "compile", Objects.toString( type, DEFAULT_TYPE ),

+            null, new ArtifactHandlerTestStub( "jar" ) );

+        

+        return artifactTestStub;

     }

 }

diff --git a/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactHandlerTestStub.java b/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactHandlerTestStub.java
index d71c994..38ed9ef 100644
--- a/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactHandlerTestStub.java
+++ b/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactHandlerTestStub.java
@@ -47,7 +47,7 @@
 

     public String getClassifier()

     {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

+        return null;

     }

 

     public String getPackaging()

diff --git a/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java b/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java
deleted file mode 100644
index c695ac0..0000000
--- a/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java
+++ /dev/null
@@ -1,357 +0,0 @@
-package org.apache.maven.plugins.ear.stub;

-

-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements.  See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership.  The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License.  You may obtain a copy of the License at

- *

- *  http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied.  See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-import org.apache.maven.artifact.Artifact;

-import org.apache.maven.artifact.handler.ArtifactHandler;

-import org.apache.maven.artifact.metadata.ArtifactMetadata;

-import org.apache.maven.artifact.repository.ArtifactRepository;

-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;

-import org.apache.maven.artifact.versioning.ArtifactVersion;

-import org.apache.maven.artifact.versioning.OverConstrainedVersionException;

-import org.apache.maven.artifact.versioning.VersionRange;

-

-import java.io.File;

-import java.util.Collection;

-import java.util.List;

-

-/**

- * A fake {@link Artifact} test stub.

- * 

- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>

- */

-public class ArtifactTestStub

-    implements Artifact

-

-{

-    public static final String DEFAULT_VERSION = "1.0";

-

-    private final String groupId;

-

-    private final String artifactId;

-

-    private final String type;

-

-    private final String classifier;

-

-    private String version;

-

-    public ArtifactTestStub( String groupId, String artifactId, String type, String classifier, String version )

-    {

-        this.groupId = groupId;

-        this.artifactId = artifactId;

-        this.type = type;

-        this.classifier = classifier;

-        this.version = version;

-    }

-

-    public ArtifactTestStub( String groupId, String artifactId, String type, String classifier )

-    {

-        this( groupId, artifactId, type, classifier, DEFAULT_VERSION );

-    }

-

-    public String getGroupId()

-    {

-        return groupId;

-    }

-

-    public String getArtifactId()

-    {

-        return artifactId;

-    }

-

-    public String getVersion()

-    {

-        return version;

-    }

-

-    public void setVersion( String version )

-    {

-        this.version = version;

-    }

-

-    public String getScope()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public String getType()

-    {

-        return type;

-    }

-

-    public String getClassifier()

-    {

-        return classifier;

-    }

-

-    public boolean hasClassifier()

-    {

-        return classifier != null;

-    }

-

-    public File getFile()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setFile( File file )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public String getBaseVersion()

-    {

-        return version;

-    }

-

-    public void setBaseVersion( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public String getId()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public String getDependencyConflictId()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void addMetadata( ArtifactMetadata artifactMetadata )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public Collection<ArtifactMetadata> getMetadataList()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setRepository( ArtifactRepository artifactRepository )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public ArtifactRepository getRepository()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void updateVersion( String string, ArtifactRepository artifactRepository )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public String getDownloadUrl()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setDownloadUrl( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public ArtifactFilter getDependencyFilter()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setDependencyFilter( ArtifactFilter artifactFilter )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public ArtifactHandler getArtifactHandler()

-    {

-        return new ArtifactHandlerTestStub( "jar" );

-    }

-

-    public List<String> getDependencyTrail()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setDependencyTrail( List<String> list )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setScope( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public VersionRange getVersionRange()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setVersionRange( VersionRange versionRange )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void selectVersion( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setGroupId( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setArtifactId( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public boolean isSnapshot()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setResolved( boolean b )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public boolean isResolved()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setResolvedVersion( String string )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setArtifactHandler( ArtifactHandler artifactHandler )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public boolean isRelease()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setRelease( boolean b )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public List<ArtifactVersion> getAvailableVersions()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setAvailableVersions( List<ArtifactVersion> list )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public boolean isOptional()

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public void setOptional( boolean b )

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public ArtifactVersion getSelectedVersion()

-        throws OverConstrainedVersionException

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public boolean isSelectedVersionKnown()

-        throws OverConstrainedVersionException

-    {

-        throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );

-    }

-

-    public boolean equals( Object o )

-    {

-        if ( this == o )

-        {

-            return true;

-        }

-        if ( o == null || getClass() != o.getClass() )

-        {

-            return false;

-        }

-

-        ArtifactTestStub that = (ArtifactTestStub) o;

-

-        if ( artifactId != null ? !artifactId.equals( that.artifactId ) : that.artifactId != null )

-        {

-            return false;

-        }

-        if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null )

-        {

-            return false;

-        }

-        if ( groupId != null ? !groupId.equals( that.groupId ) : that.groupId != null )

-        {

-            return false;

-        }

-        if ( type != null ? !type.equals( that.type ) : that.type != null )

-        {

-            return false;

-        }

-

-        return true;

-    }

-

-    public int hashCode()

-    {

-        int result;

-        result = ( groupId != null ? groupId.hashCode() : 0 );

-        result = 31 * result + ( artifactId != null ? artifactId.hashCode() : 0 );

-        result = 31 * result + ( type != null ? type.hashCode() : 0 );

-        result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );

-        return result;

-    }

-

-    public int compareTo( Artifact o )

-    {

-        if ( this.equals( o ) )

-        {

-            return 0;

-        }

-        else

-        {

-            return 1;

-        }

-    }

-

-    public ArtifactMetadata getMetadata( Class<?> metadataClass )

-    {

-        // TODO Auto-generated method stub

-        return null;

-    }

-}

diff --git a/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java b/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java
index f7739cc..0f8218c 100644
--- a/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java
+++ b/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java
@@ -22,9 +22,11 @@
 import static org.junit.Assert.assertNotNull;

 import static org.junit.Assert.assertNull;

 

+import java.util.HashSet;

+import java.util.Set;

+

+import org.apache.maven.artifact.Artifact;

 import org.apache.maven.plugins.ear.AbstractEarTestBase;

-import org.apache.maven.plugins.ear.EarPluginException;

-import org.codehaus.plexus.configuration.PlexusConfigurationException;

 import org.junit.Test;

 

 /**

@@ -34,14 +36,15 @@
     extends AbstractEarTestBase

 {

 

-    public static final String MAIN_ARTIFACT_ID = "none";

+    private static final String MAIN_ARTIFACT_ID = "none";

+

+    private ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();

 

     @Test

     public void testEmptyRepository()

     {

-        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();

-        ArtifactRepository repo =

-            new ArtifactRepository( createArtifacts( null ), MAIN_ARTIFACT_ID, artifactTypeMappingService );

+        Set<Artifact> artifacts = new HashSet<>();

+        ArtifactRepository repo = new ArtifactRepository( artifacts, MAIN_ARTIFACT_ID, artifactTypeMappingService );

         assertNull( repo.getUniqueArtifact( "ear", "ar", "jar" ) );

         assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", null ) );

         assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", "class" ) );

@@ -50,7 +53,6 @@
     @Test

     public void testRepositoryWithOneUnclassifiedArtifact()

     {

-        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();

         ArtifactRepository repo =

             new ArtifactRepository( createArtifacts( new String[] { "myartifact" } ), MAIN_ARTIFACT_ID,

                                     artifactTypeMappingService );

@@ -61,9 +63,8 @@
     @Test

     public void testRepositoryWithOneClassifiedArtifact()

     {

-        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();

         ArtifactRepository repo =

-            new ArtifactRepository( createArtifacts( new String[] { "myartifact" }, null, null,

+            new ArtifactRepository( createArtifacts( new String[] { "myartifact" },

                                                      new String[] { "classified" } ), MAIN_ARTIFACT_ID,

                                     artifactTypeMappingService );

         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );

@@ -74,10 +75,9 @@
     @Test

     public void testRepositoryWithMultipleClassifiedArtifacts()

     {

-        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();

         ArtifactRepository repo =

-            new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" }, null,

-                                                     null, new String[] { "class1", "class2", "class3" } ),

+            new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" }, 

+                                                     new String[] { "class1", "class2", "class3" } ),

                                     MAIN_ARTIFACT_ID, artifactTypeMappingService );

 

         assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );

@@ -89,12 +89,10 @@
 

     @Test

     public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact()

-        throws PlexusConfigurationException, EarPluginException

     {

-        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();

         ArtifactRepository repo =

-            new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" }, null,

-                                                     null, new String[] { "class1", "class2", null } ),

+            new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" },

+                                                     new String[] { "class1", "class2", null } ),

                                     MAIN_ARTIFACT_ID, artifactTypeMappingService );

 

         assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );

diff --git a/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java b/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java
index 693c84a..bca17c8 100644
--- a/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java
@@ -36,10 +36,11 @@
     extends AbstractEarTestBase

 {

 

+    private List<EarModule> modules = new ArrayList<EarModule>();

+

     @Test

     public void testSimpleEjbModule()

     {

-        final List<EarModule> modules = new ArrayList<EarModule>();

         final EarModule module = new EjbModule( createArtifact( "foo", "ejb" ) );

         setUri( module, "foo-1.0.jar" );

         modules.add( module );

@@ -52,7 +53,6 @@
     @Test

     public void testSimpleJarModuleWithCustomBundleDir()

     {

-        final List<EarModule> modules = new ArrayList<EarModule>();

         final EarModule module = new EjbModule( createArtifact( "foo", "jar" ) );

         setUri( module, "libs/foo-1.0.jar" );

         modules.add( module );

@@ -65,7 +65,6 @@
     @Test

     public void testTwoModules()

     {

-        final List<EarModule> modules = new ArrayList<EarModule>();

         final EarModule module = new EjbModule( createArtifact( "foo", "ejb" ) );

         setUri( module, "foo-1.0.jar" );

         modules.add( module );