@@ -17,6 +17,8 @@ package io.fabric8.mockwebserver.crud
1717
1818import spock.lang.Specification
1919
20+ import java.util.stream.Collectors
21+
2022class AttributeSetTest extends Specification {
2123
2224 def " when two feature set are empty the should be equals" () {
@@ -98,24 +100,31 @@ class AttributeSetTest extends Specification {
98100 assert attributeSet. matches(selector)
99101 }
100102
101- def " when multiple attributes are specified it should examine all" () {
102- given :
103- // Naming is important here as it controls the hashed order
104- Attribute a2 = new Attribute (" key2" , " value2" )
105- Attribute a3 = new Attribute (" key3" , " " , AttributeType . EXISTS )
106- when :
107- AttributeSet attributeSet = new AttributeSet (a2)
108- AttributeSet selectorWithOne = new AttributeSet (a2)
109- AttributeSet selectorWithTwo = new AttributeSet (a2, a3)
110- def orderedAttributes = new LinkedHashSet ([a2, a3]);
111- then :
112-
113- // Assert that the order is suitable for testing. The failing attribute should
114- // be in the *second* position to ensure we're examining all the values of the selector
115- assert new ArrayList<> (orderedAttributes). indexOf(a3) == 1 ;
103+ def " when multiple attributes are specified it should not match an attribute set with a single attribute" () {
104+ given : " multiple attributes"
105+ def a2 = new Attribute (" key2" , " value2" )
106+ def a3 = new Attribute (" key3" , " " , AttributeType . EXISTS )
107+ and : " an AttributeSet with only one attribute"
108+ def attributeSet = new AttributeSet (a2)
109+ and : " an AttributeSet with two attributes as selector"
110+ def selectorWithTwo = new AttributeSet (a2, a3)
111+ when : " matching"
112+ def matches = attributeSet. matches(selectorWithTwo)
113+ then : " it should not match"
114+ assert ! matches
115+ }
116116
117- assert attributeSet. matches(selectorWithOne)
118- assert ! attributeSet. matches(selectorWithTwo)
117+ def " when multiple attributes are specified it should examine all" () {
118+ given : " multiple attributes"
119+ def a2 = new Attribute (" key2" , " value2" )
120+ def a3 = new Attribute (" key3" , " " , AttributeType . EXISTS )
121+ and : " an AttributeSet with all attributes"
122+ def attributeSet = new AttributeSet (a2, a3)
123+ when : " listing its values"
124+ def attributes = attributeSet. attributes. values(). stream(). sorted(). collect(Collectors . toList())
125+ then : " it should contain all attributes"
126+ assert attributes. indexOf(a3) == 1
127+ assert attributes. size() == 2
119128 }
120129
121130 def " when IN attribute in selector" () {
0 commit comments