[MNG-6558] ToolchainsBuildingResult event is not sent on EventSpy

Closes #231
This commit is contained in:
Guy Brand 2019-01-11 09:08:42 +01:00 committed by Sylwester Lachiewicz
parent 7e3e5453c0
commit 15c647182a
2 changed files with 41 additions and 3 deletions

View 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() );

View 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));
}
}