-
Notifications
You must be signed in to change notification settings - Fork 951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GroovyCastException when invoking TestFor generated getters in tests #10363
Comments
The .zip file linked above is not runnable in its current state. Would you test the project at https://github.com/jeffbrown/issue10363 and let me know if the problem occurs for you there? I can't reproduce the problem. Thanks for the feedback. |
Sorry about that .zip file. Yeah it still happens on that project. Are the tests failing for you? Maybe it's a bit counter-intuitive, but they should pass if the exception is thrown: void "class under test getter throws exception"() {
when:
getDomain()
then:
thrown(ClassCastException) // test should pass if the bug is present
} |
Ok. I was looking for failing tests. I see now. Thanks for the feedback. |
See osscontributor/issue10363@d71e024. That makes more sense to me as the tests now describe how the system is supposed to behave. |
These tests fail when using @testfor. See grails/grails-core#10363.
Related to grails/grails-core#10363.
Task List
Steps to Reproduce
name
, or agetName()
method.@TestFor
annotation.getDomain()
,getController()
,getService()
).Expected Behaviour
For artefacts that don't have a
name
property there are no problems and an instance of the artefact is returned by the getter. I would expect the same to hold true if there is aname
property.Actual Behaviour
Instead, the getter throws a
GroovyCastException
. For a domain class,Bar
:From what I can tell, the exception is thrown in the getter method in the process of checking if the bean exists in the application context. I've tried decompiling the compiled test and for an artefact without a
name
property, the AST generated code looks something like this:For an artefact with the
name
property, the AST generated code looks like this:This seems to be the cast that is throwing the exception. The relevant source code seems to be in TestForTransformation, but I'm honestly not sure if this is actually more of an issue with the Groovy AST transform api itself.
Environment Information
Example Application
This bug report has three test classes (one for each kind of artefact). The tests pass if an exception is thrown when invoking the getter.
foo-bug-report-17122016.zip
The text was updated successfully, but these errors were encountered: