Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: base/test/android/javatests/src/org/chromium/base/test/util/CommandLineTestRule.java

Issue 2523983002: Create CommandLineTestRule (Closed)
Patch Set: implements SetUpTestRule Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.base.test.util;
6
7 import android.support.test.InstrumentationRegistry;
8
9 import org.junit.rules.TestRule;
10 import org.junit.runner.Description;
11 import org.junit.runners.model.Statement;
12
13 import org.chromium.base.test.SetUpTestRule;
14
15 import java.util.Arrays;
16 import java.util.HashSet;
17 import java.util.Set;
18
19 /**
20 * TestRule to used by JUnit4 style instrumentation test to set CommandLine flag s.
21 *
22 * If you need to add CommandLine flag to your junit4 style instrumentation test , add this
23 * TestRule with the flag string you need. Remember to call setUp() before you l aunch
24 * the activity.
25 *
26 * <pre><code>
27 * public class ChromeActivityTest {
28 * &#064;Rule CommandLineTestRule mCommandLineRule = new CommandLineTestRule ().setFlags(...);
29 * &#064;Rule ChromeActivityTestRule mActivityTestRule = new ChromeActivityT estRule();
30 *
31 * &#064;Before
32 * public void setUp() {
33 * mCommandLineRule.setUp();
34 * mActivityTestRule.launchActivity();
35 * }
36 *
37 * &#064;Test
38 * public void test() {...}
39 * </code></pre>
40 *
41 */
42 public final class CommandLineTestRule implements TestRule, SetUpTestRule<Comman dLineTestRule> {
43 private Set<String> mFlagSet;
44 private boolean mShouldSetUp = false;
45
46 public CommandLineTestRule setFlags(String firstFlag, String... flags) {
47 mFlagSet = new HashSet<>();
48 mFlagSet.add(firstFlag);
49 mFlagSet.addAll(Arrays.asList(flags));
50 return this;
51 }
52
53 @Override
54 public CommandLineTestRule shouldSetUp(boolean shouldSetUp) {
55 mShouldSetUp = shouldSetUp;
56 return this;
57 }
58
59 @Override
60 public void setUp() {
61 CommandLineFlags.setUp(InstrumentationRegistry.getTargetContext(), mFlag Set);
62 }
63
64 @Override
65 public Statement apply(final Statement base, Description desc) {
66 return new SetUpStatement(base, this, mShouldSetUp);
67 }
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698