@Test
public void testFastStackGetter() {

  FastStackGetter stackGetter = FastStackGetter.createIfSupported();
  Throwable throwable = new UserCode().throwable;
  // Test expected stack entries.
  assertThat(stackGetter.getStackTraceElement(throwable, 0).getMethodName()).isEqualTo("methodC");
  assertThat(stackGetter.getStackTraceElement(throwable, 1).getMethodName()).isEqualTo("methodB");
  assertThat(stackGetter.getStackTraceElement(throwable, 2).getMethodName()).isEqualTo("methodA");
  StackTraceElement[] stack = throwable.getStackTrace();
  // We added at least 5 method calls to the stack before creating throwable.
  assertThat(stack.length).isAtLeast(5);
  assertThat(stackGetter.getStackTraceDepth(throwable)).isEqualTo(stack.length);
  for (int n = 0; n < stack.length; n++) {
    assertThat(stackGetter.getStackTraceElement(throwable, n)).isEqualTo(stack[n]);
  }
  // Finally ensure we blow up if the stack index is out of bounds.
  try {
    StackTraceElement unused = stackGetter.getStackTraceElement(throwable, stack.length);
    fail("expected IndexOutOfBoundsException");
  } catch (IndexOutOfBoundsException expected) {
  }
  try {
    StackTraceElement unused = stackGetter.getStackTraceElement(throwable, -1);
    fail("expected IndexOutOfBoundsException");
  } catch (IndexOutOfBoundsException expected) {
  }
}