diff --git a/settings.gradle.kts b/settings.gradle.kts index f5a786dfdc..45a4679e4c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,6 +6,7 @@ include("inline", "proxy", "extTest", "groovyTest", + "groovyInlineTest", "kotlinTest", "kotlinReleaseCoroutinesTest", "android", diff --git a/src/main/java/org/mockito/internal/creation/bytebuddy/SubclassBytecodeGenerator.java b/src/main/java/org/mockito/internal/creation/bytebuddy/SubclassBytecodeGenerator.java index fe89070150..4107d1dabb 100644 --- a/src/main/java/org/mockito/internal/creation/bytebuddy/SubclassBytecodeGenerator.java +++ b/src/main/java/org/mockito/internal/creation/bytebuddy/SubclassBytecodeGenerator.java @@ -12,12 +12,9 @@ import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.hasParameters; import static net.bytebuddy.matcher.ElementMatchers.hasType; -import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; -import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy; import static net.bytebuddy.matcher.ElementMatchers.isEquals; import static net.bytebuddy.matcher.ElementMatchers.isHashCode; import static net.bytebuddy.matcher.ElementMatchers.isPackagePrivate; -import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.returns; import static net.bytebuddy.matcher.ElementMatchers.whereAny; import static org.mockito.internal.util.StringUtil.join; diff --git a/subprojects/groovyInlineTest/groovyInlineTest.gradle b/subprojects/groovyInlineTest/groovyInlineTest.gradle new file mode 100644 index 0000000000..1618ac6009 --- /dev/null +++ b/subprojects/groovyInlineTest/groovyInlineTest.gradle @@ -0,0 +1,11 @@ +apply plugin: 'groovy' + +description = "Integration test for using mockito-inline with Groovy." + +apply from: "$rootDir/gradle/dependencies.gradle" + +dependencies { + testImplementation project(":inline") + testImplementation libraries.groovy + testImplementation libraries.junit4 +} diff --git a/subprojects/groovyInlineTest/src/test/groovy/org/mockito/groovy/GroovyMockitoTest.groovy b/subprojects/groovyInlineTest/src/test/groovy/org/mockito/groovy/GroovyMockitoTest.groovy new file mode 100644 index 0000000000..c327d0e1bb --- /dev/null +++ b/subprojects/groovyInlineTest/src/test/groovy/org/mockito/groovy/GroovyMockitoTest.groovy @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Mockito contributors + * This program is made available under the terms of the MIT License. + */ +package org.mockito.groovy + +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.junit.MockitoJUnitRunner + +import static org.mockito.Mockito.verify + +@RunWith(MockitoJUnitRunner) +class GroovyMockitoTest { + + @Mock Helper helper + @InjectMocks ClassUnderTest classUnderTest + + /** + * Test that the Groovy class under test can call methods on a mocked Groovy + * helper class. + */ + @Test + void testCallGroovyFromGroovy() { + classUnderTest.methodUnderTest() + verify(helper).helperMethod() + } + + static class ClassUnderTest { + private final Helper helper + + ClassUnderTest(Helper helper) { + this.helper = helper + } + + void methodUnderTest() { + helper.helperMethod() + } + } + + static class Helper { + void helperMethod() { } + } +}