• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors
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.runner.Description;
9 import org.junit.runners.model.Statement;
10 
11 import org.chromium.base.test.util.InMemorySharedPreferencesContext;
12 
13 /** Holds setUp / tearDown logic common to all instrumentation tests. */
14 class BaseJUnit4TestRule implements TestRule {
15     @Override
apply(Statement base, Description description)16     public Statement apply(Statement base, Description description) {
17         return new Statement() {
18             @Override
19             public void evaluate() throws Throwable {
20                 InMemorySharedPreferencesContext context =
21                         BaseChromiumAndroidJUnitRunner.sInMemorySharedPreferencesContext;
22                 if (context == null) {
23                     throw new IllegalStateException(
24                             "BaseJUnit4TestRule requires that you use "
25                                     + "BaseChromiumAndroidJUnitRunner (or a subclass)");
26                 }
27                 base.evaluate();
28             }
29         };
30     }
31 }
32