@Test
  public void sendMessageWithTextThenModifyHistory_historyChangedToNewContentList()
      throws IOException {

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

    // (Act) Send text message via sendMessage and get the history.
    GenerateContentResponse response = chat.sendMessage(SAMPLE_MESSAGE1);
    List<Content> history = chat.getHistory();
    // (Assert) Assert that 1) the first content contains the user request text, and 2) the second
    // content in history contains the response.
    assertThat(history.get(0).getParts(0).getText()).isEqualTo(SAMPLE_MESSAGE1);
    assertThat(history.get(1).getParts(0).getText()).isEqualTo(FULL_RESPONSE_TEXT);

    // (Act) Set history to an empty list
    chat.setHistory(Arrays.asList());
    // (Assert) Asser that the history is empty.
    assertThat(chat.getHistory().size()).isEqualTo(0);
  }
Callable function getCurrentWeather for testing automatic function calling.
java-vertexai/google-cloud-vertexai/src/test/java/com/google/cloud/vertexai/generativeai/ChatSessionTest.java