Skip to content

Commit 33965b6

Browse files
google-genai-botcopybara-github
authored andcommitted
test:Add unit tests
cleanup:Add policy headers to all test files PiperOrigin-RevId: 823641556
1 parent 2a86ae8 commit 33965b6

File tree

10 files changed

+273
-0
lines changed

10 files changed

+273
-0
lines changed

core/src/test/java/com/google/adk/agents/CallbacksTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.agents;
218

319
import static com.google.adk.testing.TestUtils.createEvent;

core/src/test/java/com/google/adk/agents/InstructionTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.agents;
218

319
import static com.google.adk.testing.TestUtils.createInvocationContext;

core/src/test/java/com/google/adk/agents/ParallelAgentTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.agents;
218

319
import static com.google.adk.testing.TestUtils.createInvocationContext;

core/src/test/java/com/google/adk/agents/RunConfigTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.agents;
218

319
import static com.google.common.truth.Truth.assertThat;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.events;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.adk.tools.ToolConfirmation;
22+
import com.google.common.collect.ImmutableMap;
23+
import com.google.genai.types.Part;
24+
import java.util.concurrent.ConcurrentHashMap;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.JUnit4;
28+
29+
@RunWith(JUnit4.class)
30+
public final class EventActionsTest {
31+
32+
private static final Part PART = Part.builder().text("text").build();
33+
private static final ToolConfirmation TOOL_CONFIRMATION =
34+
ToolConfirmation.builder().hint("hint").confirmed(true).build();
35+
36+
@Test
37+
public void toBuilder_createsBuilderWithSameValues() {
38+
EventActions eventActionsWithSkipSummarization =
39+
EventActions.builder().skipSummarization(true).build();
40+
41+
EventActions eventActionsAfterRebuild = eventActionsWithSkipSummarization.toBuilder().build();
42+
43+
assertThat(eventActionsAfterRebuild).isEqualTo(eventActionsWithSkipSummarization);
44+
}
45+
46+
@Test
47+
public void merge_mergesAllFields() {
48+
EventActions eventActions1 =
49+
EventActions.builder()
50+
.skipSummarization(true)
51+
.stateDelta(new ConcurrentHashMap<>(ImmutableMap.of("key1", "value1")))
52+
.artifactDelta(new ConcurrentHashMap<>(ImmutableMap.of("artifact1", PART)))
53+
.requestedAuthConfigs(
54+
new ConcurrentHashMap<>(
55+
ImmutableMap.of("config1", new ConcurrentHashMap<>(ImmutableMap.of("k", "v")))))
56+
.requestedToolConfirmations(
57+
new ConcurrentHashMap<>(ImmutableMap.of("tool1", TOOL_CONFIRMATION)))
58+
.build();
59+
EventActions eventActions2 =
60+
EventActions.builder()
61+
.stateDelta(new ConcurrentHashMap<>(ImmutableMap.of("key2", "value2")))
62+
.artifactDelta(new ConcurrentHashMap<>(ImmutableMap.of("artifact2", PART)))
63+
.transferToAgent("agentId")
64+
.escalate(true)
65+
.requestedAuthConfigs(
66+
new ConcurrentHashMap<>(
67+
ImmutableMap.of("config2", new ConcurrentHashMap<>(ImmutableMap.of("k", "v")))))
68+
.requestedToolConfirmations(
69+
new ConcurrentHashMap<>(ImmutableMap.of("tool2", TOOL_CONFIRMATION)))
70+
.endInvocation(true)
71+
.build();
72+
73+
EventActions merged = eventActions1.toBuilder().merge(eventActions2).build();
74+
75+
assertThat(merged.skipSummarization()).hasValue(true);
76+
assertThat(merged.stateDelta()).containsExactly("key1", "value1", "key2", "value2");
77+
assertThat(merged.artifactDelta()).containsExactly("artifact1", PART, "artifact2", PART);
78+
assertThat(merged.transferToAgent()).hasValue("agentId");
79+
assertThat(merged.escalate()).hasValue(true);
80+
assertThat(merged.requestedAuthConfigs())
81+
.containsExactly(
82+
"config1",
83+
new ConcurrentHashMap<>(ImmutableMap.of("k", "v")),
84+
"config2",
85+
new ConcurrentHashMap<>(ImmutableMap.of("k", "v")));
86+
assertThat(merged.requestedToolConfirmations())
87+
.containsExactly("tool1", TOOL_CONFIRMATION, "tool2", TOOL_CONFIRMATION);
88+
assertThat(merged.endInvocation()).hasValue(true);
89+
}
90+
}

core/src/test/java/com/google/adk/events/EventTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.events;
218

319
import static com.google.common.truth.Truth.assertThat;

core/src/test/java/com/google/adk/plugins/BasePluginTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.plugins;
218

319
import com.google.adk.agents.CallbackContext;

core/src/test/java/com/google/adk/plugins/LoggingPluginTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.plugins;
218

319
import static org.mockito.Mockito.when;

core/src/test/java/com/google/adk/plugins/PluginManagerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.google.adk.plugins;
218

319
import static com.google.common.truth.Truth.assertThat;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.tools;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.junit.runners.JUnit4;
24+
25+
@RunWith(JUnit4.class)
26+
public final class ToolConfirmationTest {
27+
28+
@Test
29+
public void builder_setsDefaultValues() {
30+
ToolConfirmation toolConfirmation = ToolConfirmation.builder().build();
31+
32+
assertThat(toolConfirmation.hint()).isEmpty();
33+
assertThat(toolConfirmation.confirmed()).isFalse();
34+
assertThat(toolConfirmation.payload()).isNull();
35+
}
36+
37+
@Test
38+
public void builder_setsValues() {
39+
ToolConfirmation toolConfirmation =
40+
ToolConfirmation.builder().hint("hint").confirmed(true).payload("payload").build();
41+
42+
assertThat(toolConfirmation.hint()).isEqualTo("hint");
43+
assertThat(toolConfirmation.confirmed()).isTrue();
44+
assertThat(toolConfirmation.payload()).isEqualTo("payload");
45+
}
46+
47+
@Test
48+
public void toBuilder_createsBuilderWithSameValues() {
49+
ToolConfirmation toolConfirmation =
50+
ToolConfirmation.builder().hint("hint").confirmed(true).payload("payload").build();
51+
ToolConfirmation copiedToolConfirmation = toolConfirmation.toBuilder().build();
52+
53+
assertThat(copiedToolConfirmation).isEqualTo(toolConfirmation);
54+
}
55+
}

0 commit comments

Comments
 (0)