forked from SQiShER/java-object-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffTest.java
More file actions
61 lines (45 loc) · 1.38 KB
/
DiffTest.java
File metadata and controls
61 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package demo;
import de.danielbechler.diff.ObjectDifferBuilder;
import de.danielbechler.diff.node.DiffNode;
import de.danielbechler.diff.selector.BeanPropertyElementSelector;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.text.MessageFormat;
@RunWith(JUnit4.class)
public class DiffTest {
private static User user1;
private static User user2;
static {
user1 = new User("xujie", 23);
user2 = new User("xiehuiru", 20);
}
@Test
public void diff_test1() {
DiffNode compare = ObjectDifferBuilder.buildDefault().compare(user1, user2);
compare.visitChildren((node,visit)->{
System.out.println(MessageFormat.format("key:{0},value:{1}",
((BeanPropertyElementSelector)node.getElementSelector()),node.canonicalGet(user2)));
});
}
static class User{
public User(String username,int age){
this.username = username;
this.age = age;
}
private String username;
private int age;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}