openrewrite / openrewrite/rewrite-testing-frameworks

Recipe to migrate from system-rules to system-stubs

Open
#197 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
100
Forks
105
Avg merge
2h 25m
Merged PRs (30d)
9

Description

See : https://github.com/stefanbirkner/system-rules/issues/55

Sample changes :

Remove

import org.junit.Rule;
import org.junit.contrib.java.lang.system.EnvironmentVariables;

 @Rule
    public final EnvironmentVariables envVars = new EnvironmentVariables();

Remove the dependency :

<dependency>
    <groupId>com.github.stefanbirkner</groupId>
    <artifactId>system-rules</artifactId>
    <scope>test</scope>
</dependency>

It should add the dependency :

<dependency>
            <groupId>uk.org.webcompere</groupId>
            <artifactId>system-stubs-jupiter</artifactId>
            <scope>test</scope>
        </dependency>

It should also add the SystemStubsExtension at the class level

import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;


@ExtendWith(SystemStubsExtension.class)
public class testClass {

...
}

And add the environment as a parameter in the test

For example :

 @Test
    public void testBefore() {
            envVars.set("var", "100");
    }

  @Test
    public void testAfter(EnvironmentVariables envVars) {
            envVars.set("var", "100");
    }

Sample diff :

import io.vertx.core.json.JsonObject;
 import io.vertx.junit5.VertxExtension;
 import io.vertx.junit5.VertxTestContext;
-import org.junit.Rule;
-import org.junit.contrib.java.lang.system.EnvironmentVariables;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
+import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
 
 import java.io.IOException;
 
 
 @ExtendWith(VertxExtension.class)
+@ExtendWith(SystemStubsExtension.class)
 public class AccountSegmentFunctionVerticleTest {
 
-    @Rule
-    public final EnvironmentVariables envVars = new EnvironmentVariables();
     private final Vertx vertx;
@@ -50,14 +47,14 @@ public class TestClass {
     }
 
     @Test
-    public void test(VertxTestContext testContext) {
+    public void test(VertxTestContext testContext,final EnvironmentVariables envVars) {
         envVars.set("var", "100");

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the linked system-rules issue and the sample diff as the migration specification. Locate the existing recipe and its tests for system-rules usage, then verify the dependency, imports, class extension, and test-parameter changes shown here. Done means affected tests migrate to system-stubs-jupiter without the system-rules dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.