[ https://issues.apache.org/jira/browse/MPLUGINTESTING-45?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Elliotte Rusty Harold resolved MPLUGINTESTING-45. ------------------------------------------------- Resolution: Cannot Reproduce > Use of MojoRule causes Guice injection error > -------------------------------------------- > > Key: MPLUGINTESTING-45 > URL: https://issues.apache.org/jira/browse/MPLUGINTESTING-45 > Project: Maven Plugin Testing > Issue Type: Bug > Reporter: Samuel James Corbett > Priority: Major > > I'm trying to write some tests for a plugin. I am using: > * Maven version 3.2.3 > * maven-plugin-testing-harness version 3.2.0 > * JUnit version 4.12 > I'm following the instructions at > http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/getting-started/index.html > that may or may not be out of date. > Any use of the {{MojoRule}} class causes all tests to fail with a Guice > injection error. > For example, this useless class: > {code} > package io.brooklyn.maven; > import org.apache.maven.plugin.testing.MojoRule; > import org.junit.Rule; > import org.junit.Test; > public class FakeTest { > @Rule > public MojoRule mojoRule = new MojoRule() { > @Override > protected void after() { > super.after(); > } > @Override > protected void before() throws Throwable { > super.before(); > } > }; > @Test > public void testNothing() { > } > } > {code} > fails with: > {code} > Running io.brooklyn.maven.FakeTest > Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.04 sec <<< > FAILURE! > testNothing(io.brooklyn.maven.FakeTest) Time elapsed: 0.934 sec <<< ERROR! > com.google.inject.CreationException: Unable to create injector, see the > following errors: > 1) Scope org.apache.maven.execution.scope.internal.MojoExecutionScope@eac4a5f > is already bound to org.apache.maven.execution.scope.MojoExecutionScoped at > org.apache.maven.plugin. > testing.AbstractMojoTestCase$1.configure(AbstractMojoTestCase.java:236) (via > modules: org.eclipse.sisu.wire.WireModule -> > org.codehaus.plexus.DefaultPlexusContainer$BootModule -> > org.apache.maven.plugin.testing.AbstractMojoTestCase$1). > Cannot bind > org.apache.maven.execution.scope.internal.MojoExecutionScope@5146aa7f. > at ClassRealm[plexus.core, parent: null] (via modules: > org.eclipse.sisu.wire.WireModule -> > org.eclipse.sisu.plexus.PlexusBindingModule -> > org.apache.maven.execution.scope.inter > nal.MojoExecutionScopeCoreModule) > 1 error > at > com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448) > at > com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155) > at > com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107) > at com.google.inject.Guice.createInjector(Guice.java:96) > at com.google.inject.Guice.createInjector(Guice.java:73) > at com.google.inject.Guice.createInjector(Guice.java:62) > at > org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:481) > at > org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:206) > at > org.apache.maven.plugin.testing.AbstractMojoTestCase.setupContainer(AbstractMojoTestCase.java:243) > at > org.apache.maven.plugin.testing.AbstractMojoTestCase.getContainer(AbstractMojoTestCase.java:277) > at > org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:118) > at > org.apache.maven.plugin.testing.MojoRule$2.evaluate(MojoRule.java:304) > at org.junit.rules.RunRules.evaluate(RunRules.java:20) > at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) > at > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) > at org.junit.runners.ParentRunner.run(ParentRunner.java:363) > at > org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) > at > org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) > at > org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:606) > at > org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) > at > org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) > at > org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) > at > org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) > at > org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)