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 com.android.test.runner.junit3;
17
18import junit.framework.Test;
19import junit.framework.TestResult;
20import junit.framework.TestSuite;
21
22import org.junit.Ignore;
23
24import android.app.Instrumentation;
25import android.content.Context;
26import android.os.Bundle;
27import android.test.AndroidTestCase;
28import android.test.InstrumentationTestCase;
29
30import com.android.test.BundleTest;
31
32/**
33 * A {@link TestSuite} used to pass {@link Context} and {@link Instrumentation} references to child
34 * tests.
35 */
36@Ignore
37class AndroidTestSuite extends TestSuite {
38
39    private final Instrumentation mInstr;
40    private final Bundle mBundle;
41
42    AndroidTestSuite(Class<?> clazz, Bundle bundle, Instrumentation instrumentation) {
43        super(clazz);
44        mBundle = bundle;
45        mInstr = instrumentation;
46    }
47
48    AndroidTestSuite(String name, Bundle bundle, Instrumentation instrumentation) {
49        super(name);
50        mBundle = bundle;
51        mInstr = instrumentation;
52    }
53
54    @Override
55    public void runTest(Test test, TestResult result) {
56        if (test instanceof AndroidTestCase) {
57            ((AndroidTestCase)test).setContext(mInstr.getTargetContext());
58        }
59        if (test instanceof InstrumentationTestCase) {
60            ((InstrumentationTestCase)test).injectInstrumentation(mInstr);
61        }
62        if (test instanceof BundleTest) {
63            ((BundleTest)test).injectBundle(mBundle);
64        }
65        super.runTest(test, result);
66    }
67
68    Instrumentation getInstrumentation() {
69        return mInstr;
70    }
71
72    Bundle getBundle() {
73        return mBundle;
74    }
75}
76