From 79490bad1642cf8c010596d77258ca836289f1ff Mon Sep 17 00:00:00 2001 From: Robert Scholte Date: Fri, 26 Aug 2016 19:30:10 +0000 Subject: [PATCH] Upgrade EasyMock and migrate tests git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1757908 13f79535-47bb-0310-9956-ffa450edef68 --- maven-script/maven-script-ant/pom.xml | 2 +- .../maven/script/ant/AntMojoWrapperTest.java | 71 ++++++++----------- pom.xml | 4 +- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml index 2b05ab3..c388ff8 100644 --- a/maven-script/maven-script-ant/pom.xml +++ b/maven-script/maven-script-ant/pom.xml @@ -68,7 +68,7 @@ under the License. maven-core - easymock + org.easymock easymock test diff --git a/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java b/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java index 7facf01..c4836ed 100644 --- a/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java +++ b/maven-script/maven-script-ant/src/test/java/org/apache/maven/script/ant/AntMojoWrapperTest.java @@ -18,6 +18,23 @@ package org.apache.maven.script.ant; * specific language governing permissions and limitations * under the License. */ +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.io.Reader; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; @@ -43,20 +60,6 @@ import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; -import org.easymock.MockControl; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.Reader; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import junit.framework.TestCase; @@ -160,8 +163,9 @@ public class AntMojoWrapperTest wrapper.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) ); - MockControl artifactCtl = null; - MockControl pathTranslatorCtl = null; + Artifact artifact = createMock( Artifact.class ); + PathTranslator pt = createMock( PathTranslator.class ); + if ( includeImplied ) { File pluginXmlFile = new File( StringUtils.replace( resource.getPath(), "%20", " " ) ); @@ -175,29 +179,12 @@ public class AntMojoWrapperTest archiver.addFile( pluginXmlFile, pluginXml ); archiver.createArchive(); - artifactCtl = MockControl.createControl( Artifact.class ); - Artifact artifact = (Artifact) artifactCtl.getMock(); - - artifact.getFile(); - artifactCtl.setReturnValue( jarFile, MockControl.ZERO_OR_MORE ); - - artifact.getGroupId(); - artifactCtl.setReturnValue( "groupId", MockControl.ZERO_OR_MORE ); - - artifact.getArtifactId(); - artifactCtl.setReturnValue( "artifactId", MockControl.ZERO_OR_MORE ); - - artifact.getVersion(); - artifactCtl.setReturnValue( "1", MockControl.ZERO_OR_MORE ); - - artifact.getId(); - artifactCtl.setReturnValue( "groupId:artifactId:jar:1", MockControl.ZERO_OR_MORE ); - - artifact.getClassifier(); - artifactCtl.setReturnValue( null, MockControl.ZERO_OR_MORE ); - - pathTranslatorCtl = MockControl.createControl( PathTranslator.class ); - PathTranslator pt = (PathTranslator) pathTranslatorCtl.getMock(); + expect( artifact.getFile() ).andReturn( jarFile ).anyTimes(); + expect( artifact.getGroupId() ).andReturn( "groupId" ).anyTimes(); + expect( artifact.getArtifactId() ).andReturn( "artifactId" ).anyTimes(); + expect( artifact.getVersion() ).andReturn( "1" ).anyTimes(); + expect( artifact.getId() ).andReturn( "groupId:artifactId:jar:1" ).anyTimes(); + expect( artifact.getClassifier() ).andReturn( null ).anyTimes(); Model model = new Model(); @@ -209,8 +196,7 @@ public class AntMojoWrapperTest MavenProject project = new MavenProject( model ); project.setFile( new File( "pom.xml" ).getAbsoluteFile() ); - artifactCtl.replay(); - pathTranslatorCtl.replay(); + replay( artifact, pt ); pd.setPluginArtifact( artifact ); pd.setArtifacts( Collections.singletonList( artifact ) ); @@ -248,8 +234,7 @@ public class AntMojoWrapperTest if ( includeImplied ) { - artifactCtl.verify(); - pathTranslatorCtl.verify(); + verify( artifact, pt ); } List messages = new ArrayList(); diff --git a/pom.xml b/pom.xml index b5cc33f..b595cc3 100644 --- a/pom.xml +++ b/pom.xml @@ -235,9 +235,9 @@ test - easymock + org.easymock easymock - 1.2_Java1.3 + 3.4 test