[MNG-6558] ToolchainsBuildingResult event is not sent on EventSpy
authorGuy Brand <guy@guymas.ch>
Fri, 11 Jan 2019 08:08:42 +0000 (09:08 +0100)
committerSylwester Lachiewicz <slachiewicz@apache.org>
Sun, 27 Jan 2019 11:01:35 +0000 (12:01 +0100)
Closes #231

maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java

index 4d142ee..4767b13 100644 (file)
@@ -596,7 +596,7 @@ public class MavenCli
         populateProperties( cliRequest.commandLine, cliRequest.systemProperties, cliRequest.userProperties );
     }
 
-    private PlexusContainer container( CliRequest cliRequest )
+    PlexusContainer container( CliRequest cliRequest )
         throws Exception
     {
         if ( cliRequest.classWorld == null )
@@ -1201,7 +1201,7 @@ public class MavenCli
         }
     }
 
-    private void toolchains( CliRequest cliRequest )
+    void toolchains( CliRequest cliRequest )
         throws Exception
     {
         File userToolchainsFile;
@@ -1265,7 +1265,7 @@ public class MavenCli
 
         ToolchainsBuildingResult toolchainsResult = toolchainsBuilder.build( toolchainsRequest );
 
-        eventSpyDispatcher.onEvent( toolchainsRequest );
+        eventSpyDispatcher.onEvent( toolchainsResult );
 
         executionRequestPopulator.populateFromToolchains( cliRequest.request,
                                                           toolchainsResult.getEffectiveToolchains() );
index 933ee75..2e4362c 100644 (file)
@@ -24,14 +24,24 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
 
 import java.io.File;
 
 import org.apache.commons.cli.ParseException;
+import org.apache.maven.Maven;
+import org.apache.maven.eventspy.internal.EventSpyDispatcher;
 import org.apache.maven.shared.utils.logging.MessageUtils;
+import org.apache.maven.toolchain.building.ToolchainsBuildingRequest;
+import org.apache.maven.toolchain.building.ToolchainsBuildingResult;
+import org.codehaus.plexus.PlexusContainer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.InOrder;
 
 public class MavenCliTest
 {
@@ -295,4 +305,32 @@ public class MavenCliTest
             // noop
         }
     }
+
+    /**
+     * Verifies MNG-6558
+     */
+    @Test
+    public void testToolchainsBuildingEvents() throws Exception {
+        final EventSpyDispatcher eventSpyDispatcherMock = mock(EventSpyDispatcher.class);
+        MavenCli customizedMavenCli = new MavenCli() {
+            @Override
+            protected void customizeContainer(PlexusContainer container) {
+                super.customizeContainer(container);
+                container.addComponent(eventSpyDispatcherMock, "org.apache.maven.eventspy.internal.EventSpyDispatcher");
+                container.addComponent(mock(Maven.class), "org.apache.maven.Maven");
+            }
+        };
+
+        CliRequest cliRequest = new CliRequest(new String[]{}, null);
+
+        customizedMavenCli.cli(cliRequest);
+        customizedMavenCli.logging(cliRequest);
+        customizedMavenCli.container(cliRequest);
+        customizedMavenCli.toolchains(cliRequest);
+
+        InOrder orderdEventSpyDispatcherMock = inOrder(eventSpyDispatcherMock);
+        orderdEventSpyDispatcherMock.verify(eventSpyDispatcherMock, times(1)).onEvent(any(ToolchainsBuildingRequest.class));
+        orderdEventSpyDispatcherMock.verify(eventSpyDispatcherMock, times(1)).onEvent(any(ToolchainsBuildingResult.class));
+    }
+
 }