Skip to content

Commit 7623069

Browse files
zhansheng.lzsclaude
andcommitted
Translate plugins UT comments to English and apply google-java-format.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent bdbbc6a commit 7623069

2 files changed

Lines changed: 24 additions & 52 deletions

File tree

src/test/java/com/alibaba/dashscope/TestGenerationUsagePlugins.java

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@ public class TestGenerationUsagePlugins {
1515

1616
private static final Gson GSON = new Gson();
1717

18-
/**
19-
* 验证 GenerationUsage 声明了 plugins 字段(反射检查,对应客户 dump 逻辑)。
20-
*/
18+
/** Verify that GenerationUsage declares the 'plugins' field (reflection-based check). */
2119
@Test
2220
public void testPluginsFieldDeclared() {
2321
List<String> fieldNames =
2422
Arrays.stream(GenerationUsage.class.getDeclaredFields())
2523
.map(Field::getName)
2624
.collect(Collectors.toList());
2725

28-
assertTrue(fieldNames.contains("plugins"),
26+
assertTrue(
27+
fieldNames.contains("plugins"),
2928
"GenerationUsage should declare 'plugins' field, actual fields: " + fieldNames);
3029
}
3130

32-
/**
33-
* 验证 plugins 字段的 @SerializedName 值为 "plugins"。
34-
*/
31+
/** Verify the @SerializedName value of the 'plugins' field is "plugins". */
3532
@Test
3633
public void testPluginsSerializedName() throws NoSuchFieldException {
3734
Field pluginsField = GenerationUsage.class.getDeclaredField("plugins");
@@ -41,20 +38,18 @@ public void testPluginsSerializedName() throws NoSuchFieldException {
4138
assertEquals("plugins", annotation.value());
4239
}
4340

44-
/**
45-
* 验证 getPlugins() 方法存在且可调用。
46-
*/
41+
/** Verify the lombok-generated getPlugins() method exists and is callable. */
4742
@Test
4843
public void testGetPluginsMethodExists() {
4944
GenerationUsage usage = GenerationUsage.builder().build();
50-
// 不抛异常即说明 getPlugins() 方法存在
45+
// Calling without exception confirms getPlugins() exists.
5146
assertDoesNotThrow(usage::getPlugins);
5247
assertNull(usage.getPlugins(), "plugins should be null when not set");
5348
}
5449

5550
/**
56-
* 模拟服务端返回含 usage.plugins.search 的 JSON,验证 Gson 反序列化后能正确读取。
57-
* 对应客户真实调用场景:request_id 541336c2-... 返回的 JSON 结构。
51+
* Simulate a server response containing usage.plugins.search and verify Gson can deserialize it
52+
* end-to-end into the typed Plugins inner class.
5853
*/
5954
@Test
6055
public void testGsonDeserializeWithPlugins() {
@@ -83,17 +78,11 @@ public void testGsonDeserializeWithPlugins() {
8378
assertEquals("web_search", usage.getPlugins().getSearch().getStrategy());
8479
}
8580

86-
/**
87-
* 验证不含 plugins 的旧版 JSON 仍能正常反序列化(向后兼容)。
88-
*/
81+
/** Verify legacy JSON without the 'plugins' field still deserializes (backward compatible). */
8982
@Test
9083
public void testGsonDeserializeWithoutPlugins() {
9184
String json =
92-
"{"
93-
+ "\"input_tokens\": 100,"
94-
+ "\"output_tokens\": 50,"
95-
+ "\"total_tokens\": 150"
96-
+ "}";
85+
"{" + "\"input_tokens\": 100," + "\"output_tokens\": 50," + "\"total_tokens\": 150" + "}";
9786

9887
GenerationUsage usage = GSON.fromJson(json, GenerationUsage.class);
9988

@@ -103,9 +92,7 @@ public void testGsonDeserializeWithoutPlugins() {
10392
assertNull(usage.getPlugins(), "plugins should be null when not present in JSON");
10493
}
10594

106-
/**
107-
* 验证 plugins.search 部分字段缺失时不会报错。
108-
*/
95+
/** Verify that a partial plugins.search payload (missing optional fields) does not error. */
10996
@Test
11097
public void testGsonDeserializeWithPartialPlugins() {
11198
String json =
@@ -125,7 +112,7 @@ public void testGsonDeserializeWithPartialPlugins() {
125112
assertNotNull(usage.getPlugins());
126113
assertNotNull(usage.getPlugins().getSearch());
127114
assertEquals(5, (int) usage.getPlugins().getSearch().getCount());
128-
assertNull(usage.getPlugins().getSearch().getStrategy(),
129-
"strategy should be null when not present");
115+
assertNull(
116+
usage.getPlugins().getSearch().getStrategy(), "strategy should be null when not present");
130117
}
131118
}

src/test/java/com/alibaba/dashscope/TestMultiModalConversationUsagePlugins.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@ public class TestMultiModalConversationUsagePlugins {
1515

1616
private static final Gson GSON = new Gson();
1717

18-
/**
19-
* 验证 MultiModalConversationUsage 声明了 plugins 字段(反射检查)。
20-
*/
18+
/** Verify that MultiModalConversationUsage declares the 'plugins' field (reflection-based). */
2119
@Test
2220
public void testPluginsFieldDeclared() {
2321
List<String> fieldNames =
2422
Arrays.stream(MultiModalConversationUsage.class.getDeclaredFields())
2523
.map(Field::getName)
2624
.collect(Collectors.toList());
2725

28-
assertTrue(fieldNames.contains("plugins"),
26+
assertTrue(
27+
fieldNames.contains("plugins"),
2928
"MultiModalConversationUsage should declare 'plugins' field, actual fields: " + fieldNames);
3029
}
3130

32-
/**
33-
* 验证 plugins 字段的 @SerializedName 值为 "plugins"。
34-
*/
31+
/** Verify the @SerializedName value of the 'plugins' field is "plugins". */
3532
@Test
3633
public void testPluginsSerializedName() throws NoSuchFieldException {
3734
Field pluginsField = MultiModalConversationUsage.class.getDeclaredField("plugins");
@@ -41,19 +38,15 @@ public void testPluginsSerializedName() throws NoSuchFieldException {
4138
assertEquals("plugins", annotation.value());
4239
}
4340

44-
/**
45-
* 验证 getPlugins() 方法存在且可调用。
46-
*/
41+
/** Verify the lombok-generated getPlugins() method exists and is callable. */
4742
@Test
4843
public void testGetPluginsMethodExists() {
4944
MultiModalConversationUsage usage = new MultiModalConversationUsage();
5045
assertDoesNotThrow(usage::getPlugins);
5146
assertNull(usage.getPlugins(), "plugins should be null when not set");
5247
}
5348

54-
/**
55-
* 模拟服务端返回含 usage.plugins.search 的 JSON,验证 Gson 反序列化后能正确读取。
56-
*/
49+
/** Simulate a server response containing usage.plugins.search and verify Gson can deserialize. */
5750
@Test
5851
public void testGsonDeserializeWithPlugins() {
5952
String json =
@@ -83,17 +76,11 @@ public void testGsonDeserializeWithPlugins() {
8376
assertEquals("web_search", usage.getPlugins().getSearch().getStrategy());
8477
}
8578

86-
/**
87-
* 验证不含 plugins 的旧版 JSON 仍能正常反序列化(向后兼容)。
88-
*/
79+
/** Verify legacy JSON without the 'plugins' field still deserializes (backward compatible). */
8980
@Test
9081
public void testGsonDeserializeWithoutPlugins() {
9182
String json =
92-
"{"
93-
+ "\"input_tokens\": 100,"
94-
+ "\"output_tokens\": 50,"
95-
+ "\"total_tokens\": 150"
96-
+ "}";
83+
"{" + "\"input_tokens\": 100," + "\"output_tokens\": 50," + "\"total_tokens\": 150" + "}";
9784

9885
MultiModalConversationUsage usage = GSON.fromJson(json, MultiModalConversationUsage.class);
9986

@@ -103,9 +90,7 @@ public void testGsonDeserializeWithoutPlugins() {
10390
assertNull(usage.getPlugins(), "plugins should be null when not present in JSON");
10491
}
10592

106-
/**
107-
* 验证 plugins.search 部分字段缺失时不会报错。
108-
*/
93+
/** Verify that a partial plugins.search payload (missing optional fields) does not error. */
10994
@Test
11095
public void testGsonDeserializeWithPartialPlugins() {
11196
String json =
@@ -125,7 +110,7 @@ public void testGsonDeserializeWithPartialPlugins() {
125110
assertNotNull(usage.getPlugins());
126111
assertNotNull(usage.getPlugins().getSearch());
127112
assertEquals(5, (int) usage.getPlugins().getSearch().getCount());
128-
assertNull(usage.getPlugins().getSearch().getStrategy(),
129-
"strategy should be null when not present");
113+
assertNull(
114+
usage.getPlugins().getSearch().getStrategy(), "strategy should be null when not present");
130115
}
131116
}

0 commit comments

Comments
 (0)