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.BundleUtils; 12 13 /** Ensures that BundleUtils#isBundle returns true for the duration of the test. */ 14 public class BundleTestRule 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 boolean oldValue = BundleUtils.isBundle(); 21 try { 22 BundleUtils.setIsBundle(true); 23 base.evaluate(); 24 } finally { 25 BundleUtils.setIsBundle(oldValue); 26 } 27 } 28 }; 29 } 30 } 31