File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
core/src/testFixtures/java/io/grpc/internal Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -164,4 +164,25 @@ public void log(ChannelLogLevel level, String message) {}
164164 @ Override
165165 public void log (ChannelLogLevel level , String messageFormat , Object ... args ) {}
166166 }
167+
168+ /**
169+ * Configures {@link GrpcUtil#getFlag(String, boolean)} to return 'value' for 'flag' for the
170+ * lifetime of the returned {@link AutoCloseable}.
171+ *
172+ * <p>Use the returned {@link AutoCloseable} in a try-with-resources statement to set a flag just
173+ * for its scope and unconditionally restore the flag's previous value upon scope exit.
174+ *
175+ * <p>Use this method in a @Before junit method to set a flag for the scope of a whole test.
176+ * You must save the returned {@link AutoCloseable} and close it in an @After method.
177+ */
178+ public static AutoCloseable setFlagForScope (String flag , boolean value ) {
179+ String oldValue = System .setProperty (flag , Boolean .toString (value ));
180+ return () -> {
181+ if (oldValue != null ) {
182+ System .setProperty (flag , oldValue );
183+ } else {
184+ System .clearProperty (flag );
185+ }
186+ };
187+ }
167188}
You can’t perform that action at this time.
0 commit comments