Skip to content
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

Fixes #2204: Ignore Groovy methods annotated with Internal #2207

Merged
merged 2 commits into from Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/dependencies.gradle
Expand Up @@ -35,6 +35,8 @@ libraries.osgi = 'org.osgi:osgi.core:8.0.0'
libraries.equinox = 'org.eclipse.platform:org.eclipse.osgi:3.16.100'
libraries.bndGradle = 'biz.aQute.bnd:biz.aQute.bnd.gradle:5.2.0'

libraries.groovy = 'org.codehaus.groovy:groovy:3.0.7'

def kotlinVersion = '1.4.30'
libraries.kotlin = [
version: kotlinVersion,
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Expand Up @@ -5,6 +5,7 @@ plugins {
include("deprecatedPluginsTest",
"inline",
"extTest",
"groovyTest",
"kotlinTest",
"kotlinReleaseCoroutinesTest",
"android",
Expand Down
Expand Up @@ -226,7 +226,8 @@ private <T> Collection<Class<? super T>> getAllTypes(Class<T> type) {
}

private static ElementMatcher<MethodDescription> isGroovyMethod() {
return isDeclaredBy(named("groovy.lang.GroovyObjectSupport"));
return isDeclaredBy(named("groovy.lang.GroovyObjectSupport"))
.or(isAnnotatedWith(named("groovy.transform.Internal")));
}

private boolean isComingFromJDK(Class<?> type) {
Expand Down
11 changes: 11 additions & 0 deletions subprojects/groovyTest/groovyTest.gradle
@@ -0,0 +1,11 @@
apply plugin: 'groovy'

description = "Integration test for using Mockito from Groovy."

apply from: "$rootDir/gradle/dependencies.gradle"

dependencies {
testCompile project(":")
testCompile libraries.groovy
testCompile libraries.junit4
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 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() { }
}
}