3636import com .google .genai .types .FunctionCall ;
3737import com .google .genai .types .FunctionResponse ;
3838import com .google .genai .types .Part ;
39+ import java .util .Optional ;
3940import org .junit .Test ;
4041import org .junit .runner .RunWith ;
4142import org .junit .runners .JUnit4 ;
4243
4344@ RunWith (JUnit4 .class )
4445public class RequestConfirmationLlmRequestProcessorTest {
45- private static final String ORIGINAL_FUNCTION_CALL_ID = "fc0" ;
46- private static final String REQUEST_CONFIRMATION_FUNCTION_CALL_ID = "fc1" ;
4746 private static final String ECHO_TOOL_NAME = "echo_tool" ;
47+ private static final String ORIGINAL_FUNCTION_CALL_ID = "original_fc_id" ;
48+ private static final ImmutableMap <String , Object > ORIGINAL_FUNCTION_CALL_ARGS =
49+ ImmutableMap .of ("say" , "hello" );
50+ private static final String FUNCTION_CALL_ID = "fc_id" ;
51+ private static final ImmutableMap <String , Object > ARGS =
52+ ImmutableMap .of (
53+ "originalFunctionCall" ,
54+ ImmutableMap .of ( // original function call as a map
55+ "id" ,
56+ Optional .of ("original_fc_id" ),
57+ "name" ,
58+ Optional .of (ECHO_TOOL_NAME ),
59+ "args" ,
60+ Optional .of (ORIGINAL_FUNCTION_CALL_ARGS )));
61+ private static final FunctionCall FUNCTION_CALL =
62+ FunctionCall .builder ().id (FUNCTION_CALL_ID ).name (ECHO_TOOL_NAME ).args (ARGS ).build ();
4863
4964 private static final Event REQUEST_CONFIRMATION_EVENT =
5065 Event .builder ()
5166 .author ("model" )
52- .content (
53- Content .fromParts (
54- Part .builder ()
55- .functionCall (
56- FunctionCall .builder ()
57- .id (REQUEST_CONFIRMATION_FUNCTION_CALL_ID )
58- .name (REQUEST_CONFIRMATION_FUNCTION_CALL_NAME )
59- .args (
60- ImmutableMap .of (
61- "originalFunctionCall" ,
62- ImmutableMap .of (
63- "id" ,
64- ORIGINAL_FUNCTION_CALL_ID ,
65- "name" ,
66- ECHO_TOOL_NAME ,
67- "args" ,
68- ImmutableMap .of ("say" , "hello" ))))
69- .build ())
70- .build ()))
67+ .content (Content .fromParts (Part .builder ().functionCall (FUNCTION_CALL ).build ()))
7168 .build ();
7269
7370 private static final Event USER_CONFIRMATION_EVENT =
@@ -78,7 +75,7 @@ public class RequestConfirmationLlmRequestProcessorTest {
7875 Part .builder ()
7976 .functionResponse (
8077 FunctionResponse .builder ()
81- .id (REQUEST_CONFIRMATION_FUNCTION_CALL_ID )
78+ .id (FUNCTION_CALL_ID )
8279 .name (REQUEST_CONFIRMATION_FUNCTION_CALL_NAME )
8380 .response (ImmutableMap .of ("confirmed" , true ))
8481 .build ())
@@ -93,7 +90,7 @@ public class RequestConfirmationLlmRequestProcessorTest {
9390 Part .builder ()
9491 .functionResponse (
9592 FunctionResponse .builder ()
96- .id (REQUEST_CONFIRMATION_FUNCTION_CALL_ID )
93+ .id (FUNCTION_CALL_ID )
9794 .name (REQUEST_CONFIRMATION_FUNCTION_CALL_NAME )
9895 .response (ImmutableMap .of ("confirmed" , false ))
9996 .build ())
@@ -208,8 +205,7 @@ public void runAsync_withConfirmationAndToolAlreadyCalled_doesNotCallOriginalFun
208205 FunctionResponse .builder ()
209206 .id (ORIGINAL_FUNCTION_CALL_ID )
210207 .name (ECHO_TOOL_NAME )
211- .response (
212- ImmutableMap .of ("result" , ImmutableMap .of ("say" , "hello" )))
208+ .response (ImmutableMap .of ("result" , ORIGINAL_FUNCTION_CALL_ARGS ))
213209 .build ())
214210 .build ()))
215211 .build ();
0 commit comments