diff --git a/grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/TestForTransformation.java b/grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/TestForTransformation.java index a275a435def..7309fce7434 100644 --- a/grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/TestForTransformation.java +++ b/grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/TestForTransformation.java @@ -459,8 +459,9 @@ private IfStatement getAutowiringIfStatement(ClassExpression targetClass, Variab arguments.addExpression(new ConstantExpression(false)); BlockStatement assignFromApplicationContext = new BlockStatement(); ArgumentListExpression argWithClassName = new ArgumentListExpression(); - MethodCallExpression getClassNameMethodCall = new MethodCallExpression(targetClass, "getName", new ArgumentListExpression()); - argWithClassName.addExpression(getClassNameMethodCall); + + final PropertyExpression classNamePropertyExpression = new PropertyExpression(targetClass, new ConstantExpression("name")); + argWithClassName.addExpression(classNamePropertyExpression); assignFromApplicationContext.addStatement(new ExpressionStatement(new BinaryExpression(fieldExpression, ASSIGN, new MethodCallExpression(appCtxVar, "getBean", argWithClassName)))); BlockStatement elseBlock = new BlockStatement(); diff --git a/grails-test-suite-web/src/test/groovy/grails/test/mixin/TestForControllerWithNamePropertySpec.groovy b/grails-test-suite-web/src/test/groovy/grails/test/mixin/TestForControllerWithNamePropertySpec.groovy new file mode 100644 index 00000000000..dc43fbf3369 --- /dev/null +++ b/grails-test-suite-web/src/test/groovy/grails/test/mixin/TestForControllerWithNamePropertySpec.groovy @@ -0,0 +1,23 @@ +package grails.test.mixin + +import grails.artefact.Artefact +import spock.lang.Issue +import spock.lang.Specification + +@TestFor(SomeController) +class TestForControllerWithNamePropertySpec extends Specification { + + @Issue('grails/grails-core#10363') + void "test referencing a controller with a 'name' property"() { + when: + controller + + then: + notThrown ClassCastException + } +} + +@Artefact('Controller') +class SomeController { + String name +}