@Test
  public void sendMessageMixedStreamAndUnary_historyOfFour() throws IOException {
    // Arrange
    String firstMessage = "hello!";
    String secondMessage = "how old are you?";
    Content expectedFirstContent = ContentMaker.fromString(firstMessage);
    Content expectedThirdContent = ContentMaker.fromString(secondMessage);

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

    // Assert
    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