From f7276261dbd1916a61ec10c5a21f77b2ef6ea70c Mon Sep 17 00:00:00 2001
From: roost-io <8110509+mgdevstack@users.noreply.github.com>
Date: Thu, 7 May 2026 13:22:47 +0530
Subject: [PATCH] Unit test generated by RoostGPT
Using AI Model gpt-5
---
core/pom.xml | 21 +-
.../ClaudeGenerateContentTest.java.invalid | 344 ++++++++++++++++++
pom.xml | 79 +++-
3 files changed, 420 insertions(+), 24 deletions(-)
create mode 100644 core/src/test/java/com/google/adk/models/ClaudeGenerateContentTest.java.invalid
diff --git a/core/pom.xml b/core/pom.xml
index fe65715f3..7d2032c7e 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -1,4 +1,4 @@
-
+
4.0.0
-
com.google.adk
google-adk-parent
- 0.4.1-SNAPSHOT
+ 0.4.1-SNAPSHOT
+
-
google-adk
Agent Development Kit
Agent Development Kit: an open-source, code-first toolkit designed to simplify building, evaluating, and deploying advanced AI agents anywhere.
-
-
-
com.anthropic
@@ -201,6 +197,15 @@
maven-compiler-plugin
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+ 0.0.40
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/core/src/test/java/com/google/adk/models/ClaudeGenerateContentTest.java.invalid b/core/src/test/java/com/google/adk/models/ClaudeGenerateContentTest.java.invalid
new file mode 100644
index 000000000..877fa1bde
--- /dev/null
+++ b/core/src/test/java/com/google/adk/models/ClaudeGenerateContentTest.java.invalid
@@ -0,0 +1,344 @@
+//This test file is marked invalid as it contains compilation errors. Change the extension to of this file to .java, to manually edit its contents
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+// ********RoostGPT********
+/*
+Test generated by RoostGPT for test unit-java-adk using AI Type Azure Open AI and AI Model gpt-5
+
+ROOST_METHOD_HASH=generateContent_bc4a182290
+ROOST_METHOD_SIG_HASH=generateContent_c08b9769fe
+
+Scenario 1: Builds messages from text-only contents and invokes Anthropic once
+
+Details:
+ TestName: buildsMessageParamsFromTextOnlyContents
+ Description: Verifies that when LlmRequest contains Content instances with only text Part(s), the method maps them into Anthropic MessageParam(s), builds MessageCreateParams correctly, calls anthropicClient.messages().create exactly once, and returns a Flowable that emits exactly one LlmResponse.
+
+Execution:
+ Arrange: Create an LlmRequest with a non-empty contents() list where each Content has role "user" and parts containing text only. Mock anthropicClient.messages().create to return a valid Message with a simple text ContentBlock.
+ Act: Call generateContent with stream=false.
+ Assert: Capture the MessageCreateParams passed to anthropicClient.messages().create and assert that:
+ - messages contains entries equal in count to LlmRequest.contents().
+ - each MessageParam contains text blocks reflecting the corresponding input text parts.
+ - the Flowable emits exactly one LlmResponse and completes.
+Validation:
+ Confirms that text parts are correctly propagated to Anthropic as text message blocks and that the method performs a single, synchronous Anthropic call, then wraps the converted response in a single-emission Flowable.
+
+
+*/
+
+// ********RoostGPT********
+package com.google.adk.models;import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import com.anthropic.client.AnthropicClient;
+import com.anthropic.models.messages.ContentBlockParam;
+import com.anthropic.models.messages.Message;
+import com.anthropic.models.messages.MessageCreateParams;
+import com.anthropic.models.messages.MessageParam;
+import com.anthropic.models.messages.TextBlockParam;
+import com.anthropic.models.messages.ToolChoice;
+import com.anthropic.models.messages.ToolChoiceAuto;
+import com.anthropic.models.messages.ToolUnion;
+import com.anthropic.models.messages.Model;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.types.Content;
+import com.google.genai.types.FunctionCall;
+import com.google.genai.types.GenerateContentConfig;
+import com.google.genai.types.Part;
+import io.reactivex.rxjava3.core.Flowable;
+import io.reactivex.rxjava3.subscribers.TestSubscriber;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.junit.jupiter.api.*;
+import com.anthropic.models.messages.ContentBlock;
+import com.anthropic.models.messages.MessageParam.Role;
+import com.anthropic.models.messages.Tool;
+import com.anthropic.models.messages.ToolResultBlockParam;
+import com.anthropic.models.messages.ToolUseBlockParam;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.google.genai.types.FunctionDeclaration;
+import java.util.HashMap;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class ClaudeGenerateContentTest extends BaseLlm {
+ public ClaudeGenerateContentTest() {
+ super("unit-test-model");
+ }
+ @Test
+ @Tag("valid")
+ public void testBuildsMessageParamsFromTextOnlyContents() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ Message message = mock(Message.class);
+ when(message.content()).thenReturn(new ArrayList<>());
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenReturn(message);
+ Content userContent1 = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().text("Hello world").build()))
+ .build();
+ Content userContent2 = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().text("How are you?").build()))
+ .build();
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of(userContent1, userContent2));
+ when(llmRequest.config()).thenReturn(Optional.empty());
+ when(llmRequest.tools()).thenReturn(ImmutableMap.of());
+ when(llmRequest.model()).thenReturn(Optional.of("test-model"));
+ Claude claude = new Claude("test-claude-model", anthropicClient);
+ Flowable result = claude.generateContent(llmRequest, false);
+ ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(MessageCreateParams.class);
+ verify(anthropicClient.messages(), times(1)).create(paramsCaptor.capture());
+ MessageCreateParams captured = paramsCaptor.getValue();
+ assertNotNull(captured, "MessageCreateParams should not be null");
+ List messageParams = captured.messages();
+ assertNotNull(messageParams, "messages() should not be null");
+ assertEquals(2, (int) messageParams.size(), "Expected two MessageParam entries");
+ // Validate first message text block
+ MessageParam.Content content0 = messageParams.get(0).content();
+ List blocks0 = (content0 != null && content0.isList()) ? content0.asList() : ImmutableList.of();
+ assertNotNull(blocks0, "First message's content blocks should not be null");
+ assertEquals(1, (int) blocks0.size(), "First message should have one content block");
+ ContentBlockParam block0 = blocks0.get(0);
+ if (block0.isText()) {
+ TextBlockParam textBlock0 = block0.asText();
+ assertEquals("Hello world", (String) textBlock0.text(), "First message text should match input");
+ }
+ // Validate second message text block
+ MessageParam.Content content1 = messageParams.get(1).content();
+ List blocks1 = (content1 != null && content1.isList()) ? content1.asList() : ImmutableList.of();
+ assertNotNull(blocks1, "Second message's content blocks should not be null");
+ assertEquals(1, (int) blocks1.size(), "Second message should have one content block");
+ ContentBlockParam block1 = blocks1.get(0);
+ if (block1.isText()) {
+ TextBlockParam textBlock1 = block1.asText();
+ assertEquals("How are you?", (String) textBlock1.text(), "Second message text should match input");
+ }
+ TestSubscriber ts = new TestSubscriber<>();
+ result.subscribe(ts);
+ ts.assertComplete();
+ ts.assertNoErrors();
+ ts.assertValueCount(1);
+ List responses = ts.values();
+ assertNotNull(responses.get(0), "LlmResponse should not be null");
+ }
+ @Test
+ @Tag("boundary")
+ public void testUsesDefaultModelWhenRequestModelMissing() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ Message message = mock(Message.class);
+ when(message.content()).thenReturn(new ArrayList<>());
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenReturn(message);
+ Content userContent = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().text("Ping").build()))
+ .build();
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of(userContent));
+ when(llmRequest.config()).thenReturn(Optional.empty());
+ when(llmRequest.tools()).thenReturn(ImmutableMap.of());
+ when(llmRequest.model()).thenReturn(Optional.empty());
+ Claude claude = new Claude("default-claude-model", anthropicClient);
+ Flowable result = claude.generateContent(llmRequest, false);
+ ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(MessageCreateParams.class);
+ verify(anthropicClient.messages(), times(1)).create(paramsCaptor.capture());
+ MessageCreateParams captured = paramsCaptor.getValue();
+ Model modelUnion = captured.model();
+ String modelStr = (modelUnion != null && modelUnion.isString()) ? modelUnion.asString() : null;
+ assertEquals("default-claude-model", (String) modelStr, "Should fallback to Claude's default model when request model is missing");
+ TestSubscriber ts = new TestSubscriber<>();
+ result.subscribe(ts);
+ ts.assertComplete();
+ ts.assertNoErrors();
+ ts.assertValueCount(1);
+ }
+ @Test
+ @Tag("valid")
+ public void testSetsSystemInstructionWhenPresent() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ Message message = mock(Message.class);
+ when(message.content()).thenReturn(new ArrayList<>());
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenReturn(message);
+ Content sysContent = Content.builder()
+ .parts(ImmutableList.of(
+ Part.builder().text("You are a helpful assistant.").build(),
+ Part.builder().text("Always be concise.").build()
+ )).build();
+ GenerateContentConfig config = mock(GenerateContentConfig.class);
+ when(config.systemInstruction()).thenReturn(Optional.of(sysContent));
+ when(config.tools()).thenReturn(Optional.empty());
+ Content userContent = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().text("Tell me a joke").build()))
+ .build();
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of(userContent));
+ when(llmRequest.config()).thenReturn(Optional.of(config));
+ when(llmRequest.tools()).thenReturn(ImmutableMap.of());
+ when(llmRequest.model()).thenReturn(Optional.of("some-model"));
+ Claude claude = new Claude("test-claude", anthropicClient);
+ Flowable result = claude.generateContent(llmRequest, false);
+ ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(MessageCreateParams.class);
+ verify(anthropicClient.messages(), times(1)).create(paramsCaptor.capture());
+ MessageCreateParams captured = paramsCaptor.getValue();
+ Optional systemOpt = captured.system();
+ String systemStr = systemOpt.isPresent() && systemOpt.get().isString() ? systemOpt.get().asString() : null;
+ assertEquals("You are a helpful assistant.\nAlways be concise.", (String) systemStr, "System instruction should concatenate text parts with newline");
+ TestSubscriber ts = new TestSubscriber<>();
+ result.subscribe(ts);
+ ts.assertNoErrors();
+ ts.assertComplete();
+ ts.assertValueCount(1);
+ }
+ @Test
+ @Tag("valid")
+ public void testSetsToolChoiceWhenToolsMapNotEmpty() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ Message message = mock(Message.class);
+ when(message.content()).thenReturn(new ArrayList<>());
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenReturn(message);
+ // Avoid referencing BaseTool type directly; use raw map and cast to satisfy return type
+ Map rawTools = new HashMap<>();
+ rawTools.put("myTool", new Object());
+ Content userContent = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().text("Call a tool").build()))
+ .build();
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of(userContent));
+ when(llmRequest.config()).thenReturn(Optional.empty());
+ when(llmRequest.tools()).thenReturn((Map) rawTools);
+ when(llmRequest.model()).thenReturn(Optional.of("tool-model"));
+ Claude claude = new Claude("test-claude", anthropicClient);
+ Flowable result = claude.generateContent(llmRequest, false);
+ ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(MessageCreateParams.class);
+ verify(anthropicClient.messages(), times(1)).create(paramsCaptor.capture());
+ MessageCreateParams captured = paramsCaptor.getValue();
+ ToolChoice expectedToolChoice = ToolChoice.ofAuto(ToolChoiceAuto.builder().disableParallelToolUse(true).build());
+ Optional actualToolChoiceOpt = captured.toolChoice();
+ org.junit.jupiter.api.Assertions.assertTrue(actualToolChoiceOpt.isPresent(), "Tool choice should be set when request tools map is non-empty");
+ ToolChoice actualToolChoice = actualToolChoiceOpt.get();
+ assertEquals(expectedToolChoice.getClass(), actualToolChoice.getClass(), "Tool choice type should be AUTO");
+ TestSubscriber ts = new TestSubscriber<>();
+ result.subscribe(ts);
+ ts.assertComplete();
+ ts.assertNoErrors();
+ ts.assertValueCount(1);
+ }
+ @Test
+ @Tag("boundary")
+ public void testEmptyContentsStillCallsAnthropicOnceAndReturnsResponse() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ Message message = mock(Message.class);
+ when(message.content()).thenReturn(new ArrayList<>());
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenReturn(message);
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of());
+ when(llmRequest.config()).thenReturn(Optional.empty());
+ when(llmRequest.tools()).thenReturn(ImmutableMap.of());
+ when(llmRequest.model()).thenReturn(Optional.of("empty-model"));
+ Claude claude = new Claude("test-claude", anthropicClient);
+ Flowable result = claude.generateContent(llmRequest, false);
+ ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(MessageCreateParams.class);
+ verify(anthropicClient.messages(), times(1)).create(paramsCaptor.capture());
+ MessageCreateParams captured = paramsCaptor.getValue();
+ assertEquals(0, (int) captured.messages().size(), "No message params should be built for empty contents");
+ TestSubscriber ts = new TestSubscriber<>();
+ result.subscribe(ts);
+ ts.assertComplete();
+ ts.assertNoErrors();
+ ts.assertValueCount(1);
+ }
+ @Test
+ @Tag("invalid")
+ public void testAnthropicThrowsExceptionPropagates() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenThrow(new RuntimeException("Upstream failure"));
+ Content userContent = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().text("Fail please").build()))
+ .build();
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of(userContent));
+ when(llmRequest.config()).thenReturn(Optional.empty());
+ when(llmRequest.tools()).thenReturn(ImmutableMap.of());
+ when(llmRequest.model()).thenReturn(Optional.of("failing-model"));
+ Claude claude = new Claude("test-claude", anthropicClient);
+ assertThrows(RuntimeException.class, () -> {
+ claude.generateContent(llmRequest, false);
+ }, "Exception from anthropicClient should propagate");
+ }
+ @Test
+ @Tag("valid")
+ public void testFunctionCallPartMapsToToolUseBlock() {
+ AnthropicClient anthropicClient = mock(AnthropicClient.class, RETURNS_DEEP_STUBS);
+ Message message = mock(Message.class);
+ when(message.content()).thenReturn(new ArrayList<>());
+ when(anthropicClient.messages().create(any(MessageCreateParams.class))).thenReturn(message);
+ FunctionCall fnCall = FunctionCall.builder()
+ .id("call-1")
+ .name("sum")
+ .args(ImmutableMap.of("a", 1, "b", 2))
+ .build();
+ Content userContent = Content.builder()
+ .role("user")
+ .parts(ImmutableList.of(Part.builder().functionCall(fnCall).build()))
+ .build();
+ LlmRequest llmRequest = mock(LlmRequest.class);
+ when(llmRequest.contents()).thenReturn(ImmutableList.of(userContent));
+ when(llmRequest.config()).thenReturn(Optional.empty());
+ when(llmRequest.tools()).thenReturn(ImmutableMap.of());
+ when(llmRequest.model()).thenReturn(Optional.of("tool-use-model"));
+ Claude claude = new Claude("test-claude", anthropicClient);
+ Flowable result = claude.generateContent(llmRequest, false);
+ ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(MessageCreateParams.class);
+ verify(anthropicClient.messages(), times(1)).create(paramsCaptor.capture());
+ MessageCreateParams captured = paramsCaptor.getValue();
+ List messageParams = captured.messages();
+ assertEquals(1, (int) messageParams.size(), "Expected one message for single content");
+ MessageParam.Content content = messageParams.get(0).content();
+ List blocks = (content != null && content.isList()) ? content.asList() : ImmutableList.of();
+ assertEquals(1, (int) blocks.size(), "Expected one block generated from function call part");
+ ContentBlockParam block = blocks.get(0);
+ if (block.isToolUse()) {
+ assertNotNull(block.asToolUse().id(), "Tool use id should not be null");
+ assertEquals("call-1", (String) block.asToolUse().id(), "Tool use id should match function call id");
+ assertEquals("sum", (String) block.asToolUse().name(), "Tool use name should match function call name");
+ }
+ TestSubscriber ts = new TestSubscriber<>();
+ result.subscribe(ts);
+ ts.assertComplete();
+ ts.assertNoErrors();
+ ts.assertValueCount(1);
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 6009c7316..24fd6ece6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-
+
-
+
4.0.0
-
com.google.adk
google-adk-parent
- 0.4.1-SNAPSHOT
+ 0.4.1-SNAPSHOT
+
pom
-
Google Agent Development Kit Maven Parent POM
https://github.com/google/adk-java
Google Agent Development Kit (ADK) for Java
-
core
dev
@@ -39,12 +35,10 @@
a2a
a2a/webservice
-
17
${java.version}
UTF-8
-
1.11.0
3.4.1
1.49.0
@@ -73,7 +67,6 @@
3.9.0
5.4.3
-
@@ -112,7 +105,6 @@
pom
import
-
com.anthropic
@@ -274,9 +266,21 @@
assertj-core
${assertj.version}
+
+ org.mockito
+ mockito-junit-jupiter
+ 2.23.4
+ test
+
+
+
+ io.spring.javaformat
+ spring-javaformat-formatter
+ 0.0.40
+
+
-
@@ -324,8 +328,7 @@
plain
-
+
**/*Test.java
@@ -469,6 +472,36 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.2.5
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 3.2.5
+
+ testReport
+
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 2.1
+
+ testReport
+
+
+
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+ 0.0.40
+
+
@@ -528,7 +561,6 @@
-
The Apache License, Version 2.0
@@ -558,4 +590,19 @@
https://central.sonatype.com/repository/maven-snapshots/
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 2.23.4
+ test
+
+
+
+ io.spring.javaformat
+ spring-javaformat-formatter
+ 0.0.40
+
+
+
\ No newline at end of file