MCPcopy Create free account
hub / github.com/LianjiaTech/json-diff / DiffTest

Class DiffTest

src/test/java/com/ke/diff/diff/DiffTest.java:26–127  ·  view source on GitHub ↗

@Author JingWei @create 2022/2/28

Source from the content-addressed store, hash-verified

24 * @create 2022/2/28
25 */
26public class DiffTest {
27 /**
28 * 测试withA withB diff方法
29 */
30 @Test
31 public void diff() {
32 String str1 = "{\"a\":null}";
33 String str2 = "{\"a\":\"\"}";
34 List<Result> diff = new Diff().diff(str1,str2);
35 assertEquals(ResultConvertUtil.TYPE_MODIFY,diff.get(0).getDiffType());
36 }
37
38 /**
39 * 测试withNoisePahList方法
40 */
41 @Test
42 public void diff1() {
43 String str1 = "{\"a\":null}";
44 String str2 = "{\"a\":\"\"}";
45 List<String> noiseList = Lists.newArrayList("a");
46 List<Result> diff = new Diff().withNoisePahList(noiseList).diff(str1, str2);
47 assertEquals(0,diff.size());
48 }
49
50 /**
51 * 测试withPathModule withAlgorithmEnum方法
52 */
53 @Test
54 public void diff3() {
55 String str1 = "{\"a\":null}";
56 String str2 = "{\"a\":\"\"}";
57 List<String> noiseList = Lists.newArrayList("a");
58 List<Result> diff = new Diff().withNoisePahList(noiseList).withAlgorithmEnum(null).diff(str1, str2);
59 assertEquals(0,diff.size());
60 }
61
62 /**
63 * 测试withSpecialPath withAlgorithmEnum withA withB方法
64 */
65 @Test
66 public void diff4() {
67 String str1 = "{\"a\":null}";
68 String str2 = "{\"a\":\"\"}";
69 JsonElement a = new JsonParser().parse(str1);
70 JsonElement b = new JsonParser().parse(str2);
71 List<String> specialPath = new ArrayList<>();
72 List<Result> diff = new Diff().withNoisePahList(null).withSpecialPath(specialPath).withAlgorithmEnum(AlgorithmEnum.SIMLAR_ARRAY_AND_LEFTJOIN_OBJECT).diffElement(a, b);
73 assertEquals(ResultConvertUtil.TYPE_MODIFY, diff.get(0).getDiffType());
74 }
75
76 /**
77 * 测试withObjectAlgorithm withArrayAlgorithm withPrimitiveAlgorithm withNullAlgorithm withOtherAlgorithm方法
78 */
79 @Test
80 public void diff5() {
81 String str1 = "{\"a\":null}";
82 String str2 = "{\"a\":null}";
83 JsonElement a = new JsonParser().parse(str1);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected