Generated test in commons-component-default doesn't execute
vmassol opened this issue · 13 comments
DSpot generated the following test:
/**
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.component;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.junit.Assert;
import org.junit.Test;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.ComponentRole;
import org.xwiki.component.descriptor.DefaultComponentDescriptor;
import org.xwiki.component.embed.EmbeddableComponentManager;
import org.xwiki.component.embed.EmbeddableComponentManagerTest;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentRepositoryException;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
/**
* Validate loading and injection of Providers in a real use case.
*
* @version $Id: 683593067e19c75185fdb6191dd1cdd96ea36387 $
*/
public class AmplProviderTest {
@ComponentRole
public static interface TestComponentRole {}
@Component
@Singleton
public static class TestComponentWithProviders implements TestComponentRole {
@Inject
public Provider<String> provider1;
@Inject
@Named("another")
public Provider<String> provider12;
@Inject
public Provider<Integer> provider2;
@Inject
public Provider<List<EmbeddableComponentManagerTest.Role>> providerList;
@Inject
public Provider<Map<String, EmbeddableComponentManagerTest.Role>> providerMap;
}
public static class TestProvider1 implements Provider<String> {
@Override
public String get() {
return "value";
}
}
@Named("another")
public static class TestProvider12 implements Provider<String> {
@Override
public String get() {
return "another value";
}
}
public static class TestProvider2 implements Provider<Integer> {
@Override
public Integer get() {
return 1;
}
}
@Component
@Named("exception")
@Singleton
public static class TestComponentWithProviderInException implements TestComponentRole {
@Inject
@Named("exception")
public Provider<String> providerWithExceptionInInitialize;
}
@Named("exception")
public static class TestProviderWithExceptionInInitialize implements Provider<String> , Initializable {
@Override
public void initialize() throws InitializationException {
throw new InitializationException("Some error in init");
}
@Override
public String get() {
throw new RuntimeException("should not be called!");
}
}
@Test(timeout = 10000)
public void loadAndInjectProviders_remove98_failAssert0() throws ComponentLookupException, ComponentRepositoryException {
// AssertionGenerator generate try/catch block with fail statement
try {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
// Register components for the list and map
DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role> cd1 = new DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role>();
cd1.setRoleType(EmbeddableComponentManagerTest.Role.class);
cd1.setRoleHint("hint1");
cd1.setImplementation(EmbeddableComponentManagerTest.RoleImpl.class);
cm.registerComponent(cd1);
DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role> cd2 = new DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role>();
cd2.setRoleType(EmbeddableComponentManagerTest.Role.class);
cd2.setRoleHint("hint2");
cm.registerComponent(cd2);
// Initialize
cm.initialize(getClass().getClassLoader());
TestComponentWithProviders component = cm.getInstance(TestComponentRole.class);
component.provider1.get();
component.provider12.get();
Integer.valueOf(1);
component.provider2.get();
component.providerList.get().size();
component.providerMap.get().size();
Assert.fail("loadAndInjectProviders_remove98 should have thrown RuntimeException");
} catch (RuntimeException expected) {
Assert.assertEquals("Failed to get [role = [java.util.List<org.xwiki.component.embed.EmbeddableComponentManagerTest$Role>] hint = [default]]", expected.getMessage());
}
}
/**
* Verify that an exception is raised when a Provider implementing {@link Initializable} fails to initialize.
*/
@Test(timeout = 10000)
public void loadAndInjectProviderWhenExceptionInInitialize_failAssert0() throws Exception {
// AssertionGenerator generate try/catch block with fail statement
try {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(getClass().getClassLoader());
{
cm.getInstance(TestComponentRole.class, "exception");
}
Assert.fail("loadAndInjectProviderWhenExceptionInInitialize should have thrown ComponentLookupException");
} catch (ComponentLookupException expected) {
Assert.assertEquals("Failed to lookup component [org.xwiki.component.AmplProviderTest$TestComponentWithProviderInException] identified by type [interface org.xwiki.component.AmplProviderTest$TestComponentRole] and hint [exception]", expected.getMessage());
}
}
/**
* Verify that an exception is raised when a Provider implementing {@link Initializable} fails to initialize.
*/
@Test(timeout = 10000)
public void loadAndInjectProviderWhenExceptionInInitializenull24() throws Exception {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
// AssertionGenerator add assertion
Assert.assertNull(((EmbeddableComponentManager) (cm)).getParent());
// AssertionGenerator add assertion
Assert.assertNull(((EmbeddableComponentManager) (cm)).getNamespace());
// AssertionGenerator add assertion
Assert.assertNull(((EmbeddableComponentManager) (cm)).getComponentEventManager());
cm.initialize(getClass().getClassLoader());
{
cm.getInstance(TestComponentRole.class, null);
}
// AssertionGenerator add assertion
Assert.assertNull(((EmbeddableComponentManager) (cm)).getParent());
// AssertionGenerator add assertion
Assert.assertNull(((EmbeddableComponentManager) (cm)).getNamespace());
// AssertionGenerator add assertion
Assert.assertNull(((EmbeddableComponentManager) (cm)).getComponentEventManager());
}
}
When building the module it fails with:
[INFO] Running org.xwiki.component.AmplProviderTest
[ERROR] Tests run: 3, Failures: 1, Errors: 2, Skipped: 0, Time elapsed: 0.011 s <<< FAILURE! - in org.xwiki.component.AmplProviderTest
[ERROR] loadAndInjectProviders_remove98_failAssert0 Time elapsed: 0.006 s <<< ERROR!
org.xwiki.component.manager.ComponentLookupException: Can't find descriptor for the component with type [interface org.xwiki.component.AmplProviderTest$TestComponentRole] and hint [null]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:212)
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:189)
at org.xwiki.component.AmplProviderTest.loadAndInjectProviders_remove98_failAssert0(AmplProviderTest.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
[ERROR] loadAndInjectProviderWhenExceptionInInitializenull24 Time elapsed: 0.002 s <<< ERROR!
org.xwiki.component.manager.ComponentLookupException: Can't find descriptor for the component with type [interface org.xwiki.component.AmplProviderTest$TestComponentRole] and hint [null]
at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:212)
at org.xwiki.component.AmplProviderTest.loadAndInjectProviderWhenExceptionInInitializenull24(AmplProviderTest.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
[ERROR] loadAndInjectProviderWhenExceptionInInitialize_failAssert0 Time elapsed: 0.003 s <<< FAILURE!
org.junit.ComparisonFailure: expected:<[Failed to lookup component [org.xwiki.component.AmplProviderTest$TestComponentWithProviderInException] identified by] type [interface org...> but was:<[Can't find descriptor for the component with] type [interface org...>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at org.xwiki.component.AmplProviderTest.loadAndInjectProviderWhenExceptionInInitialize_failAssert0(AmplProviderTest.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] AmplProviderTest.loadAndInjectProviderWhenExceptionInInitialize_failAssert0:159 expected:<[Failed to lookup component [org.xwiki.component.AmplProviderTest$TestComponentWithProviderInException] identified by] type [interface org...> but was:<[Can't find descriptor for the component with] type [interface org...>
[ERROR] Errors:
[ERROR] AmplProviderTest.loadAndInjectProviderWhenExceptionInInitializenull24:177 » ComponentLookup
[ERROR] AmplProviderTest.loadAndInjectProviders_remove98_failAssert0:132 » ComponentLookup
[INFO]
[ERROR] Tests run: 46, Failures: 1, Errors: 2, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
What I don't understand is how can Dspot execute this test and have it kill more mutants when it doesn't execute with Maven. I guess it means there's some differences in the classpath or somewhere else?
The reason the test is not passing is because it's missing some component registration in components.txt. So that part is normal.
What is not normal is that DSpot considers that the generated tests is ok. It should discard it because it doesn't run...
I still don't get how it can say it increased the mutation score without running them. And if it did run them, how did it succeed, since that's not possible :)
FWIW to fix the test you need to modify the existing src/test/resources/components.txt and add at the bottom:
org.xwiki.component.AmplProviderTest$TestComponentWithProviders
org.xwiki.component.AmplProviderTest$TestProvider1
org.xwiki.component.AmplProviderTest$TestProvider12
org.xwiki.component.AmplProviderTest$TestProvider2
org.xwiki.component.AmplProviderTest$TestComponentWithProviderInException
org.xwiki.component.AmplProviderTest$TestProviderWithExceptionInInitialize
My guess is that it worked because when DSpot executed, it used the same test class name and it renamed it afterwards... leading to the problem...
Second problem. Even if we add what I mentioned at #897 (comment) the test suite is still failing because it means registering several times the same role with the same hint!!!
So we get:
[INFO] Running org.xwiki.component.ProviderTest
14:44:46.328 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProvider1] which implements [role = [javax.inject.Provider<java.lang.String>] hint = [default]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProvider1]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.332 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProvider12] which implements [role = [javax.inject.Provider<java.lang.String>] hint = [another]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProvider12]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.332 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProvider2] which implements [role = [javax.inject.Provider<java.lang.Integer>] hint = [default]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProvider2]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.332 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProviderWithExceptionInInitialize] which implements [role = [javax.inject.Provider<java.lang.String>] hint = [exception]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProviderWithExceptionInInitialize]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.338 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProvider1] which implements [role = [javax.inject.Provider<java.lang.String>] hint = [default]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProvider1]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.339 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProvider12] which implements [role = [javax.inject.Provider<java.lang.String>] hint = [another]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProvider12]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.339 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProvider2] which implements [role = [javax.inject.Provider<java.lang.Integer>] hint = [default]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProvider2]. However, no action was taken since both components have the same priority level of [1000].
14:44:46.339 [main] WARN o.x.c.a.ComponentAnnotationLoader - Component [org.xwiki.component.AmplProviderTest$TestProviderWithExceptionInInitialize] which implements [role = [javax.inject.Provider<java.lang.String>] hint = [exception]] tried to overwrite component [org.xwiki.component.ProviderTest$TestProviderWithExceptionInInitialize]. However, no action was taken since both components have the same priority level of [1000].
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.018 s - in org.xwiki.component.ProviderTest
[INFO] Running org.xwiki.component.annotation.ComponentDescriptorFactoryTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 s - in org.xwiki.component.annotation.ComponentDescriptorFactoryTest
[INFO] Running org.xwiki.component.annotation.ComponentAnnotationLoaderTest
[ERROR] Tests run: 8, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.03 s <<< FAILURE! - in org.xwiki.component.annotation.ComponentAnnotationLoaderTest
[ERROR] testPriorities Time elapsed: 0.029 s <<< FAILURE!
org.opentest4j.MultipleFailuresError:
Multiple Failures (2 failures)
java.lang.AssertionError: unexpected invocation: logger.warn("Component [{}] which implements [{}] tried to overwrite component [{}]. However, no action was taken since both components have the same priority level of [{}].", ["org.xwiki.component.AmplProviderTest$TestProvider1", <role = [javax.inject.Provider<java.lang.String>] hint = [default]>, "org.xwiki.component.ProviderTest$TestProvider1", <1000>])
expectations:
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.annotation.ComponentAnnotationLoaderTest$NotGenericRole], hint = [deprecated]], implementation = [org.xwiki.component.annotation.ComponentAnnotationLoaderTest$DeprecatedOverrideRole], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.manager.ComponentManager], hint = [root]], implementation = [org.xwiki.component.internal.RootComponentManager], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.annotation.ComponentAnnotationLoaderTest$NotGenericRole], hint = [test]], implementation = [org.xwiki.component.annotation.ComponentAnnotationLoaderTest$OverrideRole], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.internal.multi.ComponentManagerFactory], hint = [default]], implementation = [org.xwiki.component.internal.embed.EmbeddableComponentManagerFactory], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.internal.multi.ComponentManagerManager], hint = [default]], implementation = [org.xwiki.component.internal.multi.DefaultComponentManagerManager], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<org.xwiki.component.manager.ComponentManager>], hint = [context]], implementation = [org.xwiki.component.internal.ContextComponentManagerProvider], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.namespace.NamespaceValidator], hint = [default]], implementation = [org.xwiki.component.internal.namespace.DefaultNamespaceValidator], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.String>], hint = [default]], implementation = [org.xwiki.component.ProviderTest$TestProvider1], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.String>], hint = [another]], implementation = [org.xwiki.component.ProviderTest$TestProvider12], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.Integer>], hint = [default]], implementation = [org.xwiki.component.ProviderTest$TestProvider2], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.ProviderTest$TestComponentRole], hint = [default]], implementation = [org.xwiki.component.ProviderTest$TestComponentWithProviders], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.String>], hint = [exception]], implementation = [org.xwiki.component.ProviderTest$TestProviderWithExceptionInInitialize], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.ProviderTest$TestComponentRole], hint = [exception]], implementation = [org.xwiki.component.ProviderTest$TestComponentWithProviderInException], instantiation = [SINGLETON]>)
what happened before this: nothing!
java.lang.AssertionError: unexpected invocation: logger.warn("Component [{}] which implements [{}] tried to overwrite component [{}]. However, no action was taken since both components have the same priority level of [{}].", ["org.xwiki.component.AmplProviderTest$TestProvider1", <role = [javax.inject.Provider<java.lang.String>] hint = [default]>, "org.xwiki.component.ProviderTest$TestProvider1", <1000>])
expectations:
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.annotation.ComponentAnnotationLoaderTest$NotGenericRole], hint = [deprecated]], implementation = [org.xwiki.component.annotation.ComponentAnnotationLoaderTest$DeprecatedOverrideRole], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.manager.ComponentManager], hint = [root]], implementation = [org.xwiki.component.internal.RootComponentManager], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.annotation.ComponentAnnotationLoaderTest$NotGenericRole], hint = [test]], implementation = [org.xwiki.component.annotation.ComponentAnnotationLoaderTest$OverrideRole], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.internal.multi.ComponentManagerFactory], hint = [default]], implementation = [org.xwiki.component.internal.embed.EmbeddableComponentManagerFactory], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.internal.multi.ComponentManagerManager], hint = [default]], implementation = [org.xwiki.component.internal.multi.DefaultComponentManagerManager], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<org.xwiki.component.manager.ComponentManager>], hint = [context]], implementation = [org.xwiki.component.internal.ContextComponentManagerProvider], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.namespace.NamespaceValidator], hint = [default]], implementation = [org.xwiki.component.internal.namespace.DefaultNamespaceValidator], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.String>], hint = [default]], implementation = [org.xwiki.component.ProviderTest$TestProvider1], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.String>], hint = [another]], implementation = [org.xwiki.component.ProviderTest$TestProvider12], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.Integer>], hint = [default]], implementation = [org.xwiki.component.ProviderTest$TestProvider2], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.ProviderTest$TestComponentRole], hint = [default]], implementation = [org.xwiki.component.ProviderTest$TestComponentWithProviders], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [javax.inject.Provider<java.lang.String>], hint = [exception]], implementation = [org.xwiki.component.ProviderTest$TestProviderWithExceptionInInitialize], instantiation = [SINGLETON]>)
expected once, never invoked: componentManager.registerComponent(<role = [interface org.xwiki.component.ProviderTest$TestComponentRole], hint = [exception]], implementation = [org.xwiki.component.ProviderTest$TestComponentWithProviderInException], instantiation = [SINGLETON]>)
what happened before this: nothing!
at org.junit.vintage.engine.execution.TestRun.getStoredResultOrSuccessful(TestRun.java:179)
at org.junit.vintage.engine.execution.RunListenerAdapter.fireExecutionFinished(RunListenerAdapter.java:211)
at org.junit.vintage.engine.execution.RunListenerAdapter.testFinished(RunListenerAdapter.java:177)
at org.junit.vintage.engine.execution.RunListenerAdapter.testFinished(RunListenerAdapter.java:76)
at org.junit.runner.notification.SynchronizedRunListener.testFinished(SynchronizedRunListener.java:56)
at org.junit.runner.notification.RunNotifier$7.notifyListener(RunNotifier.java:190)
at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
at org.junit.runner.notification.RunNotifier.fireTestFinished(RunNotifier.java:187)
at org.junit.internal.runners.model.EachTestNotifier.fireTestFinished(EachTestNotifier.java:38)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:331)
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.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:40)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:71)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
To actually make the generated test work you need to remove all component definitions and use the ones from ProviderTest:
/**
* See the NOTICE file distributed with this work for additional information regarding copyright ownership.
* <p>
* This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any
* later version.
* <p>
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
* <p>
* You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to
* the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site:
* http://www.fsf.org.
*/
package org.xwiki.component;
import org.junit.Assert;
import org.junit.Test;
import org.xwiki.component.descriptor.DefaultComponentDescriptor;
import org.xwiki.component.embed.EmbeddableComponentManager;
import org.xwiki.component.embed.EmbeddableComponentManagerTest;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentRepositoryException;
import org.xwiki.component.phase.Initializable;
/**
* Validate loading and injection of Providers in a real use case.
*
* @version $Id: 683593067e19c75185fdb6191dd1cdd96ea36387 $
*/
public class AmplProviderTest
{
@Test(timeout = 10000)
public void loadAndInjectProviders_remove98_failAssert0()
throws ComponentLookupException, ComponentRepositoryException
{
// AssertionGenerator generate try/catch block with fail statement
try {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
// Register components for the list and map
DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role> cd1 =
new DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role>();
cd1.setRoleType(EmbeddableComponentManagerTest.Role.class);
cd1.setRoleHint("hint");
cd1.setImplementation(EmbeddableComponentManagerTest.RoleImpl.class);
cm.registerComponent(cd1);
DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role> cd2 =
new DefaultComponentDescriptor<EmbeddableComponentManagerTest.Role>();
cd2.setRoleType(EmbeddableComponentManagerTest.Role.class);
cd2.setRoleHint("hint2");
cm.registerComponent(cd2);
// Initialize
cm.initialize(getClass().getClassLoader());
ProviderTest.TestComponentWithProviders component = cm.getInstance(ProviderTest.TestComponentRole.class);
component.provider1.get();
component.provider12.get();
Integer.valueOf(1);
component.provider2.get();
component.providerList.get().size();
component.providerMap.get().size();
Assert.fail("loadAndInjectProviders_remove98 should have thrown RuntimeException");
} catch (RuntimeException expected) {
Assert.assertEquals(
"Failed to get [role = [java.util.List<org.xwiki.component.embed.EmbeddableComponentManagerTest$Role>] hint = [default]]",
expected.getMessage());
}
}
/**
* Verify that an exception is raised when a Provider implementing {@link Initializable} fails to initialize.
*/
@Test(timeout = 10000)
public void loadAndInjectProviderWhenExceptionInInitialize_failAssert0() throws Exception
{
// AssertionGenerator generate try/catch block with fail statement
try {
EmbeddableComponentManager cm = new EmbeddableComponentManager();
cm.initialize(getClass().getClassLoader());
{
cm.getInstance(ProviderTest.TestComponentRole.class, "exception");
}
Assert.fail("loadAndInjectProviderWhenExceptionInInitialize should have thrown ComponentLookupException");
} catch (ComponentLookupException expected) {
Assert.assertEquals(
"Failed to lookup component [org.xwiki.component.ProviderTest$TestComponentWithProviderInException] identified by type [interface org.xwiki.component.ProviderTest$TestComponentRole] and hint [exception]",
expected.getMessage());
}
}
/**
* Verify that an exception is raised when a Provider implementing {@link Initializable} fails to initialize.
*/
@Test(timeout = 10000)
public void loadAndInjectProviderWhenExceptionInInitializenull24() throws Exception
{
EmbeddableComponentManager cm = new EmbeddableComponentManager();
// AssertionGenerator add assertion
Assert.assertNull(cm.getParent());
// AssertionGenerator add assertion
Assert.assertNull(cm.getNamespace());
// AssertionGenerator add assertion
Assert.assertNull(cm.getComponentEventManager());
cm.initialize(getClass().getClassLoader());
{
cm.getInstance(ProviderTest.TestComponentRole.class, null);
}
// AssertionGenerator add assertion
Assert.assertNull(cm.getParent());
// AssertionGenerator add assertion
Assert.assertNull(cm.getNamespace());
// AssertionGenerator add assertion
Assert.assertNull(cm.getComponentEventManager());
}
}
Hello @vmassol
My guess is that it worked because when DSpot executed, it used the same test class name and it renamed it afterwards... leading to the problem...
That is true. DSpot renames (or not if you use the flag --generate-new-test-class
) the test class just before to print it out at the end of the amplification process.
We agree that the mechanism of the components comes from XWiki, and DSpot does not have to deal with it, right?
We agree that the mechanism of the components comes from XWiki, and DSpot does not have to deal with it, right?
Well it could with some extensions I guess but yes I agree. Now, as I said above, the problem here is that it's wrong to claim victory by DSpot, leading to false positive results. Basically you shouldn't generate something that has not been tested. So either the flag you mentioned is on and Dspot should use the new test class name in its execution or it's not and dspot can use the original test class name. WDYT?
that it's wrong to claim victory by DSpot, leading to false positive results.
You mean that even if you set up the components correctly, you do not observe the mutations score increase reported by DSpot?
Basically you shouldn't generate something that has not been tested.
DSpot does run the test three times to obtain the assertions and PIT does also to compute the mutation score. Meaning that the test is executable, and thus should pass, right?
ERRATUM: I made a mistake about the flag: by default this flag is disabled, and so DSpot does NOT rename the test class at the end of the process.
It will rename the amplified test class if you enable --generate-new-test-class
, and adds Ampl as a prefix or suffix, depending on the original test class name.
You mean that even if you set up the components correctly, you do not observe the mutations score increase reported by DSpot?
It's not only about setting up the components correctly, it's about having to rewrite the test because the name of the test class can influence a lot the writing of the test.
I'll repeat what I said above: IMO when you use --generate-new-test-class
then DSpot should use the new name when it executes and it shouldn't rename the test class AFTER it's finished, as otherwise it generates some tests that cannot work and that are thus not useful, i.e. it generates false positives. IMO it's better to generate less results but results that can be used. If you have to spend 1 hour to rewrite the test (which is what I did) to get a test that, if you read it, is not very useful, then you're spending too much time.
Or if you disagree, then at least offer a flag to do this, because remember that on XWiki our goal is to automate the generation of tests by DSpot and to commit them automatically so if they don't pass, it'll fail our build badly.
Hope it's more clear now.
Thanks!
IMO when you use --generate-new-test-class then DSpot should use the new name when it executes
I'm okay to do that.
But I have a question: does the early renaming will make impossible to execute the test? We still have to add the new name to the components list, right?
But I have a question: does the early renaming will make impossible to execute the test? We still have to add the new name to the components list, right?
It means that for some tests, the early renaming will just make the test execution fail because of the name and the test should be discarded, that's all.