@Test
  public void sendMessageStreamWithText_historyContainsTwoTurns() throws IOException {
    // (Arrange) Set up the responseStream
    ResponseStream<GenerateContentResponse> responseStream =
        new ResponseStream(new ResponseStreamIteratorWithHistory(mockServerStreamIterator));
    when(mockServerStreamIterator.hasNext()).thenReturn(true, true, false);
    when(mockServerStreamIterator.next())
        .thenReturn(RESPONSE_STREAM_CHUNK1_RESPONSE, RESPONSE_STREAM_CHUNK2_RESPONSE);

    // (Arrange) Set up the return value of the generateContentStream
    when(mockGenerativeModel.generateContentStream(
            Arrays.asList(ContentMaker.fromString(SAMPLE_MESSAGE1))))
        .thenReturn(responseStream);

    // (Act) send request, consume response and get history
    ResponseStream<GenerateContentResponse> returnedResponseStream =
        chat.sendMessageStream(SAMPLE_MESSAGE1);
    // User needs to consume the response stream;
    returnedResponseStream.stream().forEach(element -> {});

    List<Content> history = chat.getHistory();
    // (Assert) 1. The request message is in the first content of history. 2. The streamed output is
    // combined into the second content of history.
    assertThat(history.get(0).getParts(0).getText()).isEqualTo(SAMPLE_MESSAGE1);
    assertThat(history.get(1).getParts(0).getText()).isEqualTo(FULL_RESPONSE_TEXT);
  }
Callable function getCurrentWeather for testing automatic function calling.
java-vertexai/google-cloud-vertexai/src/test/java/com/google/cloud/vertexai/generativeai/ChatSessionTest.java