Skip to content

Commit

Permalink
add Mockito1to4MigrationTest (#651)
Browse files Browse the repository at this point in the history
* add Mockito1to4MigrationTest

* Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Minor polish

* Update src/test/java/org/openrewrite/java/testing/mockito/Mockito1to4MigrationTest.java

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent 89516ea commit e6d9a80
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ recipeDependencies {
parserClasspath("org.mockito:mockito-all:1.10.19")
parserClasspath("org.mockito:mockito-core:3.+")
parserClasspath("org.mockito:mockito-core:5.+")
parserClasspath("org.mockito:mockito-junit-jupiter:5.+")
parserClasspath("org.jmockit:jmockit:1.49")
parserClasspath("org.jmockit:jmockit:1.22") // last version with NonStrictExpectations
parserClasspath("org.mockito:mockito-junit-jupiter:3.+")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://docs.moderne.io/licensing/moderne-source-available-license
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.testing.mockito;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
import static org.openrewrite.java.Assertions.java;

class Mockito1to4MigrationTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec
.beforeRecipe(withToolingApi())
.parser(JavaParser.fromJavaVersion()
.classpathFromResources(new InMemoryExecutionContext(), "junit-jupiter-api", "mockito-core", "mockito-junit-jupiter"))
.recipeFromResources("org.openrewrite.java.testing.mockito.Mockito1to4Migration");
}

@DocumentExample
@Test
void modifyMockitoDependencies() {
rewriteRun(
//language=groovy
buildGradle(
"""
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.commons:commons-lang3:3.17.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4")
testImplementation("org.mockito:mockito-core:3.12.4")
testImplementation("org.mockito:mockito-junit-jupiter:3.12.4")
}
test {
useJUnitPlatform()
}
""",
"""
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.commons:commons-lang3:3.17.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4")
testImplementation("org.mockito:mockito-core:4.11.0")
testImplementation("org.mockito:mockito-junit-jupiter:4.11.0")
}
test {
useJUnitPlatform()
}
"""
),
//language=java
java(
"""
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
@ExtendWith(MockitoExtension.class)
public class MyTest {
@Test
public void test() {
List<String> list = Mockito.mock(List.class);
}
}
"""
)
);
}
}

0 comments on commit e6d9a80

Please sign in to comment.