From 591ed6a2feaf7bd50b1b0f6fad85a63ebcb751d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sun, 10 Aug 2025 13:33:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E8=BF=87=E9=95=BF=E5=AF=BC=E8=87=B4=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gxwebsoft/shop/WechatPayDescriptionTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/gxwebsoft/shop/WechatPayDescriptionTest.java b/src/test/java/com/gxwebsoft/shop/WechatPayDescriptionTest.java index a4f7292..f5304e9 100644 --- a/src/test/java/com/gxwebsoft/shop/WechatPayDescriptionTest.java +++ b/src/test/java/com/gxwebsoft/shop/WechatPayDescriptionTest.java @@ -19,13 +19,13 @@ public class WechatPayDescriptionTest { public void testTruncateToByteLimit() { // 测试正常情况 - 字符串长度在限制内 String shortText = "正常商品描述"; - String result1 = truncateToByteLimit(shortText, 127); + String result1 = WechatPayUtils.truncateToByteLimit(shortText, 127); assertEquals(shortText, result1); assertTrue(result1.getBytes(StandardCharsets.UTF_8).length <= 127); // 测试超长中文字符串 String longText = "【湾区认证】【百千万工程帮扶产品 通过远方320项检测 湾区认证 丰江桥佛手瓜面】独特风味低脂轻食便捷速食非油炸 720g/袋"; - String result2 = truncateToByteLimit(longText, 127); + String result2 = WechatPayUtils.truncateToByteLimit(longText, 127); assertNotNull(result2); assertTrue(result2.getBytes(StandardCharsets.UTF_8).length <= 127); System.out.println("原始文本字节数: " + longText.getBytes(StandardCharsets.UTF_8).length); @@ -33,18 +33,18 @@ public class WechatPayDescriptionTest { System.out.println("截断后字节数: " + result2.getBytes(StandardCharsets.UTF_8).length); // 测试null和空字符串 - assertNull(truncateToByteLimit(null, 127)); - assertEquals("", truncateToByteLimit("", 127)); + assertNull(WechatPayUtils.truncateToByteLimit(null, 127)); + assertEquals("", WechatPayUtils.truncateToByteLimit("", 127)); // 测试英文字符串 String englishText = "This is a very long English description that might exceed the byte limit for WeChat Pay description field"; - String result3 = truncateToByteLimit(englishText, 127); + String result3 = WechatPayUtils.truncateToByteLimit(englishText, 127); assertNotNull(result3); assertTrue(result3.getBytes(StandardCharsets.UTF_8).length <= 127); // 测试混合字符串 String mixedText = "Product Name 产品名称 with special characters @#$%^&*()"; - String result4 = truncateToByteLimit(mixedText, 50); + String result4 = WechatPayUtils.truncateToByteLimit(mixedText, 50); assertNotNull(result4); assertTrue(result4.getBytes(StandardCharsets.UTF_8).length <= 50); } @@ -61,7 +61,7 @@ public class WechatPayDescriptionTest { assertTrue(originalBytes > 127, "原始文本应该超过127字节"); // 测试截断 - String truncated = truncateToByteLimit(errorText, 127); + String truncated = WechatPayUtils.processDescription(errorText); int truncatedBytes = truncated.getBytes(StandardCharsets.UTF_8).length; System.out.println("截断后文本: " + truncated);