AndroidJUnit4Builder.java revision 92486d33cdbabc6dd0f69db97d00864d3fc2da00
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.support.test.internal.runner.junit4;
17
18import android.app.Instrumentation;
19import android.os.Bundle;
20import android.support.test.InjectContext;
21import android.support.test.InjectInstrumentation;
22
23import org.junit.internal.builders.JUnit4Builder;
24import org.junit.runner.Runner;
25import org.junit.runners.model.RunnerBuilder;
26
27/**
28 * A {@link RunnerBuilder} that will build customized runners needed to handle {@link InjectContext}
29 * and {@link InjectInstrumentation}.
30 */
31public class AndroidJUnit4Builder extends JUnit4Builder {
32
33   private final Instrumentation mInstrumentation;
34   private final Bundle mBundle;
35   private boolean mSkipExecution;
36
37   public AndroidJUnit4Builder(Instrumentation instr, Bundle bundle, boolean skipExecution) {
38      mInstrumentation = instr;
39      mBundle = bundle;
40      mSkipExecution = skipExecution;
41   }
42
43   @Override
44   public Runner runnerForClass(Class<?> testClass) throws Throwable {
45      if (mSkipExecution) {
46         return new NonExecutingJUnit4ClassRunner(testClass);
47      }
48      return new AndroidJUnit4ClassRunner(testClass, mInstrumentation, mBundle);
49   }
50}
51