Skip to content

Commit

Permalink
Configure build and tests for multiple mockito versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
pway99 committed Oct 8, 2021
1 parent 1f3d2bf commit 49c32a4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
53 changes: 48 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ group = "org.openrewrite.recipe"
description =
"A rewrite module automating best practices and major version migrations for popular Java test frameworks like JUnit and Mockito"

val mockitoVersions: List<String> = listOf("3")

sourceSets {
mockitoVersions.forEach { version ->
create("testWithMockito_${version}") {
compileClasspath += sourceSets.getByName("main").output
runtimeClasspath += sourceSets.getByName("main").output
}
}
}

repositories {
if(!project.hasProperty("releasing")) {
mavenLocal()
Expand All @@ -71,10 +82,22 @@ signing {
sign(publishing.publications["nebula"])
}

configurations.all {
resolutionStrategy {
cacheChangingModulesFor(0, TimeUnit.SECONDS)
cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
configurations {
mockitoVersions.forEach { version ->
getByName("testWithMockito_${version}RuntimeOnly") {
isCanBeResolved = true
extendsFrom(getByName("testImplementation"))
}
getByName("testWithMockito_${version}Implementation") {
isCanBeResolved = true
extendsFrom(getByName("testImplementation"))
}
}
all {
resolutionStrategy {
cacheChangingModulesFor(0, TimeUnit.SECONDS)
cacheDynamicVersionsFor(0, TimeUnit.SECONDS)
}
}
}

Expand Down Expand Up @@ -113,10 +136,13 @@ dependencies {
testRuntimeOnly("org.springframework:spring-test:4.+")
testRuntimeOnly("ch.qos.logback:logback-classic:1.0.13")
testRuntimeOnly("org.mockito:mockito-all:$mockito1Version")
testRuntimeOnly("org.mockito:mockito-core:3.+")
testRuntimeOnly("org.hamcrest:hamcrest:latest.release")
testRuntimeOnly("pl.pragmatists:JUnitParams:1.+")
testRuntimeOnly("com.squareup.okhttp3:mockwebserver:3.+")

"testWithMockito_3RuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:latest.release")
"testWithMockito_3RuntimeOnly"("junit:junit:latest.release")
"testWithMockito_3RuntimeOnly"("org.mockito:mockito-core:3.+")
}

tasks.withType(KotlinCompile::class.java).configureEach {
Expand All @@ -130,6 +156,23 @@ tasks.named<Test>("test") {
jvmArgs = listOf("-Xmx1g", "-XX:+UnlockDiagnosticVMOptions", "-XX:+ShowHiddenFrames")
}

mockitoVersions.forEach { version ->
val sourceSetName = "testWithMockito_${version}"
val sourceSetReference = project.sourceSets.getByName(sourceSetName)
val testTask = tasks.register<Test>(sourceSetName) {
description = "Runs the unit tests for ${sourceSetName}."
group = "verification"
useJUnitPlatform()
jvmArgs = listOf("-XX:+UnlockDiagnosticVMOptions", "-XX:+ShowHiddenFrames")
testClassesDirs = sourceSetReference.output.classesDirs
classpath = sourceSetReference.runtimeClasspath
shouldRunAfter(tasks.test)
}
tasks.test {
dependsOn(testTask)
}
}

tasks.named<JavaCompile>("compileJava") {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ recipeList:
- org.openrewrite.java.testing.junit5.UpdateTestAnnotation
- org.openrewrite.java.testing.junit5.ParameterizedRunnerToParameterized
- org.openrewrite.java.testing.junit5.JUnitParamsRunnerToParameterized
- org.openrewrite.java.testing.junit5.MockitoJUnitToMockitoExtension
- org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows
- org.openrewrite.java.testing.junit5.UpdateMockWebServer
- org.openrewrite.java.testing.hamcrest.AddHamcrestIfUsed
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/rewrite/mockito.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ recipeList:
artifactId: mockito-junit-jupiter
version: 3.x
onlyIfUsing: org.mockito.junit.jupiter.MockitoExtension
- org.openrewrite.java.testing.junit5.MockitoJUnitToMockitoExtension

0 comments on commit 49c32a4

Please sign in to comment.