import java.util.List;

public class TestCharAt {
    /**
     * As per spec - https://download.java.net/java/early_access/jdk18/docs/api/java.base/java/lang/StringBuffer
     * .html#charAt(int)
     * Throws:
     * IndexOutOfBoundsException - if index is negative or greater than or equal to length().
     * the test inputs,expected to throw IndexOutOfBoundsException.
     *
     * @param args
     */
    public static void main(String[] args) {
        List<Integer> indices_beyond_length = List.of(4, 5, 6, 7, 8, 9, 10, 11, 12);
        StringBuffer sb = new StringBuffer("test");
        int len = sb.length();
        try {
            for (int i : indices_beyond_length) {
                sb.charAt(i);
                System.out.println(" FAIL :: stringBuffer charAt index: " + i + " does not throw IOOBEx where index " +
                        "is " +
                        "greater than equal to length " + len);
            }
        } catch (IndexOutOfBoundsException ex) {
            System.out.println("PASS:: Expected exception thrown");
        }
    }

}
