private static void assertSizeAndAlternatingRolesInHistory(
      String methodName,
      ImmutableList<Content> history,
      int expectedSize,
      ImmutableList<Content> expectedUserContent) {
    // GenAI output is flaky so we always print out the response.
    // For the same reason, we don't do assertions much.
    logger.info(String.format("%s: The whole history is:\n%s", methodName, history));
    assertThat(history.size()).isEqualTo(expectedSize);
    for (int i = 1; i < expectedSize; i += 2) {
      if (!expectedUserContent.isEmpty()) {
        assertThat(history.get(i - 1)).isEqualTo(expectedUserContent.get((i - 1) / 2));
      }
      assertThat(history.get(i - 1).getRole()).isEqualTo("user");
      assertThat(history.get(i).getRole()).isEqualTo("model");
    }
  }
Callable function getCurrentWeather for testing automatic function calling.
java-vertexai/google-cloud-vertexai/src/test/java/com/google/cloud/vertexai/it/ITChatSessionIntegrationTest.java