Skip to content

Commit 22f418b

Browse files
committed
🎨 优化单元测试
1 parent 02bc748 commit 22f418b

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/main/java/cn/binarywang/tools/generator/util/ChineseCharUtils.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,5 @@ public static char getOneOddChar() {
184184
.charAt(random.nextInt(ODD_CHINESE_CHARS.length()));
185185
}
186186

187-
public static void main(String args[]) {
188-
System.out.println(genOneChineseChars());
189-
System.out.println(genFixedLengthChineseChars(20));
190-
System.out.println(genRandomLengthChineseChars(2, 10));
191-
}
187+
192188
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.binarywang.tools.generator.util;
2+
3+
import org.testng.annotations.Test;
4+
5+
import static cn.binarywang.tools.generator.util.ChineseCharUtils.*;
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
/**
9+
* 单元测试.
10+
*
11+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
12+
* @date 2020-10-03
13+
*/
14+
@Test
15+
public class ChineseCharUtilsTest {
16+
public void testGenOneChineseChars() {
17+
final String result = genOneChineseChars();
18+
System.out.println(result);
19+
assertThat(result).hasSize(1);
20+
}
21+
22+
public void testGenFixedLengthChineseChars() {
23+
final String result = genFixedLengthChineseChars(20);
24+
System.out.println(result);
25+
assertThat(result).hasSize(20);
26+
}
27+
28+
public void testGenRandomLengthChineseChars() {
29+
final String result = genRandomLengthChineseChars(2, 10);
30+
System.out.println(result);
31+
assertThat(result).hasSizeBetween(2, 10);
32+
}
33+
34+
public void testGetOneOddChar() {
35+
final char result = getOneOddChar();
36+
System.out.println(result);
37+
assertThat(result).isNotNull();
38+
}
39+
}

0 commit comments

Comments
 (0)