bugfix Function input is Nullable
Change-Id: Ie492fd070e300bbe6a2796805ba5f2c8a50c7248
Showing
2 changed files
with
8 additions
and
2 deletions
| ... | @@ -12,7 +12,11 @@ public final class ControllerNodeToNodeId | ... | @@ -12,7 +12,11 @@ public final class ControllerNodeToNodeId |
| 12 | 12 | ||
| 13 | @Override | 13 | @Override |
| 14 | public NodeId apply(ControllerNode input) { | 14 | public NodeId apply(ControllerNode input) { |
| 15 | - return input.id(); | 15 | + if (input == null) { |
| 16 | + return null; | ||
| 17 | + } else { | ||
| 18 | + return input.id(); | ||
| 19 | + } | ||
| 16 | } | 20 | } |
| 17 | 21 | ||
| 18 | /** | 22 | /** | ... | ... |
| 1 | package org.onlab.onos.cluster; | 1 | package org.onlab.onos.cluster; |
| 2 | 2 | ||
| 3 | +import static com.google.common.base.Predicates.notNull; | ||
| 3 | import static org.junit.Assert.*; | 4 | import static org.junit.Assert.*; |
| 4 | import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId; | 5 | import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId; |
| 5 | 6 | ||
| ... | @@ -30,12 +31,13 @@ public class ControllerNodeToNodeIdTest { | ... | @@ -30,12 +31,13 @@ public class ControllerNodeToNodeIdTest { |
| 30 | @Test | 31 | @Test |
| 31 | public final void testToNodeId() { | 32 | public final void testToNodeId() { |
| 32 | 33 | ||
| 33 | - final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3); | 34 | + final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3, null); |
| 34 | final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3); | 35 | final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3); |
| 35 | 36 | ||
| 36 | assertEquals(nodeIds, | 37 | assertEquals(nodeIds, |
| 37 | FluentIterable.from(nodes) | 38 | FluentIterable.from(nodes) |
| 38 | .transform(toNodeId()) | 39 | .transform(toNodeId()) |
| 40 | + .filter(notNull()) | ||
| 39 | .toList()); | 41 | .toList()); |
| 40 | } | 42 | } |
| 41 | 43 | ... | ... |
-
Please register or login to post a comment