Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Bug
-
2.5.4
-
None
-
None
-
gradle plugin project, built with gradle 5.6.2, test source using spock-1.3 with
groovy-2.5.4
Description
It seems to me that @Delegate annotation is broken with regard to it's exclude property:
Consider the following spock test:
class WMap { String name; @Delegate( excludes = "name,a" ) Map<String,String> data; WMap(String name, Map<String, String> data) { this.name = name this.data = data } } def 'Test WMap properties'() { given: def map = new WMap('example',['a':'valA',b:'valB','name':'wierd']) expect: map.name == 'example' // fail it's "wierd" map.a == 'valA' // but what about exclude = a ? }
In the above example we see a class that is composed with map object. Despite having
regurral name property, lookups for this property end up in the target map. It is stated in documentation that only functions existing on delegate target java type are delegated ( not any GroovyObject functions ) but it seems that the dynamic property for each key functionallity works on the WMap where it should not.
The fact that it works is no big deal, but only if the exclude works - but as we can see the
exclude is ignored and more over properties are covered which should be avoided