1 // Copyright 2023 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.ResettersForTesting; 12 13 /** 14 * Include this rule when using ParameterizedRobolectricTest. 15 * Resetters registered during @BeforeClass will be reset after each method. 16 */ 17 class ResettersForTestingTestRule implements TestRule { 18 @Override apply(Statement base, Description description)19 public Statement apply(Statement base, Description description) { 20 return new Statement() { 21 @Override 22 public void evaluate() throws Throwable { 23 try { 24 base.evaluate(); 25 } finally { 26 // We cannot guarantee that this Rule will be evaluated first, so never 27 // call setMethodMode(), and reset class resetters after each method. 28 ResettersForTesting.onAfterClass(); 29 } 30 } 31 }; 32 } 33 } 34