提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.desensitize.core; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.util.json.JsonUtils; |
|
4 |
import com.iailab.framework.desensitize.core.regex.annotation.EmailDesensitize; |
|
5 |
import com.iailab.framework.desensitize.core.regex.annotation.RegexDesensitize; |
|
6 |
import com.iailab.framework.desensitize.core.annotation.Address; |
|
7 |
import com.iailab.framework.desensitize.core.slider.annotation.BankCardDesensitize; |
|
8 |
import com.iailab.framework.desensitize.core.slider.annotation.CarLicenseDesensitize; |
|
9 |
import com.iailab.framework.desensitize.core.slider.annotation.ChineseNameDesensitize; |
|
10 |
import com.iailab.framework.desensitize.core.slider.annotation.FixedPhoneDesensitize; |
|
11 |
import com.iailab.framework.desensitize.core.slider.annotation.IdCardDesensitize; |
|
12 |
import com.iailab.framework.desensitize.core.slider.annotation.PasswordDesensitize; |
|
13 |
import com.iailab.framework.desensitize.core.slider.annotation.MobileDesensitize; |
|
14 |
import com.iailab.framework.desensitize.core.slider.annotation.SliderDesensitize; |
|
15 |
import lombok.Data; |
|
16 |
import org.junit.jupiter.api.Test; |
|
17 |
import org.junit.jupiter.api.extension.ExtendWith; |
|
18 |
import org.mockito.junit.jupiter.MockitoExtension; |
|
19 |
|
|
20 |
import static org.junit.jupiter.api.Assertions.*; |
|
21 |
|
|
22 |
/** |
|
23 |
* {@link DesensitizeTest} 的单元测试 |
|
24 |
*/ |
|
25 |
@ExtendWith(MockitoExtension.class) |
|
26 |
public class DesensitizeTest { |
|
27 |
|
|
28 |
@Test |
|
29 |
public void test() { |
|
30 |
// 准备参数 |
|
31 |
DesensitizeDemo desensitizeDemo = new DesensitizeDemo(); |
|
32 |
desensitizeDemo.setNickname("iailab"); |
|
33 |
desensitizeDemo.setBankCard("9988002866797031"); |
|
34 |
desensitizeDemo.setCarLicense("粤A66666"); |
|
35 |
desensitizeDemo.setFixedPhone("01086551122"); |
|
36 |
desensitizeDemo.setIdCard("530321199204074611"); |
|
37 |
desensitizeDemo.setPassword("123456"); |
|
38 |
desensitizeDemo.setPhoneNumber("13248765917"); |
|
39 |
desensitizeDemo.setSlider1("ABCDEFG"); |
|
40 |
desensitizeDemo.setSlider2("ABCDEFG"); |
|
41 |
desensitizeDemo.setSlider3("ABCDEFG"); |
|
42 |
desensitizeDemo.setEmail("1@email.com"); |
|
43 |
desensitizeDemo.setRegex("你好,我是iailab"); |
|
44 |
desensitizeDemo.setAddress("北京市海淀区上地十街10号"); |
|
45 |
desensitizeDemo.setOrigin("iailab"); |
|
46 |
|
|
47 |
// 调用 |
|
48 |
DesensitizeDemo d = JsonUtils.parseObject(JsonUtils.toJsonString(desensitizeDemo), DesensitizeDemo.class); |
|
49 |
// 断言 |
|
50 |
assertNotNull(d); |
|
51 |
assertEquals("芋***", d.getNickname()); |
|
52 |
assertEquals("998800********31", d.getBankCard()); |
|
53 |
assertEquals("粤A6***6", d.getCarLicense()); |
|
54 |
assertEquals("0108*****22", d.getFixedPhone()); |
|
55 |
assertEquals("530321**********11", d.getIdCard()); |
|
56 |
assertEquals("******", d.getPassword()); |
|
57 |
assertEquals("132****5917", d.getPhoneNumber()); |
|
58 |
assertEquals("#######", d.getSlider1()); |
|
59 |
assertEquals("ABC*EFG", d.getSlider2()); |
|
60 |
assertEquals("*******", d.getSlider3()); |
|
61 |
assertEquals("1****@email.com", d.getEmail()); |
|
62 |
assertEquals("你好,我是*", d.getRegex()); |
|
63 |
assertEquals("北京市海淀区上地十街10号*", d.getAddress()); |
|
64 |
assertEquals("iailab", d.getOrigin()); |
|
65 |
} |
|
66 |
|
|
67 |
@Data |
|
68 |
public static class DesensitizeDemo { |
|
69 |
|
|
70 |
@ChineseNameDesensitize |
|
71 |
private String nickname; |
|
72 |
@BankCardDesensitize |
|
73 |
private String bankCard; |
|
74 |
@CarLicenseDesensitize |
|
75 |
private String carLicense; |
|
76 |
@FixedPhoneDesensitize |
|
77 |
private String fixedPhone; |
|
78 |
@IdCardDesensitize |
|
79 |
private String idCard; |
|
80 |
@PasswordDesensitize |
|
81 |
private String password; |
|
82 |
@MobileDesensitize |
|
83 |
private String phoneNumber; |
|
84 |
@SliderDesensitize(prefixKeep = 6, suffixKeep = 1, replacer = "#") |
|
85 |
private String slider1; |
|
86 |
@SliderDesensitize(prefixKeep = 3, suffixKeep = 3) |
|
87 |
private String slider2; |
|
88 |
@SliderDesensitize(prefixKeep = 10) |
|
89 |
private String slider3; |
|
90 |
@EmailDesensitize |
|
91 |
private String email; |
|
92 |
@RegexDesensitize(regex = "iailab", replacer = "*") |
|
93 |
private String regex; |
|
94 |
@Address |
|
95 |
private String address; |
|
96 |
private String origin; |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
} |