From 7c6e6da9a6dc5c08edb6dbbf551e44f9a47d5cb8 Mon Sep 17 00:00:00 2001 From: Jeff Scott Brown Date: Mon, 19 Dec 2016 20:40:29 -0600 Subject: [PATCH] Fix ClassCastException Related to grails/grails-core#10363. --- .../injection/test/TestForTransformation.java | 5 ++-- ...stForControllerWithNamePropertySpec.groovy | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 grails-test-suite-web/src/test/groovy/grails/test/mixin/TestForControllerWithNamePropertySpec.groovy 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 +}