@Test
 public void testBarrierFieldSetGet() {
   Timeout mockedTimeout = mock(Timeout.class);
   deviceContext.setCurrentBarrierTimeout(mockedTimeout);
   final Timeout pickedBarrierTimeout = deviceContext.getBarrierTaskTimeout();
   assertEquals(mockedTimeout, pickedBarrierTimeout);
 }
 @Test
 public void testNodeConnector() {
   NodeConnectorRef mockedNodeConnectorRef = mock(NodeConnectorRef.class);
   deviceContext.storeNodeConnectorRef(DUMMY_PORT_NUMBER, mockedNodeConnectorRef);
   final NodeConnectorRef nodeConnectorRef =
       deviceContext.lookupNodeConnectorRef(DUMMY_PORT_NUMBER);
   assertEquals(mockedNodeConnectorRef, nodeConnectorRef);
 }
 @Test
 public void testProcessReply() {
   Error mockedError = mock(Error.class);
   deviceContext.processReply(mockedError);
   verify(messageIntelligenceAgency)
       .spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
   OfHeader mockedOfHeader = mock(OfHeader.class);
   deviceContext.processReply(mockedOfHeader);
   verify(messageIntelligenceAgency)
       .spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
 }
  @Test
  public void testProcessPacketInMessageFutureFailure() {
    PacketInMessage mockedPacketInMessage = mock(PacketInMessage.class);
    NotificationPublishService mockedNotificationPublishService =
        mock(NotificationPublishService.class);
    final ListenableFuture dummyFuture = Futures.immediateFailedFuture(new IllegalStateException());

    when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class)))
        .thenReturn(dummyFuture);
    deviceContext.setNotificationPublishService(mockedNotificationPublishService);
    deviceContext.processPacketInMessage(mockedPacketInMessage);
    verify(messageIntelligenceAgency)
        .spyMessage(
            any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
  }
  @Test
  public void testProcessPacketInMessageFutureSuccess() {
    PacketInMessage mockedPacketInMessage = mock(PacketInMessage.class);
    NotificationPublishService mockedNotificationPublishService =
        mock(NotificationPublishService.class);
    final ListenableFuture stringListenableFuture =
        Futures.immediateFuture(new String("dummy value"));

    when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class)))
        .thenReturn(stringListenableFuture);
    deviceContext.setNotificationPublishService(mockedNotificationPublishService);
    deviceContext.processPacketInMessage(mockedPacketInMessage);
    verify(messageIntelligenceAgency)
        .spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
  }
 @Test
 public void testAddDeleteToTxChain() {
   InstanceIdentifier<Nodes> dummyII = InstanceIdentifier.create(Nodes.class);
   deviceContext.addDeleteToTxChain(LogicalDatastoreType.CONFIGURATION, dummyII);
   verify(txChainManager)
       .addDeleteOperationTotTxChain(eq(LogicalDatastoreType.CONFIGURATION), eq(dummyII));
 }
 @Test
 public void testAuxiliaryConnectionContext() {
   ConnectionContext mockedConnectionContext = addDummyAuxiliaryConnectionContext();
   final ConnectionContext pickedConnectiobContexts =
       deviceContext.getAuxiliaryConnectiobContexts(DUMMY_COOKIE);
   assertEquals(mockedConnectionContext, pickedConnectiobContexts);
 }
 @Test
 public void testProcessReply2() {
   MultipartReply mockedMultipartReply = mock(MultipartReply.class);
   Xid dummyXid = new Xid(DUMMY_XID);
   deviceContext.processReply(dummyXid, Lists.newArrayList(mockedMultipartReply));
   verify(messageIntelligenceAgency)
       .spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
 }
  @Test
  public void testClose() {
    ConnectionAdapter mockedConnectionAdapter = mock(ConnectionAdapter.class);
    InetSocketAddress mockRemoteAddress = mock(InetSocketAddress.class);
    when(mockedConnectionAdapter.getRemoteAddress()).thenReturn(mockRemoteAddress);
    when(connectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);

    NodeId dummyNodeId = new NodeId("dummyNodeId");
    when(deviceState.getNodeId()).thenReturn(dummyNodeId);

    ConnectionContext mockedAuxiliaryConnectionContext = prepareConnectionContext();
    deviceContext.addAuxiliaryConenctionContext(mockedAuxiliaryConnectionContext);
    DeviceContextClosedHandler mockedDeviceContextClosedHandler =
        mock(DeviceContextClosedHandler.class);
    deviceContext.addDeviceContextClosedHandler(mockedDeviceContextClosedHandler);
    deviceContext.close();
    verify(connectionContext).closeConnection(eq(false));
    verify(deviceState).setValid(eq(false));
    verify(txChainManager).close();
    verify(mockedAuxiliaryConnectionContext).closeConnection(eq(false));
  }
  @Test
  public void testOnPublished() {
    final ConnectionContext auxiliaryConnectionContext = addDummyAuxiliaryConnectionContext();

    ConnectionAdapter mockedAuxConnectionAdapter = mock(ConnectionAdapter.class);
    when(auxiliaryConnectionContext.getConnectionAdapter()).thenReturn(mockedAuxConnectionAdapter);

    ConnectionAdapter mockedConnectionAdapter = mock(ConnectionAdapter.class);
    when(connectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);

    deviceContext.onPublished();
    verify(mockedAuxConnectionAdapter).setPacketInFiltering(eq(false));
    verify(mockedConnectionAdapter).setPacketInFiltering(eq(false));
  }
  @Test
  public void testPortStatusMessage() {
    PortStatusMessage mockedPortStatusMessage = mock(PortStatusMessage.class);
    Class dummyClass = Class.class;
    when(mockedPortStatusMessage.getImplementedInterface()).thenReturn(dummyClass);

    GetFeaturesOutput mockedFeature = mock(GetFeaturesOutput.class);
    when(mockedFeature.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
    when(deviceState.getFeatures()).thenReturn(mockedFeature);

    when(mockedPortStatusMessage.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(mockedPortStatusMessage.getReason()).thenReturn(PortReason.OFPPRADD);

    OpenflowPortsUtil.init();
    deviceContext.processPortStatusMessage(mockedPortStatusMessage);
    verify(txChainManager)
        .writeToTransaction(
            eq(LogicalDatastoreType.OPERATIONAL),
            any(InstanceIdentifier.class),
            any(DataObject.class));
  }
 @Test
 public void testGetDeviceState() {
   final DeviceState deviceSt = deviceContext.getDeviceState();
   assertNotNull(deviceSt);
   Assert.assertEquals(deviceState, deviceSt);
 }
 private ConnectionContext addDummyAuxiliaryConnectionContext() {
   ConnectionContext mockedConnectionContext = prepareConnectionContext();
   deviceContext.addAuxiliaryConenctionContext(mockedConnectionContext);
   return mockedConnectionContext;
 }
 @Test
 public void testGetReservedXid() {
   deviceContext.getReservedXid();
   verify(outboundQueueProvider).reserveEntry();
 }
 @Test
 public void testSubmitTransaction() {
   deviceContext.submitTransaction();
   verify(txChainManager).submitWriteTransaction();
 }
 @Test
 public void testGetMessageSpy() {
   final MessageSpy pickedMessageSpy = deviceContext.getMessageSpy();
   assertEquals(messageIntelligenceAgency, pickedMessageSpy);
 }
 @Test
 public void testGetPrimaryConnectionContext() {
   final ConnectionContext primaryConnectionContext = deviceContext.getPrimaryConnectionContext();
   assertEquals(connectionContext, primaryConnectionContext);
 }
 @Test
 public void testGetTimer() {
   final HashedWheelTimer pickedTimer = deviceContext.getTimer();
   assertEquals(timer, pickedTimer);
 }
 @Test
 public void testTranslatorLibrary() {
   final TranslatorLibrary pickedTranslatorLibrary = deviceContext.oook();
   assertEquals(translatorLibrary, pickedTranslatorLibrary);
 }
 @Test
 public void testGetDeviceMeterRegistry() {
   final DeviceMeterRegistry deviceMeterRegistry = deviceContext.getDeviceMeterRegistry();
   assertNotNull(deviceMeterRegistry);
 }
 @Test
 public void testGetReadTransaction() {
   final ReadTransaction readTx = deviceContext.getReadTransaction();
   assertNotNull(readTx);
   Assert.assertEquals(rTx, readTx);
 }