You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/05/03 18:25:01 UTC
[maven-plugin-tools] 01/01: Replace EasyMock with Mockito
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch mockito
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git
commit 9b36687ee5f85689905eee561a6cce940b83108e
Author: rfscholte <rf...@apache.org>
AuthorDate: Sun May 3 20:24:47 2020 +0200
Replace EasyMock with Mockito
---
maven-plugin-tools-annotations/pom.xml | 6 +--
.../scanner/DefaultMojoAnnotationsScannerTest.java | 18 +++----
maven-script/maven-script-ant/pom.xml | 4 +-
.../maven/script/ant/AntMojoWrapperTest.java | 61 +++++++++++++---------
pom.xml | 7 +--
5 files changed, 54 insertions(+), 42 deletions(-)
diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml
index 97ab392..9ccde1f 100644
--- a/maven-plugin-tools-annotations/pom.xml
+++ b/maven-plugin-tools-annotations/pom.xml
@@ -90,10 +90,10 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
</dependency>
-
</dependencies>
<build>
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
index b90304b..11508b8 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
@@ -19,30 +19,28 @@ package org.apache.maven.tools.plugin.extractor.annotations.scanner;
* under the License.
*/
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.mock;
import java.io.File;
-import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
+import org.junit.Test;
public class DefaultMojoAnnotationsScannerTest
- extends PlexusTestCase
{
private DefaultMojoAnnotationsScanner scanner = new DefaultMojoAnnotationsScanner();
-
+
+ @Test
public void testSkipModuleInfoClassInArchive() throws Exception
{
- scanner.scanArchive( new File( getBasedir(), "target/test-classes/java9-module.jar"), null, false );
+ scanner.scanArchive( new File( "target/test-classes/java9-module.jar"), null, false );
}
+ @Test
public void testJava8Annotations() throws Exception
{
- Logger logger = createMock( Logger.class );
- expect( logger.isDebugEnabled() ).andReturn( false );
- replay( logger );
- scanner.enableLogging( logger );
- scanner.scanArchive( new File( getBasedir(), "target/test-classes/java8-annotations.jar"), null, false );
+ scanner.enableLogging( mock( Logger.class ) );
+ scanner.scanArchive( new File( "target/test-classes/java8-annotations.jar"), null, false );
}
}
diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml
index f5675ac..bd93115 100644
--- a/maven-script/maven-script-ant/pom.xml
+++ b/maven-script/maven-script-ant/pom.xml
@@ -60,8 +60,8 @@ under the License.
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
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 560db10..2b50e99 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
@@ -19,6 +19,15 @@ package org.apache.maven.script.ant;
* under the License.
*/
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.startsWith;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -33,6 +42,7 @@ 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;
import org.apache.maven.model.Build;
@@ -55,17 +65,21 @@ import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.junit.Before;
import org.junit.Test;
-
-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 static org.junit.Assert.fail;
+import org.mockito.ArgumentCaptor;
public class AntMojoWrapperTest
{
+
+ private BuildListener buildListener;
+ @Before
+ public void setUp()
+ {
+ buildListener = mock( BuildListener.class );
+ }
+
@Test
public void test2xStylePlugin()
throws PlexusConfigurationException, IOException, ComponentInstantiationException, MojoExecutionException,
@@ -84,7 +98,12 @@ public class AntMojoWrapperTest
assertPresence( messages, "maven-script-ant < 2.1.0, or used maven-plugin-tools-ant < 2.2 during release",
false );
- assertPresence( messages, "path-is-missing", false );
+ ArgumentCaptor<BuildEvent> buildEvent = ArgumentCaptor.forClass(BuildEvent.class);
+ verify( buildListener, atLeastOnce() ).messageLogged( buildEvent.capture() );
+
+ // last message
+ assertThat( buildEvent.getValue().getMessage(), startsWith( "plugin classpath is: " ) );
+ assertThat( buildEvent.getValue().getMessage(), endsWith( ".test.jar" ) );
}
@Test
@@ -104,7 +123,12 @@ public class AntMojoWrapperTest
"Maven project, session, mojo-execution, or path-translation parameter information is", true );
assertPresence( messages, "maven-script-ant < 2.1.0, or used maven-plugin-tools-ant < 2.2 during release", true );
- assertPresence( messages, "path-is-missing", true );
+ ArgumentCaptor<BuildEvent> buildEvent = ArgumentCaptor.forClass(BuildEvent.class);
+ verify( buildListener, atLeastOnce() ).messageLogged( buildEvent.capture() );
+
+ // last message
+ assertThat( buildEvent.getValue().getMessage(), startsWith( "plugin classpath is: " ) );
+ assertThat( buildEvent.getValue().getMessage(), endsWith( "path-is-missing" ) );
}
private void assertPresence( List<String> messages, String test, boolean shouldBePresent )
@@ -158,8 +182,8 @@ public class AntMojoWrapperTest
wrapper.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
- Artifact artifact = createMock( Artifact.class );
- PathTranslator pt = createMock( PathTranslator.class );
+ Artifact artifact = mock( Artifact.class );
+ PathTranslator pt = mock( PathTranslator.class );
if ( includeImplied )
{
@@ -174,12 +198,7 @@ public class AntMojoWrapperTest
archiver.addFile( pluginXmlFile, pluginXml );
archiver.createArchive();
- 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();
+ when( artifact.getFile() ).thenReturn( jarFile );
Model model = new Model();
@@ -191,8 +210,6 @@ public class AntMojoWrapperTest
MavenProject project = new MavenProject( model );
project.setFile( new File( "pom.xml" ).getAbsoluteFile() );
- replay( artifact, pt );
-
pd.setPluginArtifact( artifact );
pd.setArtifacts( Collections.singletonList( artifact ) );
@@ -209,7 +226,8 @@ public class AntMojoWrapperTest
wrapper.setComponentConfiguration( config );
TestBuildListener tbl = new TestBuildListener();
- wrapper.getAntProject().addBuildListener( tbl );
+
+ wrapper.getAntProject().addBuildListener( buildListener );
PrintStream oldOut = System.out;
@@ -227,11 +245,6 @@ public class AntMojoWrapperTest
System.out.println( "\n\n" + stack.getMethodName() + " executed; verifying...\n\n" );
- if ( includeImplied )
- {
- verify( artifact, pt );
- }
-
List<String> messages = new ArrayList<>();
if ( !tbl.messages.isEmpty() )
{
diff --git a/pom.xml b/pom.xml
index 9851712..6b27186 100644
--- a/pom.xml
+++ b/pom.xml
@@ -230,11 +230,12 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>3.4</version>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.28.2</version>
<scope>test</scope>
</dependency>
+
</dependencies>
</dependencyManagement>
<dependencies>