@Before
  public void setUp() {
    networkDeviceHelper =
        new NetworkDeviceHelperImpl(interfaceDao, hostDeviceDao, hostNicVfsConfigDao, vdsDao);

    when(netDevice.getHostId()).thenReturn(HOST_ID);
    when(netDevice.getDeviceName()).thenReturn(NET_DEVICE_NAME);
    when(netDevice.getName()).thenReturn(NET_DEVICE_NAME);
    when(netDevice.getNetworkInterfaceName()).thenReturn(NIC_NAME);
    when(netDevice.getParentDeviceName()).thenReturn(PCI_DEVICE_NAME);

    when(pciDevice.getHostId()).thenReturn(HOST_ID);
    when(pciDevice.getDeviceName()).thenReturn(PCI_DEVICE_NAME);
    when(pciDevice.getName()).thenReturn(PCI_DEVICE_NAME);

    List<HostDevice> devices = new ArrayList<>();
    devices.add(netDevice);
    devices.add(pciDevice);
    mockHostDevices(devices);

    when(nic.getId()).thenReturn(NIC_ID);
    when(nic.getName()).thenReturn(NIC_NAME);
    when(nic.getVdsId()).thenReturn(HOST_ID);
    when(interfaceDao.get(NIC_ID)).thenReturn(nic);
    when(nic.getName()).thenReturn(NIC_NAME);

    when(hostNicVfsConfig.getNicId()).thenReturn(NIC_ID);
    when(hostNicVfsConfigDao.getByNicId(NIC_ID)).thenReturn(hostNicVfsConfig);
  }
  private VdsNetworkInterface mockNicForNetDevice(HostDevice netDeviceParam) {
    VdsNetworkInterface nic = new VdsNetworkInterface();
    nic.setVdsId(netDeviceParam.getHostId());
    nic.setName(netDeviceParam.getNetworkInterfaceName());

    return nic;
  }
  @Test
  public void getNicByNetDeviceNoNic() {
    VdsNetworkInterface newNic = new VdsNetworkInterface();
    newNic.setName(netDevice.getNetworkInterfaceName() + "not");
    mockNics(Collections.singletonList(newNic), false);

    assertNull(networkDeviceHelper.getNicByPciDevice(pciDevice));
  }
  @Test
  public void testGetVfMap() {
    final HostDevice pfNetDevice = new HostDevice();
    final HostDevice pfPciDevice = new HostDevice();

    final Guid pfNicId = Guid.newGuid();
    final String pfNicName = "pf" + NIC_NAME;
    final String pfPciDeviceName = "pf" + PCI_DEVICE_NAME;

    pfNetDevice.setHostId(HOST_ID);
    pfNetDevice.setDeviceName("pf" + NET_DEVICE_NAME);
    pfNetDevice.setNetworkInterfaceName(pfNicName);
    pfNetDevice.setParentDeviceName(pfPciDeviceName);

    pfPciDevice.setHostId(HOST_ID);
    pfPciDevice.setDeviceName(pfPciDeviceName);
    pfPciDevice.setDeviceName(pfPciDeviceName);

    when(pciDevice.getParentPhysicalFunction()).thenReturn(pfPciDeviceName);
    mockHostDevices(Arrays.asList(pfNetDevice, pfPciDevice, new HostDevice()));

    when(nic.getVlanId()).thenReturn(null);
    final VdsNetworkInterface pfNic = new VdsNetworkInterface();
    pfNic.setId(pfNicId);
    pfNic.setName(pfNetDevice.getNetworkInterfaceName());
    final VdsNetworkInterface bondNic = new VdsNetworkInterface();
    bondNic.setBonded(true);
    final VdsNetworkInterface vlanNic = new VdsNetworkInterface();
    vlanNic.setVlanId(666);
    mockNics(Arrays.asList(pfNic, bondNic, vlanNic), true);

    mockHostSupportsSriov(true);

    final Map<Guid, Guid> actual = networkDeviceHelper.getVfMap(HOST_ID);

    assertEquals(1, actual.size());
    assertThat(actual, hasEntry(NIC_ID, pfNicId));
  }