Description
I sometimes use maps as mock objects for test cases. One test case started failing with groovy 3.0.11 and 4.0.2 where a map was being used as a mock for an abstract class. Here is a simplified version of what is now failing. Note that it does not fail if A is not abstract:
abstract class A { String b } def a = [getB: { 'string b' }] as A assert 'string b' == a.b
I also noticed that I don't get an UnsupportedOperationException when calling functions that were not implemented in the map as described in https://groovy-lang.org/semantics.html#_map_to_type_coercion. MissingPropertyException seems to be working, though I can't seem to find a way to get MissingMethodException.
abstract class A { String b String c } def a = [getB: { 'string b' }, getD: { 'string d' }] as A assert null != a.c // Should get UnsupportedOperationException (doesn't work) assert null != a.d // Should get MissingPropertyException (works) assert null != a.getD() // Should get MissingMethodException (doesn't work)
Possibly related to GROOVY-8243?
Attachments
Issue Links
- is caused by
-
GROOVY-8244 SAM trait coercion with default parameters
- Closed
- is related to
-
GROOVY-7330 Incorrect dynamic proxy creation from map when there are default methods
- Closed
-
GROOVY-7412 Map-to-interface cast: map method definition does not override the default method
- Closed