Skip to content

Invalid rewrite of Assume.assumeNotNull to Assumptions.assumeNotNull #886

@cortlepp

Description

@cortlepp

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v8.70.4
  • Maven plugin v6.26.0
  • rewrite-testing-frameworks v3.24.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>6.26.0</version>
  <configuration>
  <activeRecipes>
	<activeRecipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</activeRecipe>
</activeRecipes>
  </configuration>
  <dependencies>
	<dependency>
		<groupId>org.openrewrite.recipe</groupId>
		<artifactId>rewrite-migrate-java</artifactId>
		<version>3.22.0</version>
	</dependency>
	<dependency>
		<groupId>org.openrewrite.recipe</groupId>
		<artifactId>rewrite-testing-frameworks</artifactId>
		<version>3.24.0</version>
	</dependency>
</dependencies>
</plugin>

What is the smallest, simplest way to reproduce the problem?

import org.junit.Assume;

class Test {
    void test() {
        Assume.assumeNotNull("Are you there?", new Object());
    }
}

What did you expect to see?

import org.junit.jupiter.api.Assumptions;

class Test {
    void test() {
        Assumptions.assumeTrue(new Object() != null, "Are you there?");
    }
}

Note: I'm not sure if this would be the best way to do it, I guess it's the easiest?!

What did you see instead?

import org.junit.jupiter.api.Assumptions;
  
class Test {
    void test() {
        Assumptions.assumeNotNull("Are you there?", new Object());
    }
}

The rewritten method does not exist in Junit-Jupiter: https://docs.junit.org/5.0.0/api/org/junit/jupiter/api/Assumptions.html

What is the full stack trace of any errors you encountered?

Are you interested in contributing a fix to OpenRewrite?

Yes. But I'm a bit unsure how to implement this in the existing src/main/resources/META-INF/rewrite/junit5.yml, or if this is too complex and needs a Java implementation. So I'd appreciate some advice there.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requestjunitrecipeRecipe request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions