private void processPortRemoved(Port port) {
        ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());

        Set<Host> hosts = hostService.getConnectedHosts(connectPoint);

        hosts.forEach(h -> {
            Optional<HostLocation> hostLocation = h.locations().stream()
                    .filter(l -> l.deviceId().equals(port.element().id()))
                    .filter(l -> l.port().equals(port.number())).findAny();

            // if the host contains only one filtered location, we remove the host
            if (h.locations().size() == 1) {
                hostProviderService.hostVanished(h.id());
            }

            // if the host contains multiple locations, we simply remove the
            // host location
            if (h.locations().size() > 1 && hostLocation.isPresent()) {
                hostProviderService.removeLocationFromHost(h.id(), hostLocation.get());
            }
        });
    }
@Test
    public void testProcessPortRemoved() {
        org.onosproject.net.Port addedPort = new DefaultPort(DEV1, P1, true, ANNOTATIONS);
        DeviceEvent addedEvent = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV1, addedPort);

        target.portAddedHelper(addedEvent);

        org.onosproject.net.Port removedPort = new DefaultPort(DEV2, P1, true, ANNOTATIONS);
        DeviceEvent removedEvent = new DeviceEvent(DeviceEvent.Type.PORT_REMOVED, DEV2, removedPort);

        target.portRemovedHelper(removedEvent);

        assertNull(target.hostService.getHost(HostId.hostId(HOST_MAC)));
    }