package org.camunda.bpm.extension.junit5.registerExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.ProcessEngineConfiguration;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.extension.junit5.test.ProcessEngineExtension;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.RegisterExtension;

@TestInstance(Lifecycle.PER_CLASS)
public class RegisterNewProcessEngineTest {
  
  private ProcessEngine testEngine = ProcessEngineConfiguration
      .createStandaloneInMemProcessEngineConfiguration()
      .setProcessEngineName("testEngine")
      .buildProcessEngine();
  
  @RegisterExtension
  ProcessEngineExtension extension = ProcessEngineExtension.builder()
      .useProcessEngine(testEngine)
      .build();
  
  @AfterAll
  public void closeProcessEngine() {
    testEngine.close();
  }
  
  @Test
  @Deployment(resources = "processes/subProcess.bpmn")
  public void testUseProcessEngine() {
    RuntimeService runtimeService = testEngine.getRuntimeService();
    runtimeService.startProcessInstanceByKey("subProcess");
    TaskService taskService = testEngine.getTaskService();
    assertEquals(1, taskService.createTaskQuery().list().size());
  }

}

@@ -531,168 +531,37 @@
 api.
-TestInstance;%0Aimport org.junit.jupiter.api.TestInstance.Lifecycle;%0Aimport org.junit.jupiter.api.extension.RegisterExtension;%0A%0A@TestInstance(Lifecycle.PER_CLASS)
+extension.RegisterExtension;%0A
 %0Apub
@@ -614,16 +614,23 @@
 private 
+static 
 ProcessE
@@ -774,16 +774,201 @@
 ngine%22)%0A
+      // Use a new database to resolve the conflict with existing %0A      // in-memory-database. The tables will be removed after the test.%0A      .setJdbcUrl(%22jdbc:h2:mem:camunda-test%22)%0A
       .b
@@ -1154,24 +1154,31 @@
 ll%0A  public 
+static 
 void closePr

use another database