@Test
public void testMetadataPopulationOnlyOnNecessaryWorkflowTasks() {

    String nameTaskDefinition1 = "task4";
    TaskDef taskDefinition = createTaskDefinition(nameTaskDefinition1);
    WorkflowTask workflowTask1 = createWorkflowTask(nameTaskDefinition1);
    workflowTask1.setTaskDefinition(taskDefinition);
    String nameTaskDefinition2 = "task5";
    WorkflowTask workflowTask2 = createWorkflowTask(nameTaskDefinition2);
    WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation");
    workflowDefinition.setTasks(ImmutableList.of(workflowTask1, workflowTask2));
    when(metadataDAO.getTaskDef(nameTaskDefinition2)).thenReturn(taskDefinition);
    metadataMapperService.populateTaskDefinitions(workflowDefinition);
    assertEquals(2, workflowDefinition.getTasks().size());
    List<WorkflowTask> workflowTasks = workflowDefinition.getTasks();
    assertNotNull(workflowTasks.get(0).getTaskDefinition());
    assertNotNull(workflowTasks.get(1).getTaskDefinition());
    verify(metadataDAO).getTaskDef(nameTaskDefinition2);
    verifyNoMoreInteractions(metadataDAO);
}