Mocking Workflow.getWorkflowExecution method

Hello! I have a Parent workflow with a child workflow that runs asynchronous, like:

 // some code
...
ChildWF child = Workflow.newChildWorkflowStub(ChildWF.class,
                ChildWorkflowOptions.newBuilder()
                        .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
                        .setCronSchedule(cronSched)
                        .setWorkflowId(workflowId)
                        .build());
        Async.procedure(child::childWFMethod, param);
        try {
        	Promise<WorkflowExecution> childPromise = Workflow.getWorkflowExecution(child);
            childPromise.get();
        } catch (ChildWorkflowFailure ex) {
            if (ex.getCause() instanceof WorkflowExecutionAlreadyStarted) {
                logger.error("whatever");
            }
        } catch (Exception ex) {
        	logger.error("whatever");
        }
// end parent wf

Then I want to test the failure of the child wf, so in my test I tried to mock the Workflow.getWorkflowExecution(child) to throw an exception, but I am not able to make it work.

// previous mocked activities definition, TestWorkflowExtension, ActivityStubFactory and so...

		worker.registerWorkflowImplementationFactory(ParentWF.class, () -> {
            var workflow = new ParentWFImpl(params);
            this.factory.inject(workflow, workflow.getClass());
            return workflow;
        });
		
		worker.registerWorkflowImplementationFactory(ChildWF.class, () -> {
			var childworkflow = mock(ChildWF.class);
			Mockito.doNothing().when(childworkflow).childWFMethod(Mockito.any());
            this.factory.inject(childworkflow, ChildWF.class);
            return childworkflow;
        });	
		
		var parentWorkflow = testEnv.getWorkflowClient().newWorkflowStub(ParentWF.class,
				WorkflowOptions.newBuilder().setTaskQueue(worker.getTaskQueue()).setWorkflowId("test").build());
		
		RuntimeException runtimeException = new RuntimeException("test error");
		try (MockedStatic<Workflow> wf = Mockito.mockStatic(Workflow.class)) {
			wf.when(() -> Workflow.getWorkflowExecution(childWF)).thenThrow(runtimeException);
			Assertions.assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> Workflow.getWorkflowExecution(childWF));
		}
		
		testEnv.start();
		
		Assertions.assertThatCode(() -> parentWorkflow.parentWFMethod(someParam)).doesNotThrowAnyException();

When I run the test, I have it green, like succesfull, but when I launch the coverage or debug it, I see that never enter in the exceptions part, that is what I want to test.
Is there something I am missing, thanks.

Then I want to test the failure of the child wf

Are you specifically trying to test possible failures of starting the child execution due to workflow id
reuse policy? You could in your test just start a workflow execution with same workflow id as the child this parent is trying to start async. Then make sure parent handles ChildWorkflowFailure (which should have cause WorkflowExecutionAlreadyStarted as you correctly state in code).

Yes I tried that also, but cant get the error I want. I did something like:

//something previous
...
var childWF = testEnv.getWorkflowClient().newWorkflowStub(ChildWF.class,
WorkflowOptions.newBuilder().setTaskQueue(worker.getTaskQueue()).setWorkflowId(CHILD_WORKFLOW_ID).build());

var workflow = testEnv.getWorkflowClient().newWorkflowStub(ParentWF.class,
WorkflowOptions.newBuilder().setTaskQueue(worker.getTaskQueue()).setWorkflowId("test").build());

childWF.childWFMethod(param);
parentWF.parentWFMethod(param);

Mockito.verify(this.ChildWFActivities, Mockito.times(1)).childWFActivityMethod(param);
testEnv.close();

And I have The workflow id mocked so every childwf that started in the parent, will have the same id as in the test.
And temporal logs show that the child is executed more than once. The first time because of the direct execution in the test, and then one more time, with same workflow Id, when the parent creates.