To get a code coverage report, I use the @Decorator bean plugin cobertura maven. When running my unit test in an OpenEJB container. The container reports some error during startup (new initial context).
Invokes: org.apache.webbeans.exception.WebBeansConfigurationException: Decorator: MyDecorator, Name: null, WebBeans Type: DECORATOR, API Types: [org.apache.commo ns.configuration.Configuration, net.sourceforge.cobertura.coveragedata.HasBeenmentment org.apache.commons.configuration.AbstractConfiguration, MyDecorator, org.apache.commons.configuration.event.EventSource, java.lang.Object], Qualifiers: [javax.enterprise.inject.Any, javax.enterprise.inject.Default] The delegate must implement all decorated decorated types, but the interface of the decorator type net.sourceforge.cobertura.coveragedata.HasBeenInstrumented cannot be assigned to the delegate ate interface type org.apache.commons.configuration.Configuration
Details:
I have one Decorator for testing a device. Sort of
import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.Configuration;
@Decorator
public class MyDecorator extends AbstractConfiguration {
@Inject @Delegate private Configuration conf;
.....
}
After cobertura measured it, the code is as follows: (I destroy it)
import net.sourceforge.cobertura.coveragedata.HasBeenInstrumented;
@Decorator
public class MyDecorator extends AbstractConfiguration implements HasBeenInstrumented {
@Inject @Delegate private Configuration conf;
.....
}
As you can see, cobertura adds another interface to my decorator. When OpenEJB loads and deploys this tool class, an error is reported:
Invokes: org.apache.webbeans.exception.WebBeansConfigurationException: Decorator: MyDecorator, Name: null, WebBeans Type: DECORATOR, API Types: [org.apache.commo ns.configuration.Configuration, net.sourceforge.cobertura.coveragedata.HasBeenmentment org.apache.commons.configuration.AbstractConfiguration, MyDecorator, org.apache.commons.configuration.event.EventSource, java.lang.Object], Qualifiers: [javax.enterprise.inject.Any, javax.enterprise.inject.Default] The delegate must implement all decorated decorated types, but the interface of the decorator type net.sourceforge.cobertura.coveragedata.HasBeenInstrumented cannot be assigned to the delegate ate interface type org.apache.commons.configuration.Configuration
The error log says that @Decorator and @Delegate should implement the same types. But after the tool, the tested class has another interface.
Then I try to use org.apache.commons.configuration.AbstractConfiguration and org.apache.commons.configuration.Configuration. (using the commons-configuration-1.9.jar tool with cobertura) And change my code as:
@Decorator
public class MyDecorator extends AbstractConfiguration {
@Inject @Delegate private AbstractConfiguration conf;
.....
} // I use AbstractConfiguration instead of Configuration because Configuration is an // interface that cannot be instrumental.
After that, the problem is resolved. But this is not a good way to do this.
The main reason is the maven cobertura plugin, which identifies the class file by adding an interface to the source class, I work for most cases. But not for the @Decorator bean that runs in the container.
Should I post comments for maven-cobertura-plugin org?
Does anyone have a suggestion on how unit test @ Decorators.And can easily get a coverage report? Maybe my unit test is not implemented in a good way, maybe openejb is not suitable for this?
Usually, how do you unit test your @Decorators?