Fixing an issue with unit test mocks.

Change-Id: I5a081cc737d8c7ea9a4e0cc136f69ed9dc2ba618
diff --git a/core/api/src/test/java/org/onosproject/net/NetTestTools.java b/core/api/src/test/java/org/onosproject/net/NetTestTools.java
index 1cb7825..39b217a 100644
--- a/core/api/src/test/java/org/onosproject/net/NetTestTools.java
+++ b/core/api/src/test/java/org/onosproject/net/NetTestTools.java
@@ -93,6 +93,21 @@
         return new DefaultPath(PID, links, ids.length);
     }
 
+    // Creates a path that leads through the given devices.
+    public static Path createPath(boolean srcIsEdge, boolean dstIsEdge, String... ids) {
+        List<Link> links = new ArrayList<>();
+        for (int i = 0; i < ids.length - 1; i++) {
+            if (i == 0 && srcIsEdge) {
+                links.add(DefaultEdgeLink.createEdgeLink(host(ids[i], ids[i + 1]), true));
+            } else if (i == ids.length - 2 && dstIsEdge) {
+                links.add(DefaultEdgeLink.createEdgeLink(host(ids[i + 1], ids[i]), false));
+            } else {
+                links.add(link(ids[i], i, ids[i + 1], i));
+            }
+        }
+        return new DefaultPath(PID, links, ids.length);
+    }
+
     // Creates OCh signal
     public static OchSignal createLambda() {
         return new OchSignal(GridType.DWDM, ChannelSpacing.CHL_6P25GHZ, 8, 4);
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
index 4fe5343..b20d424 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java
@@ -21,6 +21,7 @@
 import org.onosproject.core.GroupId;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.ElementId;
+import org.onosproject.net.HostId;
 import org.onosproject.net.Link;
 import org.onosproject.net.NetTestTools;
 import org.onosproject.net.NetworkResource;
@@ -152,7 +153,7 @@
                 System.arraycopy(reversePathHops, 0, allHops, 0, pathHops.length);
             }
 
-            result.add(createPath(allHops));
+            result.add(createPath(src instanceof HostId, dst instanceof HostId, allHops));
             return result;
         }
 
@@ -161,15 +162,17 @@
             final Set<Path> paths = getPaths(src, dst);
 
             for (Path path : paths) {
-                final DeviceId srcDevice = path.src().deviceId();
-                final DeviceId dstDevice = path.dst().deviceId();
-                final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice);
-                final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice);
-                final Link link = link(src.toString(), 1, dst.toString(), 1);
+                final DeviceId srcDevice = path.src().elementId() instanceof DeviceId ? path.src().deviceId() : null;
+                final DeviceId dstDevice = path.dst().elementId() instanceof DeviceId ? path.dst().deviceId() : null;
+                if (srcDevice != null && dstDevice != null) {
+                    final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice);
+                    final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice);
+                    final Link link = link(src.toString(), 1, dst.toString(), 1);
 
-                final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link));
-                if (weightValue < 0) {
-                    return new HashSet<>();
+                    final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link));
+                    if (weightValue < 0) {
+                        return new HashSet<>();
+                    }
                 }
             }
             return paths;