Skip to content

Commit 5622e7b

Browse files
committed
#919 Explicit setup for Mockito inline mocking
1 parent f95bcc0 commit 5622e7b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ java {
8585
}
8686
}
8787

88+
configurations {
89+
if (project.testJava > 8) {
90+
mockitoAgent
91+
}
92+
}
93+
8894
ext {
8995
// Do not upgrade to JUnit 6 as it requires Java 17
9096
junit_jupiter = '5.14.3'
@@ -114,6 +120,10 @@ dependencies {
114120
testImplementation "org.mockito:mockito-core:$mockito"
115121
if (project.testJava == 8) {
116122
testImplementation "org.mockito:mockito-inline:$mockito"
123+
} else {
124+
mockitoAgent("org.mockito:mockito-core:$mockito") {
125+
transitive = false
126+
}
117127
}
118128
testImplementation "org.mockito:mockito-junit-jupiter:$mockito"
119129
}
@@ -249,6 +259,13 @@ test {
249259
println "Running tests for type ${project.'test.gds_type'}"
250260
// Use junit platform for unit tests
251261
useJUnitPlatform()
262+
if (project.testJava > 8) {
263+
jvmArgumentProviders.add(
264+
objects.newInstance(JavaAgentProvider).tap {
265+
agent = configurations.mockitoAgent.asPath
266+
}
267+
)
268+
}
252269

253270
// Test configuration, defaults specified in gradle.properties (modify through ext, or use -P<prop>=<value>)
254271
systemProperties(

buildSrc/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-FileCopyrightText: Copyright 2026 Mark Rotteveel
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
plugins {
4+
id 'groovy-gradle-plugin'
5+
}
6+
7+
repositories {
8+
gradlePluginPortal()
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-FileCopyrightText: Copyright 2026 Mark Rotteveel
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
import org.gradle.api.provider.Property
4+
import org.gradle.api.tasks.InputFile
5+
import org.gradle.api.tasks.PathSensitive
6+
import org.gradle.api.tasks.PathSensitivity
7+
import org.gradle.process.CommandLineArgumentProvider
8+
9+
/**
10+
* Provider for {@code -javaagent:some.jar} command line arguments.
11+
*/
12+
abstract class JavaAgentProvider implements CommandLineArgumentProvider {
13+
14+
@InputFile
15+
@PathSensitive(PathSensitivity.RELATIVE)
16+
abstract Property<String> getAgent()
17+
18+
@Override
19+
Iterable<String> asArguments() {
20+
["-javaagent:${agent.get()}"]
21+
}
22+
23+
}

0 commit comments

Comments
 (0)