Details
Description
GrailsMock was changed with GRAILS-7448 from getting the types of parameters on mocked methods from parameter.getClass() to parameter.class. This was done to fix cases where the instance of a parameter passed in was itself a GrailsMock and resulted in undemanded methods being called. However, this caused a regression with classes that implement getProperty() in their metaClass and override the behavior such that it.class != it.getClass().
I was attempting to make a change and a test and submit a pull request, but I cannot immediately determine how to go about this. The mocked class will look and act like the class being mocked (e.g. new GrailsMock(String).createMock() instanceof String == true) so I don't know how to vary the behavior to fix the regression and allow GrailsMock's to also be parameters to other demanded methods.
Any thoughts?
-
Hide
- grails-mock-bug-report-14022012.zip
- 14/Feb/12 7:43 AM
- 22 kB
- Michael Cameron
-
- grails-app/.../ApplicationResources.groovy 0.1 kB
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/BuildConfig.groovy 2 kB
- grails-app/conf/Config.groovy 4 kB
- grails-app/conf/DataSource.groovy 1 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/.../messages_cs_CZ.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 4 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_sv.properties 3 kB
- grails-app/i18n/messages_th.properties 6 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 0.3 kB
- grails-app/views/index.gsp 3 kB
- grails-app/views/layouts/main.gsp 2 kB
- src/groovy/grails/mock/Foo.groovy 0.6 kB
- test/unit/.../mock/GrailsMockTests.groovy 0.8 kB
- application.properties 0.1 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
I added a quick workaround (and the only one I could think of right now) to fix the regression while keeping the changes for
GRAILS-7448working.https://github.com/grails/grails-core/pull/164
As you can see in the pull request, I check to see if it.class is an instanceof a Class, and only if not, then call getClass() instead. This should work in the case where a GrailsMock is a parameter, and in the case where the parameter implements getProperty() in the metaClass and overrides ".class". The only edge case where this would still seem to fail, is if getProperty() returns a java.lang.Class, but it is not the class of the object, or getMethod() is overridden in the metaClass "getClass()" is intercepted and returns something other than the class.