@@ -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}
0 commit comments