Skip to content

Commit

Permalink
Update testing frameworks to use rewrite 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Mar 19, 2021
1 parent d81615a commit 8fb08ad
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 29 deletions.
6 changes: 6 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://projectlombok.org/features/configuration
config.stopBubbling = true
lombok.addNullAnnotations = CUSTOM:org.openrewrite.internal.lang.NonNull:org.openrewrite.internal.lang.Nullable
lombok.copyableAnnotations += org.openrewrite.internal.lang.Nullable
lombok.copyableAnnotations += org.openrewrite.internal.lang.NonNull
lombok.anyConstructor.addConstructorProperties=true
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,21 @@
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnit44Runner;
import org.mockito.runners.MockitoJUnitRunner;
import org.openrewrite.java.testing.statik.UnitTest;

import java.io.File;
import java.io.IOException;
import java.util.List;

import static org.mockito.Mockito.*;

@Category(UnitTest.class)
public class ExampleJunitTestClass {

// @Rule
// public Timeout globalTimeout = new Timeout(500);

@Rule
public TemporaryFolder folder = new TemporaryFolder();

Expand Down Expand Up @@ -115,10 +103,7 @@ public void bar() { }

@Test
public void aTest() {
List<Integer> foo = mock(List.class);

when(foo.get(any())).then(invocation -> invocation.getArgumentAt(0, Integer.class));
int one = foo.get(1);
Assert.assertEquals(1, one);
String foo = mock(String.class);
when(foo.concat(any())).then(invocation -> invocation.getArgumentAt(0, String.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class RunOnMavenProjectOnDisk {

val mavenParserBuilder = MavenParser.builder()
.cache(pomCache)
.resolveOptional(false)
.mavenConfig(projectDir.resolve(".mvn/maven.config"))

val parser = MavenProjectParser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openrewrite.java.testing.junit5;

import lombok.Value;
import org.openrewrite.Cursor;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ recipeList:
onlyIfUsing:
- org.junit.jupiter.api.Test
- org.openrewrite.java.testing.junit5.UseHamcrestAssertThat
- org.openrewrite.java.tesitng.junit5.UseMockitoExtension
- org.openrewrite.java.testing.junit5.UseMockitoExtension
- org.openrewrite.java.testing.junit5.UseTestMethodOrder
- org.openrewrite.java.testing.junit5.AssertToAssertions
- org.openrewrite.java.testing.junit5.CategoryToTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.openrewrite.*
import org.openrewrite.config.Environment
import org.openrewrite.java.JavaParser
import org.openrewrite.java.JavaRecipeTest
import org.openrewrite.maven.MavenParser

/**
* Validates the recipes related to upgrading from Mockito 1 to Mockito 3
*/
@Issue("https://github.com/openrewrite/rewrite/issues/343")
@Disabled
class JunitMockitoUpgradeIntegrationTest : JavaRecipeTest {
override val parser: JavaParser = JavaParser.fromJavaVersion()
.classpath("mockito-all", "junit", "hamcrest")
.build()
.logCompilationWarningsAndErrors(true)
.classpath("mockito-all", "junit", "hamcrest")
.build()

override val recipe: Recipe
get() = loadRecipeFromClasspath("org.openrewrite.java.testing.JUnit5Migration",
override val recipe: Recipe = Environment.builder()
.scanClasspath(emptyList())
.build()
.activateRecipes("org.openrewrite.java.testing.junit5.JUnit4to5Migration",
"org.openrewrite.java.testing.mockito.Mockito1to3Migration")

/**
Expand Down Expand Up @@ -342,10 +344,7 @@ class JunitMockitoUpgradeIntegrationTest : JavaRecipeTest {
val exampleJunitAfter = """
package org.openrewrite.java.testing.junit5;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
Expand Down

0 comments on commit 8fb08ad

Please sign in to comment.