@Test
public void testWithStackTrace() {

  FakeLoggerBackend backend = new FakeLoggerBackend();
  FluentLogger logger = new FluentLogger(backend);
  // Keep these 2 lines immediately adjacent to each other.
  StackTraceElement expectedCaller = getCallerInfoFollowingLine();
  logger.atSevere().withStackTrace(StackSize.FULL).log("Answer=%#x", 66);
  assertThat(backend.getLoggedCount()).isEqualTo(1);
  backend.assertLogged(0).hasMessage("Answer=%#x");
  backend.assertLogged(0).hasArguments(66);
  backend.assertLogged(0).metadata().hasSize(1);
  backend.assertLogged(0).metadata().keys().contains(Key.LOG_CAUSE);
  Throwable cause = backend.getLogged(0).getMetadata().findValue(Key.LOG_CAUSE);
  assertThat(cause).hasMessageThat().isEqualTo("FULL");
  assertThat(cause.getCause()).isNull();
  List<StackTraceElement> actualStack = Arrays.asList(cause.getStackTrace());
  List<StackTraceElement> expectedStack = Arrays.asList(new Throwable().getStackTrace());
  // Overwrite the first element to the expected value.
  expectedStack.set(0, expectedCaller);
  // Use string representation for comparison since synthetic stack elements are not "equal" to
  // equivalent system stack elements.
  assertThat(actualStack)
      .comparingElementsUsing(transforming(Object::toString, Object::toString, "toString"))
      .containsExactlyElementsIn(expectedStack)
      .inOrder();
}