Skip to content

Commit

Permalink
[#1503] use @rule chain to ensure rule ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Dec 6, 2021
1 parent 55417c9 commit a273583
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/test/java/picocli/AutoCompleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
Expand Down Expand Up @@ -68,10 +69,16 @@
// https://apple.stackexchange.com/a/13019
public class AutoCompleteTest {

@Rule
//@Rule
// https://github.com/remkop/picocli/issues/1503
public final ProvideSystemProperty allowSecurityManager = new ProvideSystemProperty("java.security.manager", "allow");

//@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

@Rule
public RuleChain chain = RuleChain.outerRule(allowSecurityManager).around(exit);

@Rule
public final ProvideSystemProperty ansiOFF = new ProvideSystemProperty("picocli.ansi", "false");
// allows tests to set any kind of properties they like, without having to individually roll them back
Expand All @@ -84,9 +91,6 @@ public class AutoCompleteTest {
@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog().muteForSuccessfulTests();

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

public static class BasicExample implements Runnable {
@Option(names = {"-u", "--timeUnit"}) private TimeUnit timeUnit;
@Option(names = {"-t", "--timeout"}) private long timeout;
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/picocli/ExecuteLegacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.*;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import picocli.CommandLine.Model.CommandSpec;

Expand All @@ -36,10 +37,16 @@

@SuppressWarnings("deprecation")
public class ExecuteLegacyTest {
@Rule
//@Rule
// https://github.com/remkop/picocli/issues/1503
public final ProvideSystemProperty allowSecurityManager = new ProvideSystemProperty("java.security.manager", "allow");

//@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

@Rule
public RuleChain chain = RuleChain.outerRule(allowSecurityManager).around(exit);

// allows tests to set any kind of properties they like, without having to individually roll them back
@Rule
public final TestRule restoreSystemProperties = new RestoreSystemProperties();
Expand All @@ -53,8 +60,6 @@ public class ExecuteLegacyTest {
@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog().muteForSuccessfulTests();

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

interface Factory { Object create(); }
@Test
Expand Down

0 comments on commit a273583

Please sign in to comment.