Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.openrewrite.java.testing.junit5.JUnit4to5Migration fails to migrate public TemporaryFolder folder = new TemporaryFolder(); #1

Closed
nagkumar opened this issue Oct 5, 2023 · 7 comments
Assignees

Comments

@nagkumar
Copy link

nagkumar commented Oct 5, 2023


rewrite {
    activeRecipe(
	//"org.openrewrite.java.RemoveUnusedImports",
	//            "dev.simonverhoeven.sampleRecipe",
	"org.openrewrite.java.testing.junit5.JUnit4to5Migration",
image
demo\src\test\java\dev\simonverhoeven\openrewritedemo\JUnitTest.java:25: error: no suitable constructor found for File(no arguments)
    public File folder = new File();
                         ^
    constructor File.File(String,int) is not applicable
      (actual and formal argument lists differ in length)
    constructor File.File(String,File) is not applicable
      (actual and formal argument lists differ in length)
    constructor File.File(String) is not applicable
      (actual and formal argument lists differ in length)
    constructor File.File(String,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor File.File(File,String) is not applicable
      (actual and formal argument lists differ in length)
    constructor File.File(URI) is not applicable
      (actual and formal argument lists differ in length)
@nagkumar
Copy link
Author

nagkumar commented Oct 5, 2023

converts into


@Tag("DemoTag")
public class JUnitTest
{
    public File folder = new File();

    @BeforeEach
    public void beforeEachTest()
    {
    }

    @AfterEach
    public void afterEachTest()
    {
    }

    @Disabled
    public void importantTest()
    {
	// validate

@nagkumar
Copy link
Author

nagkumar commented Oct 5, 2023

https://docs.openrewrite.org/recipes/java/testing/junit5/temporaryfoldertotempdir?q=TemporaryFolder

it is supposed to use this receipe but not working

@SimonVerhoeven
Copy link
Owner

Hello, did you add any other recipes & did you enable rewrite-testing-frameworks?
I verified it just now, and when I execute it I get:

@TempDir
public File folder;

Which is the expected migration from TemporaryFolder

@SimonVerhoeven SimonVerhoeven self-assigned this Oct 6, 2023
@nagkumar
Copy link
Author

nagkumar commented Oct 6, 2023

Nope.. even with latest rewrite version.. it gives

image

I am using JDK 17.0.8 would that be an issue

My build file

plugins {
    `java-library`
    id("org.openrewrite.rewrite") version "6.3.16"
    id("com.github.ben-manes.versions") version ("0.48.0")
    id("se.patrikerdes.use-latest-versions") version ("0.2.18")
}

repositories {
    mavenCentral()
}
rewrite {
    activeRecipe(
	//"org.openrewrite.java.AddApache2LicenseHeader",
	//"org.openrewrite.java.logging.log4j.Log4j1ToLog4j2",
	//"org.openrewrite.staticanalysis.RemoveSystemOutPrintln",
	//"org.openrewrite.java.logging.SystemOutToLogging",
	//"org.openrewrite.java.migrate.UpgradeToJava17",
	"org.openrewrite.java.testing.junit5.JUnit4to5Migration",
	//"org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1",

	//"org.openrewrite.gradle.DependencyUseStringNotation",
	//"org.openrewrite.java.RemoveUnusedImports",
	//"com.teja.rac.AutoChangePackage",
	//"org.openrewrite.java.migrate.guava.NoGuava",
	//"org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ",
	//"org.openrewrite.staticanalysis.CommonStaticAnalysis",
	//"org.openrewrite.java.logging.slf4j.ParameterizedLogging",
	//"org.openrewrite.java.security.JavaSecurityBestPractices",
	//"org.openrewrite.cloudsuitability.FindFileIo",
	//"org.openrewrite.cloudsuitability.FindCacheUses",
	//"org.openrewrite.cloudsuitability.FindUnsuitableCode",
	//"org.openrewrite.java.security.OwaspTopTen",
		)
}

dependencies {
    rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.2.0"))
    rewrite("org.openrewrite.recipe:rewrite-testing-frameworks")
    //rewrite("org.openrewrite.recipe:rewrite-spring")
    //rewrite("org.openrewrite.recipe:rewrite-migrate-java")
    //rewrite("org.openrewrite.recipe:rewrite-static-analysis")
    //rewrite("org.openrewrite.recipe:rewrite-java-dependencies")
    //rewrite("org.openrewrite.recipe:rewrite-logging-frameworks")
    //rewrite("org.openrewrite.recipe:rewrite-java-security")
    //rewrite("org.openrewrite.recipe:rewrite-cloud-suitability-analyzer")

    api("org.springframework.boot:spring-boot-starter:2.7.13")
    api("org.springframework.boot:spring-boot-starter-web:2.7.13")
    api("log4j:log4j:1.2.17")
    api("com.google.guava:guava:20.0")
    testImplementation("org.hamcrest:hamcrest:2.2")
    testImplementation("junit:junit:4.13.2")

    //testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
    //testImplementation("org.assertj:assertj-core:3.24.2")
}


@nagkumar
Copy link
Author

nagkumar commented Oct 6, 2023


Gradle 8.3

Build time: 2023-08-17 07:06:47 UTC
Revision: 8afbf24b469158b714b36e84c6f4d4976c86fcd5

Kotlin: 1.9.0
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.8 (Oracle Corporation 17.0.8+9-LTS-211)
OS: Windows 10 10.0 amd64

@nagkumar
Copy link
Author

nagkumar commented Oct 6, 2023

Also, this rewrite is not changing gradle dependencies from 4.x to 5.x, is that the expected behavior

@SimonVerhoeven
Copy link
Owner

hmm, I can't reproduce your issue using the sample repository => ./gradlew rewriteRun when I just enable the JUnit recipe. It's also odd that it's doing a fully different replacement. I'd recommend creating a ticket at https://github.com/openrewrite/rewrite-testing-frameworks and sharing the results of the rewriteRun task.

As to your second question, that's an in-progress enhancement for Kotlin: openrewrite/rewrite#3291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants