Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mockito-inline for Groovy projects (#2618)
Add ignore matcher for Groovy meta methods for inline Byte Buddy mock maker. Add a new test subproject to verify fixes between mockito-inline and Groovy Fixes #2522 Co-authored-by: Steve Green <steve@Steves-MacBook-Pro.local>
- Loading branch information
Showing
6 changed files
with
85 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
46 changes: 46 additions & 0 deletions
46
subprojects/groovyInlineTest/src/test/groovy/org/mockito/groovy/GroovyMockitoTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { } | ||
} | ||
} |