title: Сamunda replace behaviour for external tasks in tests
body: <p>I created simple Camunda spring boot project and also created <a href="https://github.com/Kejam/camunda-test/blob/master/src/main/resources/process.bpmn" rel="nofollow noreferrer">simple BPMN process</a> with switcher.  (5.5 KB)</p>
  <p>I used service task with external implementation as a spring beans. I want to write tests for process but I don't want to test how beans works. Because in general I use external implementation for connection to DB and save parameter to context or REST call to internal apps. For example I want skip execute service task(one) and instead set variables for switcher. I tried to use camunda-bpm-assert-scenario for test process and wrote simple test WorkflowTest.</p>
  <p>I noticed if I use @MockBean for One.class then Camunda skip delegate execution. If use @Mock then Camunda execute delegate execution.</p>
  <p>PS Sorry for bad english</p>
  <p>One</p>
  <blockquote>
  <p>@Service
  public class One implements JavaDelegate {
  private final Random random = new Random();</p>
  <pre><code>@Override
  public void execute(DelegateExecution execution) throws Exception {
      System.out.println(&quot;Hello, One!&quot;);
      execution.setVariable(&quot;check&quot;, isValue());
  }
  
  public boolean isValue() {
      return random.nextBoolean();
  }
  </code></pre>
  <p>}</p>
  </blockquote>
  <p>WorkflowTest</p>
  <blockquote>
  <p>@SpringBootTest
  @RunWith(SpringRunner.class)
  @Deployment(resources = &quot;process.bpmn&quot;)
  public class WorkflowTest extends AbstractProcessEngineRuleTest {</p>
  <pre><code>@Mock
  private ProcessScenario insuranceApplication;
  
  @MockBean
  private One one;
  
  @Before
  public void init() {
      MockitoAnnotations.initMocks(this);
      Mocks.register(&quot;one&quot;, one);
  }
  
  @Test
  public void shouldExecuteHappyPath() throws Exception {
      // given
      when(insuranceApplication.waitsAtServiceTask(&quot;Task_generator&quot;)).thenReturn(externalTaskDelegate -&gt; {
                  externalTaskDelegate.complete(withVariables(&quot;check&quot;, true));
              }
      );
  
      String processDefinitionKey = &quot;camunda-test-process&quot;;
      Scenario scenario = Scenario.run(insuranceApplication)
              .startByKey(processDefinitionKey) // either just start process by key ...
              .execute();
  
      verify(insuranceApplication).hasFinished(&quot;end_true&quot;);
      verify(insuranceApplication, never()).hasStarted(&quot;three&quot;);
      verify(insuranceApplication, atLeastOnce()).hasStarted(&quot;two&quot;);
  
      assertThat(scenario.instance(insuranceApplication)).variables().containsEntry(&quot;check&quot;, true);
  }
  </code></pre>
  <p>}</p>
  </blockquote>