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

Recipe to migrate from system-rules to system-stubs #197

Open
yeikel opened this issue Mar 28, 2022 · 1 comment
Open

Recipe to migrate from system-rules to system-stubs #197

yeikel opened this issue Mar 28, 2022 · 1 comment
Labels
recipe Recipe request

Comments

@yeikel
Copy link
Contributor

yeikel commented Mar 28, 2022

See : stefanbirkner/system-rules#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");
@pway99
Copy link
Contributor

pway99 commented Mar 28, 2022

thanks @yeikel, this is very helpful

@pway99 pway99 added the enhancement New feature or request label Mar 28, 2022
@pway99 pway99 moved this to Backlog in OpenRewrite Mar 28, 2022
@tkvangorder tkvangorder moved this from Backlog to Ice Box in OpenRewrite Apr 8, 2022
@tkvangorder tkvangorder moved this from Request for help to Future in OpenRewrite Apr 18, 2022
@tkvangorder tkvangorder added recipe Recipe request and removed help wanted enhancement New feature or request labels Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Status: Recipes Wanted
Development

No branches or pull requests

3 participants