OLD | NEW |
---|---|
(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; | |
6 | |
7 import org.junit.rules.TestRule; | |
8 import org.junit.runners.model.Statement; | |
9 | |
10 /** | |
11 * Interface to ensure TestRule that implements it specifies if it would run a s et-up process | |
12 * before @Before. | |
13 * | |
14 * @param <T> TestRule type that implements this SetUpTestRule | |
15 */ | |
16 public interface SetUpTestRule<T extends TestRule> { | |
17 /** | |
18 * Set whether the TestRule should run setUp automatically and return the Te stRule. | |
mikecase (-- gone --)
2017/03/27 18:40:59
This could probably use clearer wording. Maybe...
the real yoland
2017/03/27 20:52:36
Done
| |
19 * | |
20 * So TestRule can be declared in test like this: | |
21 * <code> | |
22 * @Rule TestRule mRule = new MySetUpTestRule().shouldSetUp(true); | |
23 * </code> | |
24 */ | |
25 T shouldSetUp(boolean runSetUp); | |
26 | |
27 /** | |
28 * Specify setUp action in this method | |
29 */ | |
30 void setUp(); | |
31 | |
32 /** | |
33 * Custom Statment for SetUpTestRules. | |
34 * | |
35 * The statment calls {@link SetUpTestRule#setUp} before test run based on | |
36 * {@link SetUpTestRule#shouldSetUp} argument | |
37 */ | |
38 public static class SetUpStatement extends Statement { | |
39 private final Statement mBase; | |
40 private final SetUpTestRule<? extends TestRule> mSetUpTestRule; | |
41 private final boolean mShouldSetUp; | |
42 | |
43 public SetUpStatement(final Statement base, SetUpTestRule<? extends Test Rule> callback, | |
44 boolean shouldSetUp) { | |
45 mBase = base; | |
46 mSetUpTestRule = callback; | |
47 mShouldSetUp = shouldSetUp; | |
48 } | |
49 | |
50 @Override | |
51 public void evaluate() throws Throwable { | |
52 if (mShouldSetUp) { | |
53 mSetUpTestRule.setUp(); | |
54 } | |
55 mBase.evaluate(); | |
56 } | |
57 } | |
58 } | |
OLD | NEW |