// Tests_SRS_AMQPSIOTHUBCONNECTIONBASEHANDLER_14_031: [If the link is the Sender link, the event
  // handler shall create a new Target (Proton) object using the sender endpoint address member
  // variable.]
  // Tests_SRS_AMQPSIOTHUBCONNECTIONBASEHANDLER_14_033: [If the link is the Sender link, the event
  // handler shall get the Link (Proton) object and set its target.]
  // Tests_SRS_AMQPSIOTHUBCONNECTIONBASEHANDLER_14_034: [If the link is the Sender link, the event
  // handler shall set the SenderSettleMode to UNSETTLED.]
  @Test
  public void onLinkInitCreatesTargetAndSetsOnLinkForSender() {
    final String hostName = "test.host.name";
    final String deviceId = "test-deviceId";
    final String userName = "******";
    final String sasToken = "test-token";
    final String sendTag = "sender";

    new NonStrictExpectations() {
      {
        mockEvent.getLink();
        result = mockSender;
        mockSender.getName();
        result = sendTag;
        new Target();
        result = mockTarget;
      }
    };

    AmqpsIotHubConnectionBaseHandler handler =
        new AmqpsIotHubConnectionBaseHandler(
            hostName, userName, sasToken, deviceId, mockIotHubConnection);
    handler.onLinkInit(mockEvent);

    final String expectedEndpoint = "/devices/test-deviceId/messages/events";

    new Verifications() {
      {
        mockSource.setAddress(expectedEndpoint);
        mockSender.setTarget(mockTarget);
        mockSender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
      }
    };
  }
  // Tests_SRS_AMQPSIOTHUBCONNECTIONBASEHANDLER_14_030: [If the link is the Receiver link, the event
  // handler shall create a new Source (Proton) object using the receiver endpoint address member
  // variable.]
  // Tests_SRS_AMQPSIOTHUBCONNECTIONBASEHANDLER_14_032: [If the link is the Receiver link, the event
  // handler shall get the Link (Proton) object and set its source to the created Source (Proton)
  // object.]
  @Test
  public void onLinkInitCreatesSourceAndSetsOnLinkForReceiver() {
    final String hostName = "test.host.name";
    final String deviceId = "test-deviceId";
    final String userName = "******";
    final String sasToken = "test-token";
    final String receiveTag = "receiver";

    new NonStrictExpectations() {
      {
        mockEvent.getLink();
        result = mockReceiver;
        mockReceiver.getName();
        result = receiveTag;
        new Source();
        result = mockSource;
      }
    };

    AmqpsIotHubConnectionBaseHandler handler =
        new AmqpsIotHubConnectionBaseHandler(
            hostName, userName, sasToken, deviceId, mockIotHubConnection);
    handler.onLinkInit(mockEvent);

    final String expectedEndpoint = "/devices/test-deviceId/messages/devicebound";

    new Verifications() {
      {
        mockSource.setAddress(expectedEndpoint);
        mockReceiver.setSource(mockSource);
      }
    };
  }