title: Spring Boot: inserting mock Bean into Camel Processor unit test
body: <p>I have a Camel Processor in a Spring Boot application that I am trying to write unit test for. The processor class looks like this:</p>
  
  <pre><code>@Named
  public class MyProcessor implements Processor {
      @Inject
      private MyService myService;
  
      @Override
      public void process(Exchange exchange) {
         ...
      }
  }
  </code></pre>
  
  <p>I am trying to inject a mock MyService object into a unit test.</p>
  
  <p>I have tried this:</p>
  
  <pre><code>@RunWith(CamelSpringRunner.class)
  @SpringBootTest
  public class MyProcessorTest {
      @TestConfiguration
      static class Config {
          @Autowired
          private MyProcessor myProcessor;
  
          @Bean
          CamelContextConfiguration myProcessorTestContextConfiguration() {
              return new CamelContextConfiguration() {
                  @Override
                  public void beforeApplicationStart(CamelContext camelContext) {
                      MyService myService = Mockito.mock(MyService.class);
                      camelContext.addService(myService);
                      ...
  </code></pre>
  
  <p>... but that doesn't seem to work - a non-mocked instance of MyService is injected into the processor. I think the issue is because my mocked service object is created in the Camel context, rather than via Spring.</p>
  
  <p>Can anyone advise as to the correct approach here?</p>
  
  <p>Thanks in advance for any assistance.</p>