From 31a5a1560e139e75d9a8db96f1ed6f1dfe6ab22d Mon Sep 17 00:00:00 2001 From: roost-io <34998783+taher27@users.noreply.github.com> Date: Thu, 2 Jul 2026 06:14:24 +0000 Subject: [PATCH] Unit test generated by RoostGPT Using AI Model global.anthropic.claude-sonnet-4-6 --- core/pom.xml | 21 +- .../adk/agents/LiveRequestBuilderTest.java | 379 +++++++++++++ .../agents/LiveRequestShouldCloseTest.java | 519 ++++++++++++++++++ pom.xml | 79 ++- 4 files changed, 974 insertions(+), 24 deletions(-) mode change 100644 => 100755 core/pom.xml create mode 100644 core/src/test/java/com/google/adk/agents/LiveRequestBuilderTest.java create mode 100755 core/src/test/java/com/google/adk/agents/LiveRequestShouldCloseTest.java mode change 100644 => 100755 pom.xml diff --git a/core/pom.xml b/core/pom.xml old mode 100644 new mode 100755 index fe65715f3..7d2032c7e --- 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/agents/LiveRequestBuilderTest.java b/core/src/test/java/com/google/adk/agents/LiveRequestBuilderTest.java new file mode 100644 index 000000000..f94590c1f --- /dev/null +++ b/core/src/test/java/com/google/adk/agents/LiveRequestBuilderTest.java @@ -0,0 +1,379 @@ +/* + * 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 june-java-unit using AI Type AWS Bedrock Runtime AI and AI Model global.anthropic.claude-sonnet-4-6 + +ROOST_METHOD_HASH=builder_0aac37399c +ROOST_METHOD_SIG_HASH=builder_80041265ae + +Scenario 1: Verify That builder() Returns a Non-Null Builder Instance + +Details: + TestName: builderReturnsNonNullInstance + Description: Verifies that the static builder() method returns a non-null Builder instance, + ensuring the factory method is properly initialized and usable. +Execution: + Arrange: No special setup is required since builder() is a static factory method. + Act: Call LiveRequest.builder() to obtain a Builder instance. + Assert: Assert that the returned Builder instance is not null using assertNotNull(). +Validation: + The assertion confirms that the builder() method successfully creates and returns a Builder object. + This is a fundamental test to ensure the factory method is operational and does not return null, + which would cause NullPointerExceptions downstream in the application. + + +Scenario 2: Verify That the Builder Has close Set to false by Default + +Details: + TestName: builderSetsCloseToFalseByDefault + Description: Verifies that the builder returned by builder() has the close field pre-initialized + to false, confirming the default value is correctly applied without any additional + configuration. +Execution: + Arrange: No special setup is required. + Act: Call LiveRequest.builder() to get a Builder, then call build() directly after setting + a valid content field (e.g., using content(Optional.empty()) with blob or any required field). + Since close is already set to false, build() should succeed. + Obtain the resulting LiveRequest object. + Assert: Assert that the resulting LiveRequest's shouldClose() returns false, + confirming that close was pre-set to false by builder(). +Validation: + The assertion verifies that the builder() method pre-sets close to false. + This default behavior is critical to prevent unintended connection closures when a developer + creates a new LiveRequest without explicitly setting the close field. + + +Scenario 3: Verify That builder() Returns a Fresh Builder on Each Invocation + +Details: + TestName: builderReturnsFreshInstanceOnEachCall + Description: Verifies that each call to builder() returns a new, independent Builder instance, + ensuring that different Builder objects do not share state. +Execution: + Arrange: No special setup is required. + Act: Call LiveRequest.builder() twice to obtain two separate Builder instances (builder1 and builder2). + Assert: Assert that builder1 and builder2 are not the same object reference using assertNotSame(). +Validation: + The assertion confirms that builder() creates a new Builder object on every invocation. + This is important to ensure that building multiple LiveRequest objects independently does not + result in shared mutable state, which could lead to subtle and hard-to-detect bugs. + + +Scenario 4: Verify That Builder Returned by builder() Can Successfully Build a LiveRequest + +Details: + TestName: builderCanBuildValidLiveRequest + Description: Verifies that the Builder returned by builder() is fully functional and can + produce a valid LiveRequest object when build() is called, given that the + close field is already pre-set to false. +Execution: + Arrange: No special setup is required since close is pre-set by builder(). + Act: Call LiveRequest.builder() to get a Builder and immediately call build() without + setting any additional fields (close is already set to false by builder()). + Assert: Assert that the resulting LiveRequest object is not null using assertNotNull(). +Validation: + The assertion confirms that the default Builder state (with close set to false) satisfies + the Preconditions.checkState constraint that requires at least one of content, blob, or close + to be present. This test ensures the builder() method creates a usable Builder that produces + a valid LiveRequest without requiring additional field configuration. + + +Scenario 5: Verify That the Built LiveRequest Has close Present as Optional + +Details: + TestName: builtLiveRequestHasClosePresentInOptional + Description: Verifies that after calling builder() and subsequently build(), the resulting + LiveRequest has the close field present as a non-empty Optional with a value of false. +Execution: + Arrange: No special setup is required. + Act: Call LiveRequest.builder().build() to create a LiveRequest. + Assert: Assert that the resulting LiveRequest's close() Optional is present (isPresent() returns true) + and that the value inside the Optional equals false. +Validation: + The assertion verifies that close() returns Optional.of(false), not Optional.empty(). + This confirms that builder() properly pre-populates the close field using the Builder's + close(false) call, which is critical for downstream logic that relies on the Optional's + presence to determine whether a close value was explicitly set. + + +Scenario 6: Verify That shouldClose() Returns false on a LiveRequest Built Directly from builder() + +Details: + TestName: shouldCloseReturnsFalseOnDefaultBuilder + Description: Verifies that shouldClose() returns false on a LiveRequest built directly from + the default builder(), confirming the convenience method correctly reads the + pre-set close field value. +Execution: + Arrange: No special setup is required. + Act: Call LiveRequest.builder().build() to create a LiveRequest, then invoke shouldClose() on it. + Assert: Assert that shouldClose() returns false using assertFalse(). +Validation: + The assertion ensures that shouldClose() correctly interprets the default close field value + set by builder(). This is important for application logic that uses shouldClose() to determine + whether to terminate a live connection after sending the request. + + +Scenario 7: Verify That builder() Returns an Instance of Builder Class + +Details: + TestName: builderReturnsInstanceOfBuilderClass + Description: Verifies that the object returned by builder() is an instance of LiveRequest.Builder, + ensuring the correct type is returned by the factory method. +Execution: + Arrange: No special setup is required. + Act: Call LiveRequest.builder() and capture the result. + Assert: Assert that the returned object is an instance of LiveRequest.Builder using assertInstanceOf() + or assertTrue() with instanceof. +Validation: + The assertion confirms the return type of builder() is the expected LiveRequest.Builder class. + This is important for type safety and ensures that callers receive a properly typed Builder + object that exposes all the expected builder methods. + + +Scenario 8: Verify That Builder Produced by builder() Allows Overriding the Default close Value + +Details: + TestName: builderAllowsOverridingDefaultCloseValue + Description: Verifies that the default close value of false set by builder() can be overridden + by calling close(true) on the returned Builder, ensuring the default is not immutable + and can be changed for use cases that require closing the connection. +Execution: + Arrange: No special setup is required. + Act: Call LiveRequest.builder(), then call close(true) on the Builder to override the default, + then call build() to obtain the resulting LiveRequest. + Assert: Assert that shouldClose() on the built LiveRequest returns true using assertTrue(). +Validation: + The assertion verifies that the pre-set close(false) value is not locked and can be overridden + by the caller. This is important for use cases where a developer explicitly wants to close the + live connection after sending the request, confirming the builder pattern's flexibility. + + +Scenario 9: Verify That Builder Produced by builder() Allows Setting a Content Field + +Details: + TestName: builderAllowsSettingContentField + Description: Verifies that the Builder returned by builder() allows setting the content field + via content(Optional) without any issue, ensuring all Builder methods + remain accessible and functional after builder() initializes the close field. +Execution: + Arrange: Create an Optional.empty() for Content to be used as the content value. + Act: Call LiveRequest.builder(), chain content(Optional.empty()), and then call build(). + Assert: Assert that the resulting LiveRequest's content() returns Optional.empty() + using assertEquals() or assertTrue() on content().isEmpty(). +Validation: + The assertion confirms that calling builder() and then chaining content() works correctly. + This verifies that the pre-initialization of close in builder() does not interfere with + subsequent Builder method calls, ensuring the full Builder API remains functional. + + +Scenario 10: Verify That Builder Produced by builder() Allows Setting a Blob Field + +Details: + TestName: builderAllowsSettingBlobField + Description: Verifies that the Builder returned by builder() allows setting the blob field + via blob(Optional) without issue, confirming all Builder methods are + accessible after builder() pre-sets the close field. +Execution: + Arrange: Create an Optional.empty() for Blob to pass to the blob() method. + Act: Call LiveRequest.builder(), chain blob(Optional.empty()), then call build(). + Assert: Assert that the resulting LiveRequest's blob() returns Optional.empty() + using assertTrue() on blob().isEmpty(). +Validation: + The assertion confirms that setting the blob field on the Builder returned by builder() + functions correctly and does not conflict with the pre-set close value. + This ensures the builder() factory method produces a fully flexible Builder object + where all fields can be set independently. + +*/ + +// ********RoostGPT******** + +package com.google.adk.agents; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Optional; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +class LiveRequestBuilderTest { + + @Test + @Tag("valid") + void builderReturnsNonNullInstance() { + LiveRequest.Builder builder = LiveRequest.builder(); + assertNotNull(builder, "builder() should return a non-null Builder instance"); + } + + @Test + @Tag("valid") + void builderSetsCloseToFalseByDefault() { + LiveRequest liveRequest = LiveRequest.builder().build(); + assertFalse(liveRequest.shouldClose(), "Default builder should pre-set close to false"); + } + + @Test + @Tag("valid") + void builderReturnsFreshInstanceOnEachCall() { + LiveRequest.Builder builder1 = LiveRequest.builder(); + LiveRequest.Builder builder2 = LiveRequest.builder(); + assertNotSame( + builder1, + builder2, + "Each call to builder() should return a new, independent Builder instance"); + } + + @Test + @Tag("valid") + void builderCanBuildValidLiveRequest() { + LiveRequest liveRequest = LiveRequest.builder().build(); + assertNotNull( + liveRequest, "Builder with default close=false should successfully build a LiveRequest"); + } + + @Test + @Tag("valid") + void builtLiveRequestHasClosePresentInOptional() { + LiveRequest liveRequest = LiveRequest.builder().build(); + assertTrue( + liveRequest.close().isPresent(), + "close() Optional should be present after building with builder()"); + assertEquals( + Boolean.FALSE, + liveRequest.close().get(), + "close() Optional value should be false by default"); + } + + @Test + @Tag("valid") + void shouldCloseReturnsFalseOnDefaultBuilder() { + LiveRequest liveRequest = LiveRequest.builder().build(); + assertFalse( + liveRequest.shouldClose(), + "shouldClose() should return false on a LiveRequest built with default builder()"); + } + + @Test + @Tag("valid") + void builderReturnsInstanceOfBuilderClass() { + Object builder = LiveRequest.builder(); + assertNotNull(builder, "builder() should not return null"); + assertInstanceOf( + LiveRequest.Builder.class, + builder, + "builder() should return an instance of LiveRequest.Builder"); + } + + @Test + @Tag("valid") + void builderAllowsOverridingDefaultCloseValue() { + LiveRequest liveRequest = LiveRequest.builder().close(true).build(); + assertTrue( + liveRequest.shouldClose(), + "shouldClose() should return true when close(true) overrides the default"); + } + + @Test + @Tag("valid") + void builderAllowsSettingContentField() { + LiveRequest liveRequest = LiveRequest.builder().content(Optional.empty()).build(); + assertNotNull( + liveRequest, "LiveRequest built with content(Optional.empty()) should not be null"); + assertTrue( + liveRequest.content().isEmpty(), + "content() should return Optional.empty() when set to Optional.empty()"); + } + + @Test + @Tag("valid") + void builderAllowsSettingBlobField() { + LiveRequest liveRequest = LiveRequest.builder().blob(Optional.empty()).build(); + assertNotNull(liveRequest, "LiveRequest built with blob(Optional.empty()) should not be null"); + assertTrue( + liveRequest.blob().isEmpty(), + "blob() should return Optional.empty() when set to Optional.empty()"); + } + + @Test + @Tag("boundary") + void builderWithCloseSetToFalseExplicitly() { + LiveRequest liveRequest = LiveRequest.builder().close(false).build(); + assertFalse( + liveRequest.shouldClose(), + "shouldClose() should return false when explicitly set to false"); + assertTrue( + liveRequest.close().isPresent(), + "close() Optional should be present when explicitly set to false"); + assertEquals( + Boolean.FALSE, + liveRequest.close().get(), + "close() Optional value should be false when explicitly set"); + } + + @Test + @Tag("valid") + void multipleBuildsFromSameBuilderAreIndependent() { + LiveRequest.Builder builder1 = LiveRequest.builder(); + LiveRequest.Builder builder2 = LiveRequest.builder().close(true); + LiveRequest request1 = builder1.build(); + LiveRequest request2 = builder2.build(); + assertFalse( + request1.shouldClose(), "First request built with default builder should have close=false"); + assertTrue( + request2.shouldClose(), "Second request built with close(true) should have close=true"); + } + + @Test + @Tag("integration") + void builderChainWithAllOptionalFieldsEmpty() { + LiveRequest liveRequest = + LiveRequest.builder().content(Optional.empty()).blob(Optional.empty()).close(false).build(); + assertNotNull(liveRequest, "LiveRequest with all optional fields empty should not be null"); + assertTrue(liveRequest.content().isEmpty(), "content() should be empty Optional"); + assertTrue(liveRequest.blob().isEmpty(), "blob() should be empty Optional"); + assertFalse(liveRequest.shouldClose(), "shouldClose() should be false"); + } + + @Test + @Tag("integration") + void builderProducesConsistentResultsForSameConfiguration() { + LiveRequest request1 = LiveRequest.builder().build(); + LiveRequest request2 = LiveRequest.builder().build(); + assertEquals( + request1.shouldClose(), + request2.shouldClose(), + "Two LiveRequests built with default builder() should have the same shouldClose() value"); + assertEquals( + request1.close().isPresent(), + request2.close().isPresent(), + "Two LiveRequests built with default builder() should have the same close Optional presence"); + } + + @Test + @Tag("valid") + void builderCloseOptionalPresentAfterOverride() { + LiveRequest liveRequest = LiveRequest.builder().close(true).build(); + assertTrue( + liveRequest.close().isPresent(), + "close() Optional should be present after overriding with close(true)"); + assertEquals( + Boolean.TRUE, + liveRequest.close().get(), + "close() Optional value should be true after overriding"); + } +} diff --git a/core/src/test/java/com/google/adk/agents/LiveRequestShouldCloseTest.java b/core/src/test/java/com/google/adk/agents/LiveRequestShouldCloseTest.java new file mode 100755 index 000000000..85a19fe07 --- /dev/null +++ b/core/src/test/java/com/google/adk/agents/LiveRequestShouldCloseTest.java @@ -0,0 +1,519 @@ +/* + * 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 june-java-unit using AI Type AWS Bedrock Runtime AI and AI Model global.anthropic.claude-sonnet-4-6 + +ROOST_METHOD_HASH=shouldClose_e9d1581950 +ROOST_METHOD_SIG_HASH=shouldClose_c75a6108da + +[ + { + "description": "shouldClose() returns true when close is explicitly set to true via builder — the primary signal to close a connection.", + "testName": "shouldCloseReturnsTrueWhenCloseIsTrue", + "execution": { + "Arrange": "Build a LiveRequest using LiveRequest.builder().close(true).build().", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "This is the most critical scenario — the method's entire purpose is to return true when close is true; without this working correctly the connection lifecycle management breaks.", + "category": "critical", + "source": "llm", + "priority": "high" + }, + { + "description": "shouldClose() returns false when using the default builder() factory method without overriding close — ensuring no accidental connection closure.", + "testName": "shouldCloseReturnsFalseWithDefaultBuilderNoOverride", + "execution": { + "Arrange": "Call LiveRequest.builder(), set content to a valid Content object (to satisfy precondition), then call build() without calling close() again.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Critical because the builder initializes close=false — if this default is broken, every LiveRequest without explicit close=true would incorrectly signal connection closure.", + "category": "critical", + "source": "llm", + "priority": "high" + }, + { + "description": "shouldClose() returns false when close Optional is absent (empty), relying on orElse(false) fallback.", + "testName": "shouldCloseReturnsFalseWhenCloseOptionalAbsentViaNullableSetter", + "execution": { + "Arrange": "Build a LiveRequest with content set and call close((Boolean) null) to make close Optional.empty().", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false without throwing NullPointerException." + }, + "validation": "Critical null-safety test — the orElse(false) is the only guard against NPE when close is absent; failure here would cause production runtime exceptions.", + "category": "critical", + "source": "llm", + "priority": "high" + }, + { + "description": "shouldClose() returns consistent results when called multiple times to ensure idempotency of the method.", + "testName": "shouldCloseIsIdempotentOnMultipleCallsWithCloseTrue", + "execution": { + "Arrange": "Build a LiveRequest with close(true).", + "Act": "Call shouldClose() three times consecutively and store each result.", + "Assert": "Assert all three results are true and equal." + }, + "validation": "Critical because downstream consumers may call shouldClose() multiple times; any non-idempotent behavior (state mutation) would cause unpredictable connection management.", + "category": "critical", + "source": "llm", + "priority": "high" + }, + { + "description": "shouldClose() returns false when only blob is set and no close is explicitly overridden after builder() default initialization.", + "testName": "shouldCloseReturnsFalseWhenOnlyBlobIsSetNoCloseOverride", + "execution": { + "Arrange": "Build a LiveRequest using LiveRequest.builder() and set only blob to a valid Blob object; do not override close.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Critical to confirm that blob-only requests do not accidentally trigger connection closure behavior.", + "category": "critical", + "source": "llm", + "priority": "high" + }, + { + "description": "shouldClose() returns false when close is explicitly set to false via builder.", + "testName": "shouldCloseReturnsFalseWhenCloseIsSetToFalse", + "execution": { + "Arrange": "Build a LiveRequest with close(false) set explicitly (also set content to satisfy the precondition check, or rely on close being present).", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies the core happy path where close is false, confirming shouldClose() correctly delegates to close().orElse(false) and returns false.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns true when close is explicitly set to true via builder.", + "testName": "shouldCloseReturnsTrueWhenCloseIsSetToTrue", + "execution": { + "Arrange": "Build a LiveRequest using LiveRequest.builder().close(true).", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "Verifies the primary use case — when the caller signals the connection should close, shouldClose() must return true.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false when using the default builder() factory method without overriding close.", + "testName": "shouldCloseReturnsFalseWithDefaultBuilder", + "execution": { + "Arrange": "Call LiveRequest.builder() and then set content to a non-null Content object (to satisfy precondition), then build() without calling close() setter.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Confirms the default builder initializes close to false, so shouldClose() returns false without explicit configuration — important default behavior.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false when close Optional is set to Optional.empty() via builder.", + "testName": "shouldCloseReturnsFalseWhenCloseOptionalIsEmpty", + "execution": { + "Arrange": "Build a LiveRequest using builder, explicitly calling close(Optional.empty()) — but also set content or blob to satisfy precondition check since close won't be present. Note: build() checks close.isPresent() so content or blob must be set.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies the orElse(false) fallback — when close Optional is empty, shouldClose() must return false rather than throwing.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false when close is set to null (nullable @Nullable Boolean) via builder.", + "testName": "shouldCloseReturnsFalseWhenCloseIsSetToNull", + "execution": { + "Arrange": "Build a LiveRequest with content set to a valid Content and close(@Nullable Boolean) called with null — verify close becomes Optional.empty().", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies null-safety: passing null for close results in Optional.empty(), and shouldClose() safely returns false via orElse(false).", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns true after building from JSON string with close set to true.", + "testName": "shouldCloseReturnsTrueWhenDeserializedFromJsonWithCloseTrue", + "execution": { + "Arrange": "Create a JSON string '{\"close\": true}' and deserialize via LiveRequest.fromJsonString(json).", + "Act": "Call shouldClose() on the deserialized LiveRequest.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "Verifies that JSON deserialization correctly populates the close field, and shouldClose() behaves correctly in a real-world deserialization scenario.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false after building from JSON string with close set to false.", + "testName": "shouldCloseReturnsFalseWhenDeserializedFromJsonWithCloseFalse", + "execution": { + "Arrange": "Create a JSON string '{\"close\": false}' and deserialize via LiveRequest.fromJsonString(json).", + "Act": "Call shouldClose() on the deserialized LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies that JSON deserialization correctly sets close to false, and shouldClose() correctly returns false.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns consistent value when called multiple times in succession (idempotency).", + "testName": "shouldCloseIsIdempotentWhenCalledMultipleTimes", + "execution": { + "Arrange": "Build a LiveRequest with close(true).", + "Act": "Call shouldClose() three times on the same LiveRequest instance.", + "Assert": "Assert that all three calls return true and are equal to each other." + }, + "validation": "Verifies that shouldClose() is a pure getter with no side effects — repeated calls must always return the same value.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() on two independently built LiveRequest instances returns independent values.", + "testName": "shouldCloseReturnsIndependentValuesForSeparateInstances", + "execution": { + "Arrange": "Build requestA with close(true) and requestB with close(false) (requestB also needs content or blob set).", + "Act": "Call shouldClose() on both requestA and requestB.", + "Assert": "Assert requestA.shouldClose() is true and requestB.shouldClose() is false." + }, + "validation": "Verifies instance isolation — two different LiveRequest objects maintain independent state for the close field.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns true when close is set to true and content is also set (combined fields do not interfere).", + "testName": "shouldCloseReturnsTrueWhenCloseIsTrueAndContentIsAlsoSet", + "execution": { + "Arrange": "Build a LiveRequest with close(true) and content set to a valid Content object.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "Verifies that the presence of other fields (content) does not interfere with shouldClose() returning the correct value.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns true when close is set to true and blob is also set (combined fields do not interfere).", + "testName": "shouldCloseReturnsTrueWhenCloseIsTrueAndBlobIsAlsoSet", + "execution": { + "Arrange": "Build a LiveRequest with close(true) and blob set to a valid Blob object.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "Verifies that the presence of blob does not affect shouldClose() returning true when close is true.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false when only content is set (no close field set explicitly beyond default).", + "testName": "shouldCloseReturnsFalseWhenOnlyContentIsSet", + "execution": { + "Arrange": "Build a LiveRequest using builder() with only content set to a valid Content object, not calling close() setter after builder initialization.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies that when close is at its default value (false from builder()), shouldClose() returns false even when content is present.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false when only blob is set (no close field set explicitly beyond default).", + "testName": "shouldCloseReturnsFalseWhenOnlyBlobIsSet", + "execution": { + "Arrange": "Build a LiveRequest using builder() with only blob set to a valid Blob object, not calling close() setter after builder initialization.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies that when only blob is set and close remains default, shouldClose() returns false.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns true after using toBuilder() to change close from false to true.", + "testName": "shouldCloseReturnsTrueAfterToBuilderChangesClosToTrue", + "execution": { + "Arrange": "Build an initial LiveRequest with close(false) and content set. Then call toBuilder().close(true).build() to get a new instance.", + "Act": "Call shouldClose() on the new instance.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "Verifies that modifying the close field via toBuilder() correctly affects shouldClose() on the resulting new instance.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false on original instance after toBuilder produces a modified copy with close(true).", + "testName": "shouldCloseReturnsFalseOnOriginalAfterToBuilderProducesNewInstance", + "execution": { + "Arrange": "Build original LiveRequest with content set and close default (false). Create modified via toBuilder().close(true).build().", + "Act": "Call shouldClose() on original instance.", + "Assert": "Assert that original.shouldClose() returns false while modified.shouldClose() returns true." + }, + "validation": "Verifies immutability — the original LiveRequest is unchanged after toBuilder() creates a new modified instance.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false after building from JSON string that contains only content field (no close field present).", + "testName": "shouldCloseReturnsFalseWhenDeserializedFromJsonWithNoCloseField", + "execution": { + "Arrange": "Create a JSON string with content field only (no close field) and deserialize via LiveRequest.fromJsonString(json).", + "Act": "Call shouldClose() on the deserialized LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies that missing close field in JSON does not cause NullPointerException and correctly defaults to false via orElse(false).", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns false when close is set via Optional containing false.", + "testName": "shouldCloseReturnsFalseWhenCloseSetViaOptionalOfFalse", + "execution": { + "Arrange": "Build a LiveRequest using builder().close(Optional.of(false)).build() — also satisfy precondition with content or ensure close is present.", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns false." + }, + "validation": "Verifies that explicitly passing Optional.of(false) to the builder results in shouldClose() returning false.", + "category": "recommended", + "source": "llm", + "priority": "medium" + }, + { + "description": "shouldClose() returns true when close is set via Optional containing true.", + "testName": "shouldCloseReturnsTrueWhenCloseSetViaOptionalOfTrue", + "execution": { + "Arrange": "Build a LiveRequest using builder().close(Optional.of(true)).build().", + "Act": "Call shouldClose() on the built LiveRequest.", + "Assert": "Assert that shouldClose() returns true." + }, + "validation": "Verifies that passing Optional.of(true) to the builder results in shouldClose() returning true.", + "category": "recommended", + "source": "llm", + "priority": "medium" + } +] +*/ + +// ********RoostGPT******** + +package com.google.adk.agents; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.adk.JsonBaseModel; +import com.google.common.collect.ImmutableList; +import com.google.genai.types.Blob; +import com.google.genai.types.Content; +import com.google.genai.types.Part; +import java.util.Optional; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +public class LiveRequestShouldCloseTest { + + @Test + @Tag("valid") + public void shouldCloseReturnsTrueWhenCloseIsTrue() { + assertThat(LiveRequest.builder().close(true).build().shouldClose()).isTrue(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsFalseWithDefaultBuilderNoOverride() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("hi"))).build(); + assertThat(LiveRequest.builder().content(c).build().shouldClose()).isFalse(); + } + + @Test + @Tag("invalid") + public void shouldCloseReturnsFalseWhenCloseOptionalAbsentViaNullableSetter() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("hi"))).build(); + assertThat(LiveRequest.builder().content(c).close((Boolean) null).build().shouldClose()) + .isFalse(); + } + + @Test + @Tag("valid") + public void shouldCloseIsIdempotentOnMultipleCallsWithCloseTrue() { + LiveRequest req = LiveRequest.builder().close(true).build(); + assertThat(req.shouldClose()).isTrue(); + assertThat(req.shouldClose()).isTrue(); + assertThat(req.shouldClose()).isTrue(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsFalseWhenOnlyBlobIsSetNoCloseOverride() { + Blob b = Blob.builder().mimeType("image/png").data(new byte[] {1, 2}).build(); + assertThat(LiveRequest.builder().blob(b).build().shouldClose()).isFalse(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsFalseWhenCloseIsSetToFalse() { + assertThat(LiveRequest.builder().close(false).build().shouldClose()).isFalse(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsTrueWhenCloseIsSetToTrue() { + assertThat(LiveRequest.builder().close(true).build().shouldClose()).isTrue(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsFalseWithDefaultBuilder() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + assertThat(LiveRequest.builder().content(c).build().shouldClose()).isFalse(); + } + + @Test + @Tag("boundary") + public void shouldCloseReturnsFalseWhenCloseOptionalIsEmpty() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + assertThat(LiveRequest.builder().content(c).close(Optional.empty()).build().shouldClose()) + .isFalse(); + } + + @Test + @Tag("invalid") + public void shouldCloseReturnsFalseWhenCloseIsSetToNull() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + assertThat(LiveRequest.builder().content(c).close((Boolean) null).build().shouldClose()) + .isFalse(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsTrueWhenDeserializedFromJsonWithCloseTrue() { + assertThat(JsonBaseModel.fromJsonString("{\"close\": true}", LiveRequest.class).shouldClose()) + .isTrue(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsFalseWhenDeserializedFromJsonWithCloseFalse() { + assertThat(JsonBaseModel.fromJsonString("{\"close\": false}", LiveRequest.class).shouldClose()) + .isFalse(); + } + + @Test + @Tag("valid") + public void shouldCloseIsIdempotentWhenCalledMultipleTimes() { + LiveRequest req = LiveRequest.builder().close(true).build(); + boolean r1 = req.shouldClose(), r2 = req.shouldClose(), r3 = req.shouldClose(); + assertThat(r1).isEqualTo(r2); + assertThat(r2).isEqualTo(r3); + assertThat(r1).isTrue(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsIndependentValuesForSeparateInstances() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + assertThat(LiveRequest.builder().close(true).build().shouldClose()).isTrue(); + assertThat(LiveRequest.builder().content(c).close(false).build().shouldClose()).isFalse(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsTrueWhenCloseIsTrueAndContentIsAlsoSet() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + assertThat(LiveRequest.builder().close(true).content(c).build().shouldClose()).isTrue(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsTrueWhenCloseIsTrueAndBlobIsAlsoSet() { + Blob b = Blob.builder().mimeType("audio/wav").data(new byte[] {0, 1}).build(); + assertThat(LiveRequest.builder().close(true).blob(b).build().shouldClose()).isTrue(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsFalseWhenOnlyContentIsSet() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("hello"))).build(); + assertThat(LiveRequest.builder().content(c).build().shouldClose()).isFalse(); + } + + @Test + @Tag("valid") + public void shouldCloseReturnsFalseWhenOnlyBlobIsSet() { + Blob b = Blob.builder().mimeType("image/jpeg").data(new byte[] {10, 20}).build(); + assertThat(LiveRequest.builder().blob(b).build().shouldClose()).isFalse(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsTrueAfterToBuilderChangesClosToTrue() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + assertThat( + LiveRequest.builder().content(c).close(false).build().toBuilder() + .close(true) + .build() + .shouldClose()) + .isTrue(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsFalseOnOriginalAfterToBuilderProducesNewInstance() { + Content c = Content.builder().parts(ImmutableList.of(Part.fromText("test"))).build(); + LiveRequest orig = LiveRequest.builder().content(c).build(); + LiveRequest mod = orig.toBuilder().close(true).build(); + assertThat(orig.shouldClose()).isFalse(); + assertThat(mod.shouldClose()).isTrue(); + } + + @Test + @Tag("integration") + public void shouldCloseReturnsFalseWhenDeserializedFromJsonWithNoCloseField() { + assertThat( + JsonBaseModel.fromJsonString( + "{\"content\":{\"parts\":[{\"text\":\"hi\"}]}}", LiveRequest.class) + .shouldClose()) + .isFalse(); + } + + @Test + @Tag("boundary") + public void shouldCloseReturnsFalseWhenCloseSetViaOptionalOfFalse() { + assertThat(LiveRequest.builder().close(Optional.of(false)).build().shouldClose()).isFalse(); + } + + @Test + @Tag("boundary") + public void shouldCloseReturnsTrueWhenCloseSetViaOptionalOfTrue() { + assertThat(LiveRequest.builder().close(Optional.of(true)).build().shouldClose()).isTrue(); + } +} diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index 6009c7316..24fd6ece6 --- 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