@@ -23,28 +23,28 @@ import spock.lang.*
2323 */
2424@Stepwise
2525class ConfineMetaClassChangesSpec extends EmbeddedSpecification {
26-
26+
2727 def setupSpec () {
2828 newValue = 1
2929 }
30-
30+
3131 def " change the metaclass" () {
3232 expect : value == 1
3333 when : newValue = 2
3434 then : value == 2
3535 }
36-
36+
3737 def " value is still changed value" () {
3838 expect : value == 2
3939 }
40-
40+
4141 @ConfineMetaClassChanges (String )
4242 def " change it again, but with restore annotation" () {
4343 expect : value == 2
4444 when : newValue = 3
4545 then : value == 3
4646 }
47-
47+
4848 def " changes have been reverted" () {
4949 expect : value == 2
5050 }
@@ -56,7 +56,7 @@ class ConfineMetaClassChangesSpec extends EmbeddedSpecification {
5656
5757 @ConfineMetaClassChanges ([String , Integer ])
5858 def " change more than one type" () {
59- expect :
59+ expect :
6060 value == 2
6161
6262 when :
@@ -67,7 +67,7 @@ class ConfineMetaClassChangesSpec extends EmbeddedSpecification {
6767 getValue(" " ) == 3
6868 getValue(1 ) == 3
6969 }
70-
70+
7171 def " changes are reverted on both" () {
7272 expect :
7373 getValue(" " ) == 2
@@ -78,7 +78,33 @@ class ConfineMetaClassChangesSpec extends EmbeddedSpecification {
7878 then :
7979 thrown(MissingMethodException )
8080 }
81-
81+
82+ @ConfineMetaClassChanges (String )
83+ @ConfineMetaClassChanges (Integer )
84+ def " change more than one type with multiple annotations" () {
85+ expect :
86+ value == 2
87+
88+ when :
89+ setNewValue(3 , String )
90+ setNewValue(3 , Integer )
91+
92+ then :
93+ getValue(" " ) == 3
94+ getValue(1 ) == 3
95+ }
96+
97+ def " changes are still reverted on both" () {
98+ expect :
99+ getValue(" " ) == 2
100+
101+ when :
102+ getValue(1 )
103+
104+ then :
105+ thrown(MissingMethodException )
106+ }
107+
82108 def " exercise a spec level restore" () {
83109 setup :
84110 newValue = 2
@@ -112,7 +138,7 @@ class ConfineMetaClassChangesSpec extends EmbeddedSpecification {
112138 " " | 3
113139 " @ConfineMetaClassChanges(String)" | 2
114140 }
115-
141+
116142 @ConfineMetaClassChanges (String )
117143 def " meta classes are restored after each iteration" () {
118144 expect :
@@ -126,27 +152,27 @@ class ConfineMetaClassChangesSpec extends EmbeddedSpecification {
126152 where :
127153 i << [2 ,2 ]
128154 }
129-
155+
130156 def " meta class was restored after parameterised" () {
131157 expect :
132158 value == 2
133159 }
134-
160+
135161 @ConfineMetaClassChanges ([])
136162 def " annotation with empty list/array value doesn't cause an error" (){
137163 expect : true
138164 }
139-
165+
140166 def cleanupSpec () {
141167 [String , Integer ]. each {
142168 GroovySystem . metaClassRegistry. removeMetaClass(it)
143169 }
144170 }
145-
171+
146172 static setNewValue (value , type = String ) {
147173 type. metaClass. getIsolateMetaClassExtensionValue = { -> value }
148174 }
149-
175+
150176 static getValue (seed = " " ) {
151177 seed. getIsolateMetaClassExtensionValue()
152178 }
0 commit comments