-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathDiffJSONVisitorTest.groovy
More file actions
57 lines (44 loc) · 1.65 KB
/
DiffJSONVisitorTest.groovy
File metadata and controls
57 lines (44 loc) · 1.65 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
package de.danielbechler.diff.node
import de.danielbechler.diff.ObjectDifferBuilder
import spock.lang.Specification
class DiffJSONVisitorTest extends Specification {
DiffJSONVisitor visitor
Something workingObject
Something baseObject
def setup() {
workingObject = new Something(name: 'working name', someOther: new Something(name: 'working other'), theSame: 'theSame')
baseObject = new Something(name: 'base name', someOther: new Something(name: 'base other'), theSame: 'theSame')
visitor = new DiffJSONVisitor(workingObject, baseObject)
}
def "something to map"() {
when:
DiffNode root = ObjectDifferBuilder.buildDefault().compare(workingObject, baseObject)
root.visit(visitor)
Map<String, Object> messages = visitor.messagesAsMap
then:
messages.name == 'working name'
messages.someOther.name == 'working other'
}
def "something to json"() {
when:
DiffNode root = ObjectDifferBuilder.buildDefault().compare(workingObject, baseObject)
root.visit(visitor)
String json = visitor.getAsJSON()
then:
json == '{"name":"working name","someOther":{"name":"working other"}}'
}
def "clearing a field"() {
when:
workingObject.name = null
DiffNode root = ObjectDifferBuilder.buildDefault().compare(workingObject, baseObject)
root.visit(visitor)
String json = visitor.getAsJSON()
then:
json == '{"name":null,"someOther":{"name":"working other"}}'
}
static class Something {
String name
String theSame
Something someOther
}
}