FYI, we just fix this kind of issue[1] in camel trunk yesterday.
[1] https://issues.apache.org/activemq/browse/CAMEL-2750
Willem
eirilwan wrote:
Hi
When upgrading from Camel 2.1.0 to 2.3.0 we encountered a problem using
Mockito to mock endpoint behaviour while testing camel routes.
Our test is running with junit4 using Spring context configuration. We
inject mockito mocked endpoints into both the test and the route like this:
@Produce(uri = "mock:successConsumer")
protected MockEndpoint successConsumer;
@Resource(name = "testRepo")
protected TestRepository someRepo;
The TestRepo is created in spring using XML configuration:
<bean id="someRepo" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="xxx.xxx.TestRepository"/>
</bean>
The code we try to test is:
from("direct:calveConsumer")
.bean(someRepo, "someRepoMethod").to(successConsumer)
When running the test, camel don't seem to find the someRepoMethod on the
"someRepo" bean. We have tracked down the problem to getTargetClass in
org.apache.camel.component.bean.BeanInfo.class.
Since mockito is using cglib for enhancing interfaces, this method return
the superclass of the mock, which is Object. This behaviour will work fine
when an object is enhanced with cglib, but not when you use cglib to enhance
an interface.
An solution could be to check if the class before $$ is an interface and
return it if it is.
Any thoughts?
Our solution right now is to create real mock stubs of all interfaces to
work around the problem.
regards
Eirik L. Wang