@Test
public void testListByDataCenterIdVMTypeAndStates() {

    // Prepare
    final VMInstanceVO vmInstanceVO = mock(VMInstanceVO.class);
    final SearchBuilder<VMInstanceVO> vmInstanceSearch = mock(SearchBuilder.class);
    when(mockVmDao.createSearchBuilder()).thenReturn(vmInstanceSearch);
    when(vmInstanceSearch.entity()).thenReturn(vmInstanceVO);
    when(vmInstanceVO.getType()).thenReturn(VirtualMachine.Type.Instance);
    when(vmInstanceVO.getState()).thenReturn(VirtualMachine.State.Stopped);
    when(vmInstanceVO.getPodIdToDeployIn()).thenReturn(POD_ID1);
    final SearchBuilder<HostPodVO> podIdSearch = mock(SearchBuilder.class);
    when(mockPodDao.createSearchBuilder()).thenReturn(podIdSearch);
    final SearchCriteria<HostPodVO> sc = mock(SearchCriteria.class);
    final HostPodVO hostPodVO = mock(HostPodVO.class);
    when(podIdSearch.entity()).thenReturn(hostPodVO);
    when(hostPodVO.getId()).thenReturn(POD_ID1);
    when(hostPodVO.getDataCenterId()).thenReturn(DATA_CENTER_ID);
    when(podIdSearch.create()).thenReturn(sc);
    final List<HostPodVO> expectedPods = mock(List.class);
    when(mockPodDao.search(sc, null)).thenReturn(expectedPods);
    // Execute
    final List<HostPodVO> pods = deployment.listByDataCenterIdVMTypeAndStates(DATA_CENTER_ID,
            VirtualMachine.Type.User,
            VirtualMachine.State.Starting,
            VirtualMachine.State.Running);
    // Assert
    assertNotNull(pods);
    assertEquals(expectedPods, pods);
    verify(sc, times(1)).setParameters("dc", DATA_CENTER_ID);
    verify(sc, times(1)).setJoinParameters("vmInstanceSearch", "type", VirtualMachine.Type.User);
    verify(sc, times(1)).setJoinParameters("vmInstanceSearch", "states",
            VirtualMachine.State.Starting, VirtualMachine.State.Running);
    verify(mockPodDao, times(1)).search(sc, null);
}