|
1 | 1 | package org.tron.common.logsfilter; |
2 | 2 |
|
| 3 | +import java.lang.reflect.InvocationTargetException; |
| 4 | +import java.lang.reflect.Method; |
3 | 5 | import org.junit.Assert; |
4 | 6 | import org.junit.Test; |
5 | 7 |
|
6 | 8 | public class DesensitizedConverterTest { |
7 | 9 |
|
8 | 10 | @Test |
9 | | - public void testReplace() { |
| 11 | + public void testReplace() |
| 12 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
10 | 13 | DesensitizedConverter converter = new DesensitizedConverter(); |
11 | | - DesensitizedConverter.addSensitive("/192.168.1.10", "address1"); |
12 | | - DesensitizedConverter.addSensitive("/197.168.1.10", "address2"); |
| 14 | + DesensitizedConverter.addSensitive("192.168.1.10", "address1"); |
| 15 | + DesensitizedConverter.addSensitive("197.168.1.10", "address2"); |
| 16 | + |
| 17 | + Method method = converter.getClass().getDeclaredMethod( |
| 18 | + "desensitization", String.class); |
| 19 | + method.setAccessible(true); |
13 | 20 |
|
14 | 21 | String logStr1 = "This is test log /192.168.1.10:100, /197.168.1.10:200, /197.168.1.10:100"; |
15 | | - Assert.assertEquals("This is test log address1:100, address2:200, address2:100", |
16 | | - converter.desensitization(logStr1)); |
| 22 | + String result1 = (String) method.invoke(converter, logStr1); |
| 23 | + Assert.assertEquals("This is test log /address1:100, /address2:200, /address2:100", |
| 24 | + result1); |
17 | 25 |
|
18 | 26 | String logStr2 = "This is test log /192.168.1.100:100, /197.168.1.10:200, /197.168.1.10:100"; |
19 | | - Assert.assertEquals("This is test log unknown:100, address2:200, address2:100", |
20 | | - converter.desensitization(logStr2)); |
| 27 | + String result2 = (String) method.invoke(converter, logStr2); |
| 28 | + Assert.assertEquals("This is test log /IP:100, /address2:200, /address2:100", |
| 29 | + result2); |
21 | 30 | } |
22 | 31 | } |
0 commit comments