1717package de.danielbechler.diff.path
1818
1919import de.danielbechler.diff.selector.BeanPropertyElementSelector
20+ import de.danielbechler.diff.selector.CollectionItemElementSelector
21+ import de.danielbechler.diff.selector.MapKeyElementSelector
2022import de.danielbechler.diff.selector.RootElementSelector
2123import spock.lang.Specification
2224import spock.lang.Unroll
@@ -92,4 +94,72 @@ class NodePathTest extends Specification {
9294 NodePath . with(' a' , ' b' ) | NodePath . with(' a' ) || 1
9395 NodePath . with(' a' ) | NodePath . with(' b' ) || 1
9496 }
95- }
97+
98+ def ' startBuilding without elements' () {
99+ expect :
100+ NodePath . startBuilding(). build(). elementSelectors == [RootElementSelector . instance]
101+ }
102+
103+ def ' startBuilding with element' () {
104+ def elementSelector = new CollectionItemElementSelector (" foo" )
105+ expect :
106+ NodePath . startBuilding(). element(elementSelector). build(). elementSelectors == [
107+ RootElementSelector . instance,
108+ elementSelector
109+ ]
110+ }
111+
112+ def ' startBuilding with propertyName' () {
113+ expect :
114+ NodePath . startBuilding(). propertyName(" foo" , " bar" ). build(). elementSelectors == [
115+ RootElementSelector . getInstance(),
116+ new BeanPropertyElementSelector (" foo" ),
117+ new BeanPropertyElementSelector (" bar" )
118+ ]
119+ }
120+
121+ def ' startBuilding with mapKey' () {
122+ expect :
123+ NodePath . startBuilding(). mapKey(" foo" ). build(). elementSelectors == [
124+ RootElementSelector . instance,
125+ new MapKeyElementSelector (" foo" )
126+ ]
127+ }
128+
129+ def ' startBuilding with mapKey throws IllegalArgumentException when key is null' () {
130+ when :
131+ NodePath . startBuilding(). mapKey(null ). build()
132+ then :
133+ thrown IllegalArgumentException
134+ }
135+
136+ def ' startBuilding with collectionItem' () {
137+ expect :
138+ NodePath . startBuilding(). collectionItem(" foo" ). build(). elementSelectors == [
139+ RootElementSelector . instance,
140+ new CollectionItemElementSelector (" foo" )
141+ ]
142+ }
143+
144+ def ' startBuildingFrom' () {
145+ expect :
146+ NodePath . startBuildingFrom(NodePath . with(" foo" )). build(). elementSelectors == [
147+ RootElementSelector . getInstance(),
148+ new BeanPropertyElementSelector (" foo" )
149+ ]
150+ }
151+
152+ def ' startBuildingFrom: throws IllegalArgumentException when called with null' () {
153+ when :
154+ NodePath . startBuildingFrom(null ). build()
155+ then :
156+ thrown IllegalArgumentException
157+ }
158+
159+ def ' withRoot: build path with only the root element' () {
160+ expect :
161+ NodePath . withRoot(). elementSelectors == [
162+ RootElementSelector . instance
163+ ]
164+ }
165+ }
0 commit comments