@Test
  public void testWriteEmptyAcknowledgement() throws Exception {
    byte[] acknowledgement = new byte[0];

    byte[] expected = PayloadBuilder.build(START_OF_BLOCK, END_OF_BLOCK, END_OF_DATA);

    mllpSocketWriter.writeEnvelopedPayload(TEST_MESSAGE.getBytes(), acknowledgement);

    assertArrayEquals(expected, fakeSocket.payload());
  }
  @Test(expected = MllpAcknowledgementDeliveryException.class)
  public void testWriteToClosedSocket() throws Exception {
    fakeSocket.closed = true;

    try {
      mllpSocketWriter.writeEnvelopedPayload(
          TEST_MESSAGE.getBytes(), TEST_ACKNOWLEDGEMENT.getBytes());
    } catch (MllpAcknowledgementDeliveryException expectedEx) {
      verifyException(expectedEx);
      throw expectedEx;
    }
  }
  @Test(expected = MllpAcknowledgementDeliveryException.class)
  public void testGetOutputStreamFailure() throws Exception {
    fakeSocket.fakeSocketOutputStream = null;

    try {
      mllpSocketWriter.writeEnvelopedPayload(
          TEST_MESSAGE.getBytes(), TEST_ACKNOWLEDGEMENT.getBytes());
    } catch (MllpAcknowledgementDeliveryException expectedEx) {
      verifyException(expectedEx);
      throw expectedEx;
    }
  }
  @Test(expected = MllpAcknowledgementDeliveryException.class)
  public void testWriteEndOfMessageFailure() throws Exception {
    fakeSocket.fakeSocketOutputStream.writeArrayFailOn = PAYLOAD_TERMINATOR;

    try {
      mllpSocketWriter.writeEnvelopedPayload(
          TEST_MESSAGE.getBytes(), TEST_ACKNOWLEDGEMENT.getBytes());
    } catch (MllpAcknowledgementDeliveryException expectedEx) {
      verifyException(expectedEx);
      throw expectedEx;
    }
  }
  @Test(expected = MllpAcknowledgementDeliveryException.class)
  public void testWriteStartOfBlockFailure() throws Exception {
    fakeSocket.fakeSocketOutputStream.writeFailOn = new Byte((byte) START_OF_BLOCK);

    try {
      mllpSocketWriter.writeEnvelopedPayload(
          TEST_MESSAGE.getBytes(), TEST_ACKNOWLEDGEMENT.getBytes());
    } catch (MllpAcknowledgementDeliveryException expectedEx) {
      verifyException(expectedEx);
      throw expectedEx;
    }
  }