1616
1717package com .google .adk .agents ;
1818
19- import static com .google .adk .testing .TestUtils .createEvent ;
20- import static com .google .adk .testing .TestUtils .createInvocationContext ;
21- import static com .google .adk .testing .TestUtils .createSubAgent ;
2219import static com .google .common .truth .Truth .assertThat ;
2320
2421import com .google .adk .events .Event ;
2522import com .google .adk .events .EventActions ;
2623import com .google .adk .testing .TestBaseAgent ;
24+ import com .google .adk .testing .TestUtils ;
2725import com .google .common .collect .ImmutableList ;
2826import io .reactivex .rxjava3 .core .Flowable ;
2927import io .reactivex .rxjava3 .core .Single ;
@@ -39,7 +37,7 @@ public final class PlannerAgentTest {
3937
4038 @ Test
4139 public void runAsync_withDone_stopsImmediately () {
42- TestBaseAgent subAgent = createSubAgent ("sub" , createEvent ("e1" ));
40+ TestBaseAgent subAgent = TestUtils . createSubAgent ("sub" , TestUtils . createEvent ("e1" ));
4341 Planner donePlanner =
4442 new Planner () {
4543 @ Override
@@ -56,15 +54,15 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
5654 PlannerAgent agent =
5755 PlannerAgent .builder ().name ("planner" ).subAgents (subAgent ).planner (donePlanner ).build ();
5856
59- InvocationContext ctx = createInvocationContext (agent );
57+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
6058 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
6159
6260 assertThat (events ).isEmpty ();
6361 }
6462
6563 @ Test
6664 public void runAsync_withDoneWithResult_emitsResultEvent () {
67- TestBaseAgent subAgent = createSubAgent ("sub" );
65+ TestBaseAgent subAgent = TestUtils . createSubAgent ("sub" );
6866 Planner resultPlanner =
6967 new Planner () {
7068 @ Override
@@ -81,7 +79,7 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
8179 PlannerAgent agent =
8280 PlannerAgent .builder ().name ("planner" ).subAgents (subAgent ).planner (resultPlanner ).build ();
8381
84- InvocationContext ctx = createInvocationContext (agent );
82+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
8583 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
8684
8785 assertThat (events ).hasSize (1 );
@@ -90,8 +88,8 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
9088
9189 @ Test
9290 public void runAsync_withNoOp_skipsAndContinues () {
93- Event event1 = createEvent ("e1" );
94- TestBaseAgent subAgent = createSubAgent ("sub" , event1 );
91+ Event event1 = TestUtils . createEvent ("e1" );
92+ TestBaseAgent subAgent = TestUtils . createSubAgent ("sub" , event1 );
9593
9694 AtomicInteger callCount = new AtomicInteger (0 );
9795 Planner noOpThenRunPlanner =
@@ -118,15 +116,16 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
118116 .planner (noOpThenRunPlanner )
119117 .build ();
120118
121- InvocationContext ctx = createInvocationContext (agent );
119+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
122120 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
123121
124122 assertThat (events ).containsExactly (event1 );
125123 }
126124
127125 @ Test
128126 public void runAsync_withMaxIterations_stopsAtLimit () {
129- TestBaseAgent subAgent = createSubAgent ("sub" , () -> Flowable .just (createEvent ("e" )));
127+ TestBaseAgent subAgent =
128+ TestUtils .createSubAgent ("sub" , () -> Flowable .just (TestUtils .createEvent ("e" )));
130129
131130 Planner alwaysRunPlanner =
132131 new Planner () {
@@ -149,7 +148,7 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
149148 .maxIterations (3 )
150149 .build ();
151150
152- InvocationContext ctx = createInvocationContext (agent );
151+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
153152 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
154153
155154 // 3 iterations: first + 2 next calls, each producing 1 event
@@ -158,12 +157,12 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
158157
159158 @ Test
160159 public void runAsync_sequentialPlannerPattern () {
161- Event event1 = createEvent ("e1" );
162- Event event2 = createEvent ("e2" );
163- Event event3 = createEvent ("e3" );
164- TestBaseAgent agentA = createSubAgent ("agentA" , event1 );
165- TestBaseAgent agentB = createSubAgent ("agentB" , event2 );
166- TestBaseAgent agentC = createSubAgent ("agentC" , event3 );
160+ Event event1 = TestUtils . createEvent ("e1" );
161+ Event event2 = TestUtils . createEvent ("e2" );
162+ Event event3 = TestUtils . createEvent ("e3" );
163+ TestBaseAgent agentA = TestUtils . createSubAgent ("agentA" , event1 );
164+ TestBaseAgent agentB = TestUtils . createSubAgent ("agentB" , event2 );
165+ TestBaseAgent agentC = TestUtils . createSubAgent ("agentC" , event3 );
167166
168167 AtomicInteger cursor = new AtomicInteger (0 );
169168 ImmutableList <String > order = ImmutableList .of ("agentA" , "agentB" , "agentC" );
@@ -196,18 +195,18 @@ private Single<PlannerAction> selectNext(PlanningContext context) {
196195 .planner (seqPlanner )
197196 .build ();
198197
199- InvocationContext ctx = createInvocationContext (agent );
198+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
200199 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
201200
202201 assertThat (events ).containsExactly (event1 , event2 , event3 ).inOrder ();
203202 }
204203
205204 @ Test
206205 public void runAsync_withParallelRunAgents_runsMultipleAgents () {
207- Event event1 = createEvent ("e1" );
208- Event event2 = createEvent ("e2" );
209- TestBaseAgent agentA = createSubAgent ("agentA" , event1 );
210- TestBaseAgent agentB = createSubAgent ("agentB" , event2 );
206+ Event event1 = TestUtils . createEvent ("e1" );
207+ Event event2 = TestUtils . createEvent ("e2" );
208+ TestBaseAgent agentA = TestUtils . createSubAgent ("agentA" , event1 );
209+ TestBaseAgent agentB = TestUtils . createSubAgent ("agentB" , event2 );
211210
212211 Planner parallelPlanner =
213212 new Planner () {
@@ -229,7 +228,7 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
229228 .planner (parallelPlanner )
230229 .build ();
231230
232- InvocationContext ctx = createInvocationContext (agent );
231+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
233232 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
234233
235234 assertThat (events ).containsExactly (event1 , event2 );
@@ -257,23 +256,23 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
257256 .planner (planner )
258257 .build ();
259258
260- InvocationContext ctx = createInvocationContext (agent );
259+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
261260 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
262261
263262 assertThat (events ).isEmpty ();
264263 }
265264
266265 @ Test (expected = IllegalStateException .class )
267266 public void builder_withoutPlanner_throwsIllegalState () {
268- TestBaseAgent subAgent = createSubAgent ("sub" );
267+ TestBaseAgent subAgent = TestUtils . createSubAgent ("sub" );
269268 PlannerAgent .builder ().name ("planner" ).subAgents (subAgent ).build ();
270269 }
271270
272271 @ Test
273272 public void runAsync_stateIsSharedAcrossAgents () {
274273 // Agent A writes to state, Agent B reads from state
275274 Event eventA =
276- createEvent ("eA" ).toBuilder ()
275+ TestUtils . createEvent ("eA" ).toBuilder ()
277276 .actions (
278277 EventActions .builder ()
279278 .stateDelta (
@@ -282,8 +281,8 @@ public void runAsync_stateIsSharedAcrossAgents() {
282281 .build ())
283282 .build ();
284283
285- TestBaseAgent agentA = createSubAgent ("agentA" , eventA );
286- TestBaseAgent agentB = createSubAgent ("agentB" , createEvent ("eB" ));
284+ TestBaseAgent agentA = TestUtils . createSubAgent ("agentA" , eventA );
285+ TestBaseAgent agentB = TestUtils . createSubAgent ("agentB" , TestUtils . createEvent ("eB" ));
287286
288287 AtomicInteger cursor = new AtomicInteger (0 );
289288 Planner seqPlanner =
@@ -314,7 +313,7 @@ public Single<PlannerAction> nextAction(PlanningContext context) {
314313 .planner (seqPlanner )
315314 .build ();
316315
317- InvocationContext ctx = createInvocationContext (agent );
316+ InvocationContext ctx = TestUtils . createInvocationContext (agent );
318317 List <Event > events = agent .runAsync (ctx ).toList ().blockingGet ();
319318
320319 // Both events should be emitted
0 commit comments