### Question:
SwitchManager implements AutoCloseable { synchronized void updateSwitchConfig(NodeId nodeId, @Nullable OfOverlayNodeConfig config) { SwitchState state = getSwitchState(checkNotNull(nodeId)); SwitchStatus oldStatus = state.status; state.setConfig(config); handleSwitchState(state, oldStatus); } SwitchManager(DataBroker dataProvider); static void activatingSwitch(NodeId nodeId); static void deactivatingSwitch(NodeId nodeId); synchronized InstanceIdentifier<NodeConnector> getNodeConnectorIidForPortName(Name portName); synchronized Collection<NodeId> getReadySwitches(); synchronized Set<NodeConnectorId> getExternalPorts(NodeId nodeId); Set<Long> getExternalPortNumbers(NodeId nodeId); synchronized Collection<NodeConnectorId> getTunnelPorts(NodeId nodeId); synchronized NodeConnectorId getTunnelPort(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType); synchronized IpAddress getTunnelIP(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType); void registerListener(SwitchListener listener); void setEncapsulationFormat(EncapsulationFormat format); @Override void close();  }### Answer:
@Test public void updateSwitchConfigTestStateNull() { NodeId nodeId = mock(NodeId.class); switchManager.updateSwitchConfig(nodeId, ofOverlayNodeConfig); verifyZeroInteractions(listener); }
@Test public void updateSwitchConfigTestRemoved() { switchState.status = SwitchStatus.READY; switchManager.updateSwitchConfig(nodeId, ofOverlayNodeConfig); }
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void updateSwitchConfigTestReady() { FlowCapableNode fcNode = mock(FlowCapableNode.class); switchState.setFlowCapableNode(fcNode); switchState.status = SwitchStatus.DISCONNECTED; switchState.setHasEndpoints(true); Tunnel tunnel = mock(Tunnel.class); List<Tunnel> tunnels = Arrays.asList(tunnel); when(ofOverlayNodeConfig.getTunnel()).thenReturn(tunnels); when(tunnel.getTunnelType()).thenReturn((Class) TunnelTypeVxlan.class); IpAddress tAddress = mock(IpAddress.class); when(tunnel.getIp()).thenReturn(tAddress); NodeConnectorId tConnector = mock(NodeConnectorId.class); when(tunnel.getNodeConnectorId()).thenReturn(tConnector); PortNumber tPort = mock(PortNumber.class); when(tunnel.getPort()).thenReturn(tPort); switchManager.updateSwitchConfig(nodeId, ofOverlayNodeConfig); }
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void updateSwitchConfigTestUpdated() { FlowCapableNode fcNode = mock(FlowCapableNode.class); switchState.setFlowCapableNode(fcNode); switchState.status = SwitchStatus.READY; switchState.setHasEndpoints(true); Tunnel tunnel = mock(Tunnel.class); List<Tunnel> tunnels = Arrays.asList(tunnel); when(ofOverlayNodeConfig.getTunnel()).thenReturn(tunnels); when(tunnel.getTunnelType()).thenReturn((Class) TunnelTypeVxlan.class); IpAddress tAddress = mock(IpAddress.class); when(tunnel.getIp()).thenReturn(tAddress); NodeConnectorId tConnector = mock(NodeConnectorId.class); when(tunnel.getNodeConnectorId()).thenReturn(tConnector); PortNumber tPort = mock(PortNumber.class); when(tunnel.getPort()).thenReturn(tPort); switchManager.updateSwitchConfig(nodeId, ofOverlayNodeConfig); }
@Test public void updateSwitchConfigTestDisconnected() { switchState.status = SwitchStatus.DISCONNECTED; switchState.setHasEndpoints(true); switchState.setConfig(mock(OfOverlayNodeConfig.class)); switchManager.updateSwitchConfig(nodeId, null); }