@Test(expected = TerminateWorkflowException.class)
public void testExceptionWhenWorkflowDefinitionNotAvailable() {

    String nameTaskDefinition = "taskSubworkflow8";
    String workflowDefinitionName = "subworkflow";
    WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition);
    workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName(workflowDefinitionName);
    workflowTask.setSubWorkflowParam(subWorkflowParams);
    WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation");
    workflowDefinition.setTasks(ImmutableList.of(workflowTask));
    when(metadataDAO.getLatestWorkflowDef(workflowDefinitionName)).thenReturn(Optional.empty());
    metadataMapperService.populateTaskDefinitions(workflowDefinition);
    verify(metadataDAO).getLatestWorkflowDef(workflowDefinitionName);
}