Skip to content

Commit 30e062e

Browse files
committed
add test
1 parent 4e30820 commit 30e062e

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

hutool-captcha/src/test/java/cn/hutool/captcha/GifCaptchaUtilTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.jupiter.api.Test;
55

66
import java.awt.*;
7+
import java.awt.image.BufferedImage;
78
import java.io.ByteArrayOutputStream;
89
import java.lang.reflect.Field;
910
import java.lang.reflect.Method;
@@ -88,7 +89,7 @@ public void testGraphicsImage() throws Exception {
8889
Object result = invokePrivateMethod("graphicsImage", new Class[]{char[].class, Color[].class, char[].class, int.class}, new Object[]{chars, colors, chars, 0});
8990

9091
assertNotNull(result, "生成的图片不应该为 null");
91-
assertTrue(result instanceof java.awt.image.BufferedImage, "返回的结果应该是 BufferedImage 类型");
92+
assertInstanceOf(BufferedImage.class, result, "返回的结果应该是 BufferedImage 类型");
9293
}
9394

9495
// 测试 getRandomColor() 方法
@@ -98,7 +99,7 @@ public void testRandomColor() throws Exception {
9899
Object result = invokePrivateMethod("getRandomColor", new Class[]{int.class, int.class}, new Object[]{0, 255});
99100

100101
assertNotNull(result, "生成的颜色不应该为 null");
101-
assertTrue(result instanceof Color, "返回的结果应该是 Color 类型");
102+
assertInstanceOf(Color.class, result, "返回的结果应该是 Color 类型");
102103

103104
Color color = (Color) result;
104105
assertTrue(color.getRed() >= 0 && color.getRed() <= 255, "颜色的红色分量应该在 0 到 255 之间");

hutool-captcha/src/test/java/cn/hutool/captcha/ShearCaptchaTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cn.hutool.captcha;
2-
import cn.hutool.captcha.ShearCaptcha;
2+
33
import cn.hutool.captcha.generator.RandomGenerator;
4-
import cn.hutool.core.img.GraphicsUtil;
5-
import cn.hutool.core.img.ImgUtil;
6-
import cn.hutool.core.util.RandomUtil;
74
import org.junit.jupiter.api.BeforeEach;
85
import org.junit.jupiter.api.Test;
96

@@ -35,7 +32,7 @@ public void testCreateImage() {
3532
String code = "ABCD";
3633
Image image = captcha.createImage(code);
3734
assertNotNull(image, "验证码图片不应该为 null");
38-
assertTrue(image instanceof BufferedImage, "生成的图片应该是 BufferedImage 类型");
35+
assertInstanceOf(BufferedImage.class, image, "生成的图片应该是 BufferedImage 类型");
3936

4037
// 可选:进一步测试图像的内容
4138
BufferedImage bufferedImage = (BufferedImage) image;

0 commit comments

Comments
 (0)