|
17 | 17 | package com.google.adk.models; |
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 21 | +import static org.mockito.Mockito.mock; |
| 22 | +import static org.mockito.Mockito.when; |
20 | 23 |
|
21 | 24 | import com.anthropic.client.AnthropicClient; |
22 | 25 | import com.anthropic.models.messages.ContentBlockParam; |
| 26 | +import com.anthropic.models.messages.Message; |
23 | 27 | import com.anthropic.models.messages.ToolResultBlockParam; |
| 28 | +import com.anthropic.models.messages.Usage; |
24 | 29 | import com.google.common.collect.ImmutableMap; |
25 | 30 | import com.google.genai.types.FunctionResponse; |
26 | 31 | import com.google.genai.types.Part; |
@@ -78,4 +83,21 @@ public void testPartToAnthropicMessageBlock_jsonFallback() throws Exception { |
78 | 83 | ToolResultBlockParam toolResult = result.asToolResult(); |
79 | 84 | assertThat(toolResult.content().get().asString()).contains("\"custom_key\":\"custom_value\""); |
80 | 85 | } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void testClaudeUsageMapping_ShouldFailWhenMappingIsMissing() throws Exception { |
| 89 | + Usage mockUsage = mock(Usage.class); |
| 90 | + when(mockUsage.inputTokens()).thenReturn(10L); |
| 91 | + when(mockUsage.outputTokens()).thenReturn(20L); |
| 92 | + |
| 93 | + Message mockMessage = mock(Message.class); |
| 94 | + when(mockMessage.usage()).thenReturn(mockUsage); |
| 95 | + when(mockMessage.content()).thenReturn(java.util.Collections.emptyList()); |
| 96 | + |
| 97 | + Method convertMethod = |
| 98 | + Claude.class.getDeclaredMethod("convertAnthropicResponseToLlmResponse", Message.class); |
| 99 | + convertMethod.setAccessible(true); |
| 100 | + LlmResponse result = (LlmResponse) convertMethod.invoke(claude, mockMessage); |
| 101 | + assertTrue(result.usageMetadata().isPresent()); |
| 102 | + } |
81 | 103 | } |
0 commit comments