camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eirilwan <>
Subject Using mockito to mock endpoint behavior
Date Thu, 27 May 2010 12:51:20 GMT


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=""/>

The code we try to test is: 
                .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

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. 

Eirik L. Wang

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message