From 8c177bb6451c7697ca3515ef767d82cc07d43170 Mon Sep 17 00:00:00 2001
From: roost-io <8110509+mgdevstack@users.noreply.github.com>
Date: Fri, 8 May 2026 09:22:38 +0530
Subject: [PATCH] Unit test generated by RoostGPT
Using AI Model gpt-5
---
core/pom.xml | 21 +-
.../AutoValueMemoryEntryContentTest.java | 186 ++++++++++++
...ryMemoryServiceAddSessionToMemoryTest.java | 282 ++++++++++++++++++
pom.xml | 79 ++++-
4 files changed, 544 insertions(+), 24 deletions(-)
create mode 100644 core/src/test/java/com/google/adk/memory/AutoValueMemoryEntryContentTest.java
create mode 100644 core/src/test/java/com/google/adk/memory/InMemoryMemoryServiceAddSessionToMemoryTest.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/memory/AutoValueMemoryEntryContentTest.java b/core/src/test/java/com/google/adk/memory/AutoValueMemoryEntryContentTest.java
new file mode 100644
index 000000000..ca4d95023
--- /dev/null
+++ b/core/src/test/java/com/google/adk/memory/AutoValueMemoryEntryContentTest.java
@@ -0,0 +1,186 @@
+// ********RoostGPT********
+/*
+Test generated by RoostGPT for test unit-java-adk using AI Type Azure Open AI and AI Model gpt-5
+
+ROOST_METHOD_HASH=content_f95ec3ddc9
+ROOST_METHOD_SIG_HASH=content_accc65ce1a
+
+
+Scenario 1: Returns the same Content instance that was supplied at construction
+
+Details:
+ TestName: returnsSameContentInstance
+ Description: Verify that the content() method returns the exact Content object that was used to build the AutoValue_MemoryEntry instance (reference identity, not a copy).
+
+Execution:
+ Arrange: Create a valid Content instance (e.g., a concrete instance or a simple test double) and build a MemoryEntry via the Builder with that Content.
+ Act: Call content() on the built MemoryEntry.
+ Assert: Use JUnit assertions to confirm that the returned Content is the same object instance as the one provided during construction (reference equality).
+
+Validation:
+ This assertion verifies that content() is a simple accessor returning the internal field without copying or transforming it. It ensures the method exposes the exact Content reference stored in the entry, which is important for consumers relying on object identity or avoiding unnecessary allocations.
+
+*/
+
+// ********RoostGPT********
+package com.google.adk.memory;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import com.google.genai.types.Content;
+import javax.annotation.processing.Generated;
+import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@Generated("AutoValueMemoryEntryContentTest")
+@ExtendWith(MockitoExtension.class)
+public class AutoValueMemoryEntryContentTest {
+
+ @Mock private Content contentMock;
+
+ @Mock private Content otherContentMock;
+
+ @Test
+ @Tag("valid")
+ @DisplayName(
+ "returnsSameContentInstance: content() returns the exact Content instance supplied at construction")
+ public void testReturnsSameContentInstance() {
+ MemoryEntry entry =
+ MemoryEntry.builder()
+ .content(contentMock)
+ .author("author-1")
+ .timestamp("2023-01-01T00:00:00Z")
+ .build();
+ Content actual = entry.content();
+ assertSame(
+ (Object) contentMock,
+ (Object) actual,
+ "Expected content() to return the same Content instance");
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName("contentIsNotNullWhenConstructedWithValidContent")
+ public void testContentIsNotNull() {
+ MemoryEntry entry =
+ MemoryEntry.builder()
+ .content(contentMock)
+ .author("author-2")
+ .timestamp("2024-01-01T12:34:56Z")
+ .build();
+ Content actual = entry.content();
+ assertNotNull((Object) actual, "Expected non-null Content from content()");
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName(
+ "contentReferencePreservedByToBuilder: toBuilder().build() preserves original content reference")
+ public void testContentReferencePreservedByToBuilder() {
+ MemoryEntry original =
+ MemoryEntry.builder()
+ .content(contentMock)
+ .author("author-3")
+ .timestamp("2025-05-05T05:05:05Z")
+ .build();
+ MemoryEntry copied = original.toBuilder().build();
+ assertSame(
+ (Object) original.content(),
+ (Object) copied.content(),
+ "Expected copied entry to preserve same Content reference");
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName(
+ "contentReferenceChangesWhenReplaced: toBuilder().content(new).build() updates content reference")
+ public void testContentReferenceChangesWhenReplaced() {
+ MemoryEntry original =
+ MemoryEntry.builder()
+ .content(contentMock)
+ .author("author-4")
+ .timestamp("2026-06-06T06:06:06Z")
+ .build();
+ MemoryEntry updated = original.toBuilder().content(otherContentMock).build();
+ assertSame(
+ (Object) otherContentMock,
+ (Object) updated.content(),
+ "Expected updated entry to return the new Content reference");
+ assertNotSame(
+ (Object) original.content(),
+ (Object) updated.content(),
+ "Expected updated entry content to differ from original content");
+ }
+
+ @Test
+ @Tag("boundary")
+ @DisplayName(
+ "builderAllowsNullOptionalFields: author and timestamp can be null without affecting content")
+ public void testBuilderAllowsNullAuthorAndTimestamp() {
+ MemoryEntry entry =
+ MemoryEntry.builder()
+ .content(contentMock)
+ .author((String) null)
+ .timestamp((String) null)
+ .build();
+ assertSame(
+ (Object) contentMock,
+ (Object) entry.content(),
+ "Expected content() to return the provided Content instance");
+ assertNull((String) entry.author(), "Expected author() to be null when not provided");
+ assertNull((String) entry.timestamp(), "Expected timestamp() to be null when not provided");
+ }
+
+ @Test
+ @Tag("invalid")
+ @DisplayName("buildingWithNullContentThrows: builder rejects null content")
+ public void testBuildingWithNullContentThrowsException() {
+ NullPointerException ex =
+ assertThrows(
+ NullPointerException.class,
+ () ->
+ MemoryEntry.builder()
+ .content((Content) null) // Explicit cast to avoid ambiguity
+ .author("author-5")
+ .timestamp("2027-07-07T07:07:07Z")
+ .build(),
+ "Expected NullPointerException when content is null");
+ assertNotNull((Object) ex, "Expected an exception instance to be thrown");
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName(
+ "distinctEntriesSameContentRef: different entries built with the same Content reference return the same instance via content()")
+ public void testDistinctEntriesWithSameContentReturnSameReference() {
+ MemoryEntry entryA =
+ MemoryEntry.builder()
+ .content(contentMock)
+ .author("author-A")
+ .timestamp("2028-08-08T08:08:08Z")
+ .build();
+ MemoryEntry entryB =
+ MemoryEntry.builder()
+ .content(contentMock) // reusing the same reference
+ .author("author-B")
+ .timestamp("2029-09-09T09:09:09Z")
+ .build();
+ assertSame(
+ (Object) contentMock,
+ (Object) entryA.content(),
+ "Expected entryA to return same Content reference supplied");
+ assertSame(
+ (Object) contentMock,
+ (Object) entryB.content(),
+ "Expected entryB to return same Content reference supplied");
+ assertSame(
+ (Object) entryA.content(),
+ (Object) entryB.content(),
+ "Expected both entries to return the same Content reference");
+ }
+}
diff --git a/core/src/test/java/com/google/adk/memory/InMemoryMemoryServiceAddSessionToMemoryTest.java b/core/src/test/java/com/google/adk/memory/InMemoryMemoryServiceAddSessionToMemoryTest.java
new file mode 100644
index 000000000..90300ef9e
--- /dev/null
+++ b/core/src/test/java/com/google/adk/memory/InMemoryMemoryServiceAddSessionToMemoryTest.java
@@ -0,0 +1,282 @@
+/*
+ * 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=addSessionToMemory_8a630adf5c
+ROOST_METHOD_SIG_HASH=addSessionToMemory_3e3003d0a0
+
+Scenario 1: Successfully stores a session with events that have non-empty parts
+
+Details:
+ TestName: storesSessionWithEventsHavingNonEmptyParts
+ Description: Verifies that addSessionToMemory stores a session whose events include content with present, non-empty parts. Confirms that the returned Completable completes without errors and that the stored events are discoverable via searchMemory.
+
+Execution:
+ Arrange: Create a Session with appName "appA", userId "user1", session id "s1", and events where at least one event has content().isPresent() and parts().isPresent() with a non-empty list containing a Part with non-empty text like "hello world".
+ Act: Invoke addSessionToMemory(session) and await the Completable to complete. Then call searchMemory("appA", "user1", "hello") to retrieve memories.
+ Assert: Assert the Completable completes successfully. Assert that searchMemory returns at least one MemoryEntry with content containing the word "hello".
+
+Validation:
+ Confirms that events meeting the filter (content present, parts present and non-empty) are retained and can be retrieved through searchMemory. Ensures the Completable signals completion, indicating the write to memory occurred.
+
+*/
+
+// ********RoostGPT********
+
+package com.google.adk.memory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.adk.events.Event;
+import com.google.adk.sessions.Session;
+import com.google.genai.types.Content;
+import com.google.genai.types.Part;
+import io.reactivex.rxjava3.core.Completable;
+import io.reactivex.rxjava3.core.Single;
+import java.time.Instant;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+public class InMemoryMemoryServiceAddSessionToMemoryTest {
+
+ private InMemoryMemoryService service;
+
+ @BeforeEach
+ public void setUp() {
+ service = new InMemoryMemoryService();
+ }
+
+ @Test
+ @Tag("integration")
+ @Tag("valid")
+ public void testStoresSessionWithEventsHavingNonEmptyParts() {
+ // Arrange
+ String appName = "appA";
+ String userId = "user1";
+ String sessionId = "s1";
+ long ts = 1_700_000_000L; // example epoch seconds (deterministic, not live)
+ // Mock Part with non-empty text "hello world"
+ Part part = mock(Part.class);
+ when(part.text()).thenReturn(Optional.of("hello world"));
+ // Mock Content with non-empty parts list
+ Content content = mock(Content.class);
+ when(content.parts()).thenReturn(Optional.of(List.of(part)));
+ // Mock Event with content present and timestamp set
+ Event event = mock(Event.class);
+ when(event.content()).thenReturn(Optional.of(content));
+ when(event.author()).thenReturn("user");
+ when(event.timestamp()).thenReturn(ts);
+ // Mock Session
+ Session session = mock(Session.class);
+ when(session.appName()).thenReturn(appName);
+ when(session.userId()).thenReturn(userId);
+ when(session.id()).thenReturn(sessionId);
+ when(session.events()).thenReturn(List.of(event));
+ // Act
+ Completable addCompletable = service.addSessionToMemory(session);
+ addCompletable.test().assertComplete().assertNoErrors();
+ Single searchSingle = service.searchMemory(appName, userId, "hello");
+ SearchMemoryResponse response = searchSingle.blockingGet();
+ // Assert
+ assertNotNull(response, "SearchMemoryResponse should not be null");
+ List memories = response.memories();
+ assertNotNull(memories, "Memories list should not be null");
+ assertTrue((int) memories.size() > 0, "Expected at least one memory to be returned");
+ boolean containsHelloContent =
+ memories.stream()
+ .anyMatch(
+ m -> {
+ Content c = m.content();
+ return c != null
+ && c.parts().isPresent()
+ && c.parts().get().stream()
+ .map(p -> p.text().orElse("").toLowerCase(Locale.ROOT))
+ .anyMatch(t -> t.contains("hello"));
+ });
+ assertTrue(containsHelloContent, "Expected at least one memory containing the word 'hello'");
+ // Also validate timestamp formatting is deterministic for the inserted event
+ String expectedIso = Instant.ofEpochSecond(ts).toString();
+ boolean timestampMatches = memories.stream().anyMatch(m -> expectedIso.equals(m.timestamp()));
+ assertTrue(
+ timestampMatches, "Expected at least one memory with the expected ISO-8601 timestamp");
+ }
+
+ @Test
+ @Tag("boundary")
+ public void testDoesNotStoreEventsWhenPartsAreEmpty() {
+ // Arrange
+ String appName = "appA";
+ String userId = "user1";
+ String sessionId = "s2";
+ // Mock Content with empty parts
+ Content content = mock(Content.class);
+ when(content.parts()).thenReturn(Optional.of(List.of()));
+ // Mock Event with content present but parts empty
+ Event event = mock(Event.class);
+ when(event.content()).thenReturn(Optional.of(content));
+ when(event.author()).thenReturn("user");
+ when(event.timestamp()).thenReturn(123L);
+ // Mock Session
+ Session session = mock(Session.class);
+ when(session.appName()).thenReturn(appName);
+ when(session.userId()).thenReturn(userId);
+ when(session.id()).thenReturn(sessionId);
+ when(session.events()).thenReturn(List.of(event));
+ // Act
+ Completable addCompletable = service.addSessionToMemory(session);
+ addCompletable.test().assertComplete().assertNoErrors();
+ // Query for any word; since parts were empty, there should be no matches
+ SearchMemoryResponse response = service.searchMemory(appName, userId, "anything").blockingGet();
+ // Assert
+ assertNotNull(response, "SearchMemoryResponse should not be null");
+ assertEquals(0, (int) response.memories().size(), "Expected no memories for empty parts");
+ }
+
+ @Test
+ @Tag("invalid")
+ public void testIgnoresEventsWithNoContent() {
+ // Arrange
+ String appName = "appA";
+ String userId = "user1";
+ String sessionId = "s3";
+ // Mock Event with no content
+ Event event = mock(Event.class);
+ when(event.content()).thenReturn(Optional.empty());
+ when(event.author()).thenReturn("user");
+ when(event.timestamp()).thenReturn(456L);
+ // Mock Session
+ Session session = mock(Session.class);
+ when(session.appName()).thenReturn(appName);
+ when(session.userId()).thenReturn(userId);
+ when(session.id()).thenReturn(sessionId);
+ when(session.events()).thenReturn(List.of(event));
+ // Act
+ Completable addCompletable = service.addSessionToMemory(session);
+ addCompletable.test().assertComplete().assertNoErrors();
+ // Assert: no memories should be found for any query
+ SearchMemoryResponse response = service.searchMemory(appName, userId, "query").blockingGet();
+ assertNotNull(response, "SearchMemoryResponse should not be null");
+ assertEquals(
+ 0, (int) response.memories().size(), "Expected no memories when event has no content");
+ }
+
+ @Test
+ @Tag("integration")
+ public void testUserAndAppIsolationAndMultipleSessions() {
+ // Arrange
+ String appName = "appA";
+ String user1 = "user1";
+ String user2 = "user2";
+ // Event for user1: text "alpha"
+ Part partAlpha = mock(Part.class);
+ when(partAlpha.text()).thenReturn(Optional.of("alpha"));
+ Content contentAlpha = mock(Content.class);
+ when(contentAlpha.parts()).thenReturn(Optional.of(List.of(partAlpha)));
+ Event eventAlpha = mock(Event.class);
+ when(eventAlpha.content()).thenReturn(Optional.of(contentAlpha));
+ when(eventAlpha.author()).thenReturn("author1");
+ when(eventAlpha.timestamp()).thenReturn(1000L);
+ Session sessionUser1 = mock(Session.class);
+ when(sessionUser1.appName()).thenReturn(appName);
+ when(sessionUser1.userId()).thenReturn(user1);
+ when(sessionUser1.id()).thenReturn("s1");
+ when(sessionUser1.events()).thenReturn(List.of(eventAlpha));
+ // Event for user2: text "beta"
+ Part partBeta = mock(Part.class);
+ when(partBeta.text()).thenReturn(Optional.of("beta"));
+ Content contentBeta = mock(Content.class);
+ when(contentBeta.parts()).thenReturn(Optional.of(List.of(partBeta)));
+ Event eventBeta = mock(Event.class);
+ when(eventBeta.content()).thenReturn(Optional.of(contentBeta));
+ when(eventBeta.author()).thenReturn("author2");
+ when(eventBeta.timestamp()).thenReturn(2000L);
+ Session sessionUser2 = mock(Session.class);
+ when(sessionUser2.appName()).thenReturn(appName);
+ when(sessionUser2.userId()).thenReturn(user2);
+ when(sessionUser2.id()).thenReturn("s2");
+ when(sessionUser2.events()).thenReturn(List.of(eventBeta));
+ // Act
+ service.addSessionToMemory(sessionUser1).test().assertComplete().assertNoErrors();
+ service.addSessionToMemory(sessionUser2).test().assertComplete().assertNoErrors();
+ // Assert: searching user1 for "alpha" should return results
+ SearchMemoryResponse r1 = service.searchMemory(appName, user1, "alpha").blockingGet();
+ assertNotNull(r1, "Response should not be null");
+ assertTrue((int) r1.memories().size() > 0, "Expected memories for user1 query 'alpha'");
+ // Assert: searching user1 for "beta" should return no results (isolation)
+ SearchMemoryResponse r2 = service.searchMemory(appName, user1, "beta").blockingGet();
+ assertNotNull(r2, "Response should not be null");
+ assertEquals(0, (int) r2.memories().size(), "Expected no memories for user1 query 'beta'");
+ }
+
+ @Test
+ @Tag("integration")
+ public void testOverwriteExistingSessionIdReplacesEvents() {
+ // Arrange
+ String appName = "appA";
+ String userId = "user1";
+ String sessionId = "sOverwrite";
+ // First event: "foo"
+ Part partFoo = mock(Part.class);
+ when(partFoo.text()).thenReturn(Optional.of("foo"));
+ Content contentFoo = mock(Content.class);
+ when(contentFoo.parts()).thenReturn(Optional.of(List.of(partFoo)));
+ Event eventFoo = mock(Event.class);
+ when(eventFoo.content()).thenReturn(Optional.of(contentFoo));
+ when(eventFoo.author()).thenReturn("authorFoo");
+ when(eventFoo.timestamp()).thenReturn(3000L);
+ Session sessionFoo = mock(Session.class);
+ when(sessionFoo.appName()).thenReturn(appName);
+ when(sessionFoo.userId()).thenReturn(userId);
+ when(sessionFoo.id()).thenReturn(sessionId);
+ when(sessionFoo.events()).thenReturn(List.of(eventFoo));
+ // Second event: "bar" with the same session id (overwrite)
+ Part partBar = mock(Part.class);
+ when(partBar.text()).thenReturn(Optional.of("bar"));
+ Content contentBar = mock(Content.class);
+ when(contentBar.parts()).thenReturn(Optional.of(List.of(partBar)));
+ Event eventBar = mock(Event.class);
+ when(eventBar.content()).thenReturn(Optional.of(contentBar));
+ when(eventBar.author()).thenReturn("authorBar");
+ when(eventBar.timestamp()).thenReturn(4000L);
+ Session sessionBar = mock(Session.class);
+ when(sessionBar.appName()).thenReturn(appName);
+ when(sessionBar.userId()).thenReturn(userId);
+ when(sessionBar.id()).thenReturn(sessionId); // same session id
+ when(sessionBar.events()).thenReturn(List.of(eventBar));
+ // Act: add first, then overwrite with second
+ service.addSessionToMemory(sessionFoo).test().assertComplete().assertNoErrors();
+ service.addSessionToMemory(sessionBar).test().assertComplete().assertNoErrors();
+ // Assert: "foo" should no longer be found
+ SearchMemoryResponse rFoo = service.searchMemory(appName, userId, "foo").blockingGet();
+ assertNotNull(rFoo, "Response should not be null");
+ assertEquals(0, (int) rFoo.memories().size(), "Expected no memories for 'foo' after overwrite");
+ // Assert: "bar" should be found
+ SearchMemoryResponse rBar = service.searchMemory(appName, userId, "bar").blockingGet();
+ assertNotNull(rBar, "Response should not be null");
+ assertTrue((int) rBar.memories().size() > 0, "Expected memories for 'bar' after overwrite");
+ }
+}
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