@Test
  public void sendMessageWithNewConfigs_historyContainsFullConversation() throws IOException {
    // Arrange
    String firstMessage = "hello!";
    String secondMessage = "how old are you?";
    Content expectedFirstContent = ContentMaker.fromString(firstMessage);
    Content expectedThirdContent = ContentMaker.fromString(secondMessage);
    GenerationConfig config = GenerationConfig.newBuilder().setTemperature(0.7F).build();
    ImmutableList<SafetySetting> safetySettings =
        ImmutableList.of(
            SafetySetting.newBuilder()
                .setCategory(HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT)
                .setThreshold(SafetySetting.HarmBlockThreshold.BLOCK_ONLY_HIGH)
                .build());

    // Act
    chat = model.startChat();
    ResponseStream<GenerateContentResponse> stream =
        chat.withGenerationConfig(config)
            .withSafetySettings(safetySettings)
            .sendMessageStream(firstMessage);
    // We consume the stream before sending another message
    for (GenerateContentResponse resp : stream) {
      // Assert while consuming
      assertThat(resp.getCandidatesList()).isNotEmpty();
    }
    GenerateContentResponse response =
        chat.withGenerationConfig(config)
            .withSafetySettings(safetySettings)
            .sendMessage(secondMessage);

    // Assert
    ImmutableList<Content> history = chat.getHistory();
    assertSizeAndAlternatingRolesInHistory(
        Thread.currentThread().getStackTrace()[1].getMethodName(),
        history,
        4,
        ImmutableList.of(expectedFirstContent, expectedThirdContent));
  }
Callable function getCurrentWeather for testing automatic function calling.
java-vertexai/google-cloud-vertexai/src/test/java/com/google/cloud/vertexai/it/ITChatSessionIntegrationTest.java