From 3deeaac25f06547475c182f5a65192dd77d03ecf Mon Sep 17 00:00:00 2001 From: roost-io <8110509+mgdevstack@users.noreply.github.com> Date: Thu, 7 May 2026 12:13:31 +0530 Subject: [PATCH] Unit test generated by RoostGPT Using AI Model gpt-5 --- core/pom.xml | 21 ++-- ...ValueLlmResponseGroundingMetadataTest.java | 115 ++++++++++++++++++ pom.xml | 79 +++++++++--- 3 files changed, 191 insertions(+), 24 deletions(-) create mode 100644 core/src/test/java/com/google/adk/models/AutoValueLlmResponseGroundingMetadataTest.java 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/AutoValueLlmResponseGroundingMetadataTest.java b/core/src/test/java/com/google/adk/models/AutoValueLlmResponseGroundingMetadataTest.java new file mode 100644 index 000000000..7d539759f --- /dev/null +++ b/core/src/test/java/com/google/adk/models/AutoValueLlmResponseGroundingMetadataTest.java @@ -0,0 +1,115 @@ +// ********RoostGPT******** +/* +Test generated by RoostGPT for test unit-java-adk using AI Type Azure Open AI and AI Model gpt-5 + +ROOST_METHOD_HASH=groundingMetadata_a0a2aa3d33 +ROOST_METHOD_SIG_HASH=groundingMetadata_a669e0aed0 + +Scenario 1: Returns Optional.empty() when grounding metadata is not set + +Details: + TestName: returnsEmptyWhenNotSetByDefault + Description: Verify that groundingMetadata() returns Optional.empty() when the AutoValue_LlmResponse instance is created without setting any grounding metadata. + +Execution: + Arrange: Create an AutoValue_LlmResponse instance using the available builder without setting groundingMetadata. + Act: Invoke groundingMetadata() on the instance. + Assert: Assert that the returned Optional is empty. + +Validation: + Confirm that the absence of grounding metadata in the builder results in Optional.empty(). This ensures the method faithfully reflects the default state of the field and avoids unexpected non-empty values. + +*/ + +// ********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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.genai.types.GenerateContentResponse; +import com.google.genai.types.GroundingMetadata; +import java.util.Optional; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class AutoValueLlmResponseGroundingMetadataTest { + + @Test + @Tag("boundary") + public void testReturnsEmptyWhenNotSetByDefault() { + GenerateContentResponse response = GenerateContentResponse.builder().build(); + LlmResponse llmResponse = LlmResponse.builder().response(response).build(); + Optional actual = llmResponse.groundingMetadata(); + Optional expected = Optional.empty(); + assertEquals(expected, actual); + } + + @Test + @Tag("valid") + public void testGroundingMetadataPresentWhenSet() { + GroundingMetadata gm = Mockito.mock(GroundingMetadata.class); + GenerateContentResponse response = GenerateContentResponse.builder().build(); + LlmResponse base = LlmResponse.builder().response(response).build(); + LlmResponse withGm = base.toBuilder().groundingMetadata(Optional.of(gm)).build(); + Optional actual = withGm.groundingMetadata(); + Optional expected = Optional.of(gm); + assertTrue(actual.isPresent()); + assertSame(gm, actual.get()); + assertEquals(expected, actual); + } + + @Test + @Tag("boundary") + public void testExplicitEmptyOverridesPreviousValue() { + GroundingMetadata gm = Mockito.mock(GroundingMetadata.class); + GenerateContentResponse response = GenerateContentResponse.builder().build(); + LlmResponse withGm = + LlmResponse.builder().response(response).build().toBuilder() + .groundingMetadata(Optional.of(gm)) + .build(); + LlmResponse overridden = withGm.toBuilder().groundingMetadata(Optional.empty()).build(); + Optional expected = Optional.empty(); + Optional actual = overridden.groundingMetadata(); + assertEquals(expected, actual); + } + + @Test + @Tag("integration") + public void testCreateWithResponseReturnsEmptyGroundingMetadata() { + GenerateContentResponse response = GenerateContentResponse.builder().build(); + LlmResponse llmResponse = LlmResponse.create(response); + Optional actual = llmResponse.groundingMetadata(); + Optional expected = Optional.empty(); + assertEquals(expected, actual); + } + + @Test + @Tag("boundary") + public void testGetterIsNonNull() { + GenerateContentResponse response = GenerateContentResponse.builder().build(); + LlmResponse llmResponse = LlmResponse.builder().response(response).build(); + Optional actual = llmResponse.groundingMetadata(); + assertNotNull(actual); + } + + @Test + @Tag("valid") + public void testToBuilderPreservesGroundingMetadataIfNotModified() { + GroundingMetadata gm = Mockito.mock(GroundingMetadata.class); + GenerateContentResponse response = GenerateContentResponse.builder().build(); + LlmResponse original = + LlmResponse.builder().response(response).build().toBuilder() + .groundingMetadata(Optional.of(gm)) + .build(); + LlmResponse copy = original.toBuilder().build(); + Optional expected = Optional.of(gm); + Optional actual = copy.groundingMetadata(); + assertTrue(actual.isPresent()); + assertSame(gm, actual.get()); + assertEquals(expected, actual); + } +} 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