openrewrite / openrewrite/rewrite-testing-frameworks
Recipe to migrate from system-rules to system-stubs
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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