@Test
public void testIsTextWithInvalidIndexAndLength() {

    ByteBuf buffer = Unpooled.buffer();
    try {
        buffer.writeBytes(new byte[4]);
        int[][] validIndexLengthPairs = new int[][] {
                new int[]{4, 0},
                new int[]{0, 4},
                new int[]{1, 3},
        };
        for (int[] pair : validIndexLengthPairs) {
            assertTrue(ByteBufUtil.isText(buffer, pair[0], pair[1], CharsetUtil.US_ASCII));
        }
        int[][] invalidIndexLengthPairs = new int[][]{
                new int[]{4, 1},
                new int[]{-1, 2},
                new int[]{3, -1},
                new int[]{3, -2},
                new int[]{5, 0},
                new int[]{1, 5},
        };
        for (int[] pair : invalidIndexLengthPairs) {
            try {
                ByteBufUtil.isText(buffer, pair[0], pair[1], CharsetUtil.US_ASCII);
                fail("Expected IndexOutOfBoundsException");
            } catch (IndexOutOfBoundsException e) {
                // expected
            }
        }
    } finally {
        buffer.release();
    }
}