Skip to content

Commit 6c64326

Browse files
committed
Don't apply DomainClassUnitTestMixin if the test extends HibernateSpec. Fixes #10242
1 parent a06e1e2 commit 6c64326

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/TestForTransformation.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,26 +263,30 @@ protected MethodNode weaveMock(ClassNode classNode, ClassExpression value, boole
263263
}
264264

265265
// must be a domain class
266-
Class<?> domainClassPresent = null;
267-
try {
268-
domainClassPresent = Class.forName("org.grails.plugins.domain.DomainClassGrailsPlugin", true, TestForTransformation.class.getClassLoader());
269-
} catch (ClassNotFoundException e) {
270-
// not on classpath ignore
271-
} catch (NoClassDefFoundError e) {
272-
// ignore
273-
}
266+
boolean isDataTest = GrailsASTUtils.isSubclassOf(classNode, "grails.test.hibernate.HibernateSpec") || GrailsASTUtils.isSubclassOf(classNode, "grails.test.mongodb.MongoSpec");
267+
if(!isDataTest) {
268+
269+
Class<?> domainClassPresent = null;
270+
try {
271+
domainClassPresent = Class.forName("org.grails.plugins.domain.DomainClassGrailsPlugin", true, TestForTransformation.class.getClassLoader());
272+
} catch (ClassNotFoundException e) {
273+
// not on classpath ignore
274+
} catch (NoClassDefFoundError e) {
275+
// ignore
276+
}
274277

275-
if(domainClassPresent != null) {
278+
if(domainClassPresent != null) {
276279

277-
weaveMixinClass(classNode, DomainClassUnitTestMixin.class);
278-
if (isClassUnderTest) {
279-
testForMethod = addClassUnderTestMethod(classNode, value, DOMAIN_TYPE);
280-
}
281-
else {
282-
addMockCollaboratorToSetup(classNode, value, DOMAIN_TYPE);
283-
}
280+
weaveMixinClass(classNode, DomainClassUnitTestMixin.class);
281+
if (isClassUnderTest) {
282+
testForMethod = addClassUnderTestMethod(classNode, value, DOMAIN_TYPE);
283+
}
284+
else {
285+
addMockCollaboratorToSetup(classNode, value, DOMAIN_TYPE);
286+
}
284287

285-
return testForMethod;
288+
return testForMethod;
289+
}
286290
}
287291
return null;
288292
}

0 commit comments

Comments
 (0)