public void appendBytesAsPrintFriendlyString(StringBuilder builder, byte[] phiBytes) {
        appendBytesAsPrintFriendlyString(builder, phiBytes, 0, phiBytes != null ? phiBytes.length : 0);
    }
@Test
    public void testAppendBytesAsPrintFriendlyStringWithStartAndEndPositions() {
        StringBuilder builder = null;

        try {
            hl7util.appendBytesAsPrintFriendlyString(builder, null);
            fail("Exception should be raised with null StringBuilder argument");
        } catch (IllegalArgumentException ignoredEx) {
            // Eat this
        }

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, 0, 1000);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, 200, 1000);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, -200, 1000);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, 0, 0);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, 200, 0);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, -200, 0);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, 0, -1000);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, 200, -1000);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, null, -200, -1000);
        assertEquals(hl7util.NULL_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], 0, 1000);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], 200, 1000);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], -200, 1000);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], 0, 0);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], 200, 0);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], -200, 0);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], 0, -1000);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], 200, -1000);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, new byte[0], -200, -1000);
        assertEquals(hl7util.EMPTY_REPLACEMENT_VALUE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 0, TEST_MESSAGE_BYTES.length);
        assertEquals(EXPECTED_MESSAGE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 0, 0);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, -14, TEST_MESSAGE_BYTES.length);
        assertEquals(EXPECTED_MESSAGE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, -14, 0);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, -14, -14);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, -14, 1000000);
        assertEquals(EXPECTED_MESSAGE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 0, -14);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 0, 1000000);
        assertEquals(EXPECTED_MESSAGE, builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 1000000, TEST_MESSAGE_BYTES.length);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 1000000, 0);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 1000000, -14);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 1000000, 1000000);
        assertEquals("", builder.toString());

        builder = new StringBuilder();
        hl7util.appendBytesAsPrintFriendlyString(builder, TEST_MESSAGE_BYTES, 54, 100);
        assertEquals("ORM^O01|00001|D|2.3|||||||<0x0D CR>PID|1||ICE999999^^^", builder.toString());
    }