@@ -20,6 +20,7 @@ import de.danielbechler.diff.ObjectDifferBuilder
2020import de.danielbechler.diff.introspection.ObjectDiffProperty
2121import de.danielbechler.diff.path.NodePath
2222import de.danielbechler.diff.selector.CollectionItemElementSelector
23+ import groovy.transform.EqualsAndHashCode
2324import spock.lang.Specification
2425
2526/**
@@ -29,8 +30,8 @@ import spock.lang.Specification
2930class InclusionAT extends Specification {
3031
3132 def objectDifferBuilder = ObjectDifferBuilder . startBuilding()
32- def base = new Album (artist : ' Pharrell Williams' , songs : [' Happy' ])
33- def working = new Album (artist : ' N.E.R.D.' , songs : [' It' ])
33+ def base = new Album (artist : new Artist ( name : ' Pharrell Williams' ) , songs : [new Song ( durationInSeconds : 130 , title : ' Happy' ) ])
34+ def working = new Album (artist : new Artist ( name : ' N.E.R.D.' ) , songs : [new Song ( durationInSeconds : 150 , title : ' It' ) ])
3435
3536 def ' exclude an element by type' () {
3637 given :
@@ -74,7 +75,7 @@ class InclusionAT extends Specification {
7475
7576 def ' include an element by type' () {
7677 given :
77- objectDifferBuilder. inclusion(). include(). type(ArrayList )
78+ objectDifferBuilder. inclusion(). include(). type(ArrayList ). type( Song )
7879 when :
7980 def node = objectDifferBuilder. build(). compare(working, base)
8081 then :
@@ -139,32 +140,43 @@ class InclusionAT extends Specification {
139140 when :
140141 def node = objectDifferBuilder. build(). compare(working, base)
141142 then :
142- node. getChild(' songs' ). getChild(new CollectionItemElementSelector (' Happy' )). removed
143- node. getChild(' songs' ). getChild(new CollectionItemElementSelector (' It' )). added
143+ node. getChild(' songs' ). getChild(new CollectionItemElementSelector (new Song ( title : ' Happy' ) )). removed
144+ node. getChild(' songs' ). getChild(new CollectionItemElementSelector (new Song ( title : ' It' ) )). added
144145 }
145146
146147 def ' including an element by path implicitly includes its parents' () {
147148 given :
148149 objectDifferBuilder. inclusion()
149- .include(). node(NodePath . startBuilding(). propertyName(' songs' ). collectionItem(' Happy' ). build())
150+ .include(). node(NodePath . startBuilding(). propertyName(' songs' ). collectionItem(new Song ( title : ' Happy' ) ). build())
150151 when :
151152 def node = objectDifferBuilder. build(). compare(working, base)
152153 then :
153- node. getChild(' songs' ). getChild(new CollectionItemElementSelector (' Happy' )). removed
154+ node. getChild(' songs' ). getChild(new CollectionItemElementSelector (new Song ( title : ' Happy' ) )). removed
154155 node. getChild(' songs' ). childCount() == 1
155156 }
156157
157158 class Album {
158- def String artist
159- def ArrayList<String > songs
159+ def Artist artist
160+ def ArrayList<Song > songs
160161
161162 @ObjectDiffProperty (categories = [' foo' ])
162- ArrayList<String > getSongs () {
163+ ArrayList<Song > getSongs () {
163164 return songs
164165 }
165166
166- void setSongs (ArrayList<String > songs ) {
167+ void setSongs (ArrayList<Song > songs ) {
167168 this . songs = songs
168169 }
169170 }
171+
172+ @EqualsAndHashCode (includeFields = true )
173+ class Artist {
174+ def String name
175+ }
176+
177+ @EqualsAndHashCode (includeFields = true , includes = [' title' ])
178+ class Song {
179+ def String title
180+ def int durationInSeconds
181+ }
170182}
0 commit comments