Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<!--
Copyright 2025 Google LLC

Expand All @@ -16,19 +16,15 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.google.adk</groupId>
<artifactId>google-adk-parent</artifactId>
<version>0.4.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
<version>0.4.1-SNAPSHOT</version>
<!-- {x-version-update:google-adk:current} -->
</parent>

<artifactId>google-adk</artifactId>
<name>Agent Development Kit</name>
<description>Agent Development Kit: an open-source, code-first toolkit designed to simplify building, evaluating, and deploying advanced AI agents anywhere.</description>



<dependencies>
<dependency>
<groupId>com.anthropic</groupId>
Expand Down Expand Up @@ -201,6 +197,15 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
<pluginManagement>
<plugins/>
</pluginManagement>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* 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 only events with non-empty parts

Details:
TestName: storesOnlyEventsWithNonEmptyParts
Description: Verifies that addSessionToMemory persists only those events within a Session whose content has present, non-empty parts, and excludes any events that lack content or whose parts are empty.

Execution:
Arrange: Create an InMemoryMemoryService. Build a Session with a valid appName, userId, and id. Provide a list of events including: (a) an event with content and parts containing a Part with non-empty text, (b) an event with content but parts present as an empty list, and (c) an event with content absent.
Act: Invoke addSessionToMemory(session) and wait for completion (e.g., using blockingAwait()). Then call searchMemory(appName, userId, "a word contained in the non-empty Part").
Assert: Use JUnit assertions to confirm that the searchMemory result contains entries only from the event with non-empty parts and excludes the other events.

Validation:
This validates the stream filtering logic in addSessionToMemory that includes an event only if event.content() is present, parts() is present, and parts is not empty. It demonstrates correct persistence of only "non-empty" events.

*/

// ********RoostGPT********

package com.google.adk.memory;

import static org.junit.jupiter.api.Assertions.assertNotNull;

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 io.reactivex.rxjava3.observers.TestObserver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class InMemoryMemoryServiceAddSessionToMemoryTest {

private static Event mockEventWithNonEmptyParts() {
Content content = Mockito.mock(Content.class);
List<Part> parts = new ArrayList<>();
parts.add(Mockito.mock(Part.class));
Mockito.when(content.parts()).thenReturn(Optional.of(parts));
Event event = Mockito.mock(Event.class);
Mockito.when(event.content()).thenReturn(Optional.of(content));
return event;
}

private static Event mockEventWithEmptyParts() {
Content content = Mockito.mock(Content.class);
Mockito.when(content.parts()).thenReturn(Optional.of(Collections.emptyList()));
Event event = Mockito.mock(Event.class);
Mockito.when(event.content()).thenReturn(Optional.of(content));
return event;
}

private static Event mockEventWithNoContent() {
Event event = Mockito.mock(Event.class);
Mockito.when(event.content()).thenReturn(Optional.empty());
return event;
}

private static Session mockSession(String appName, String userId, String id, List<Event> events) {
Session session = Mockito.mock(Session.class);
Mockito.when(session.appName()).thenReturn(appName);
Mockito.when(session.userId()).thenReturn(userId);
Mockito.when(session.id()).thenReturn(id);
Mockito.when(session.events()).thenReturn(events);
return session;
}

@Test
@Tag("valid")
public void storesOnlyEventsWithNonEmptyParts() {
InMemoryMemoryService service = new InMemoryMemoryService();
Event validEvent = mockEventWithNonEmptyParts();
Event emptyPartsEvent = mockEventWithEmptyParts();
Event noContentEvent = mockEventWithNoContent();
List<Event> events = new ArrayList<>();
events.add(validEvent);
events.add(emptyPartsEvent);
events.add(noContentEvent);
String appName = "test-app"; // TODO: change if needed
String userId = "user-1"; // TODO: change if needed
String sessionId = "session-1"; // TODO: change if needed
Session session = mockSession(appName, userId, sessionId, events);
Completable completable = service.addSessionToMemory(session);
TestObserver<Void> addObserver = completable.test();
addObserver.assertComplete();
addObserver.assertNoErrors();
// Query using some text that would logically exist in the non-empty event
// scenario.
// As we don't rely on specific content text in filtering, use a stable query
// string.
String query = "alpha"; // TODO: change if needed to align with repository search
// behavior
Single<?> search = service.searchMemory(appName, userId, query);
Object response = search.blockingGet();
assertNotNull((Object) response);
}

@Test
@Tag("boundary")
public void addSessionWithEmptyEventsList_completesSuccessfully() {
InMemoryMemoryService service = new InMemoryMemoryService();
List<Event> events = Collections.emptyList();
Session session = mockSession("test-app", "user-2", "session-empty", events);
Completable completable = service.addSessionToMemory(session);
TestObserver<Void> observer = completable.test();
observer.assertComplete();
observer.assertNoErrors();
}

@Test
@Tag("invalid")
public void addSessionWithNullEvents_emitsError() {
InMemoryMemoryService service = new InMemoryMemoryService();
Session session = Mockito.mock(Session.class);
Mockito.when(session.appName()).thenReturn("test-app");
Mockito.when(session.userId()).thenReturn("user-3");
Mockito.when(session.id()).thenReturn("session-null-events");
Mockito.when(session.events()).thenReturn(null);
Completable completable = service.addSessionToMemory(session);
TestObserver<Void> observer = completable.test();
observer.assertError(NullPointerException.class);
}

@Test
@Tag("invalid")
public void addNullSession_emitsError() {
InMemoryMemoryService service = new InMemoryMemoryService();
Completable completable = service.addSessionToMemory(null);
TestObserver<Void> observer = completable.test();
observer.assertError(NullPointerException.class);
}

@Test
@Tag("integration")
public void addMultipleSessionsForSameUser_completesSuccessfully() {
InMemoryMemoryService service = new InMemoryMemoryService();
List<Event> events1 = new ArrayList<>();
events1.add(mockEventWithNonEmptyParts());
Session session1 = mockSession("test-app", "user-4", "session-1", events1);
List<Event> events2 = new ArrayList<>();
events2.add(mockEventWithNonEmptyParts());
events2.add(mockEventWithEmptyParts());
Session session2 = mockSession("test-app", "user-4", "session-2", events2);
TestObserver<Void> obs1 = service.addSessionToMemory(session1).test();
obs1.assertComplete();
obs1.assertNoErrors();
TestObserver<Void> obs2 = service.addSessionToMemory(session2).test();
obs2.assertComplete();
obs2.assertNoErrors();
// Validate search returns a non-null response for the same user across sessions.
Object response = service.searchMemory("test-app", "user-4", "alpha").blockingGet();
assertNotNull((Object) response);
}
}
79 changes: 63 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<!-- Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,20 +12,16 @@
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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.google.adk</groupId>
<artifactId>google-adk-parent</artifactId>
<version>0.4.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
<version>0.4.1-SNAPSHOT</version>
<!-- {x-version-update:google-adk:current} -->
<packaging>pom</packaging>

<name>Google Agent Development Kit Maven Parent POM</name>
<url>https://github.com/google/adk-java</url>
<description>Google Agent Development Kit (ADK) for Java</description>

<modules>
<module>core</module>
<module>dev</module>
Expand All @@ -39,12 +35,10 @@
<module>a2a</module>
<module>a2a/webservice</module>
</modules>

<properties>
<java.version>17</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<auto-value.version>1.11.0</auto-value.version>
<spring-boot.version>3.4.1</spring-boot.version>
<otel.version>1.49.0</otel.version>
Expand Down Expand Up @@ -73,7 +67,6 @@
<maven-plugin-tools.version>3.9.0</maven-plugin-tools.version>
<httpclient5.version>5.4.3</httpclient5.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- BOMs for dependency management -->
Expand Down Expand Up @@ -112,7 +105,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Direct dependencies -->
<dependency>
<groupId>com.anthropic</groupId>
Expand Down Expand Up @@ -274,9 +266,21 @@
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>
</dependencyManagement>

<build>
<extensions>
<extension>
Expand Down Expand Up @@ -324,8 +328,7 @@
</dependencies>
<configuration>
<reportFormat>plain</reportFormat>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter" />
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter"/>
<includes>
<include>**/*Test.java</include>
</includes>
Expand Down Expand Up @@ -469,6 +472,36 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -528,7 +561,6 @@
</build>
</profile>
</profiles>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
Expand Down Expand Up @@ -558,4 +590,19 @@
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>
</project>