@Test
public void testGetActiveDomain() {

    String taskType = "test-task";
    String[] domains = new String[]{"domain1", "domain2"};
    PollData pollData1 = new PollData("queue1", domains[0], "worker1", System.currentTimeMillis() - 99 * 1000);
    when(executionDAOFacade.getTaskPollDataByDomain(taskType, domains[0])).thenReturn(pollData1);
    String activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertEquals(domains[0], activeDomain);
    Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
    PollData pollData2 = new PollData("queue2", domains[1], "worker2", System.currentTimeMillis() - 99 * 1000);
    when(executionDAOFacade.getTaskPollDataByDomain(taskType, domains[1])).thenReturn(pollData2);
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertEquals(domains[1], activeDomain);
    Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertEquals(domains[1], activeDomain);
    domains = new String[]{""};
    when(executionDAOFacade.getTaskPollDataByDomain(any(), any())).thenReturn(new PollData());
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNotNull(activeDomain);
    assertEquals("", activeDomain);
    domains = new String[]{};
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNull(activeDomain);
    activeDomain = workflowExecutor.getActiveDomain(taskType, null);
    assertNull(activeDomain);
    domains = new String[]{"test-domain"};
    when(executionDAOFacade.getTaskPollDataByDomain(anyString(), anyString())).thenReturn(null);
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNotNull(activeDomain);
    assertEquals("test-domain", activeDomain);
}