2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.android.settings.testutils;
18 import android.content.Context;
20 import com.android.settings.applications.ApplicationFeatureProvider;
21 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
22 import com.android.settings.dashboard.DashboardFeatureProvider;
23 import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
24 import com.android.settings.localepicker.LocaleFeatureProvider;
25 import com.android.settings.overlay.FeatureFactory;
26 import com.android.settings.overlay.SupportFeatureProvider;
28 import static org.mockito.Matchers.anyString;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.when;
33 * Test util to provide fake FeatureFactory. To use this factory, call {@code setupForTest} in
34 * {@code @Before} method of the test class.
36 public class FakeFeatureFactory extends FeatureFactory {
38 public final SupportFeatureProvider supportFeatureProvider;
39 public final MetricsFeatureProvider metricsFeatureProvider;
40 public final PowerUsageFeatureProvider powerUsageFeatureProvider;
41 public final DashboardFeatureProvider dashboardFeatureProvider;
42 public final LocaleFeatureProvider localeFeatureProvider;
43 public final ApplicationFeatureProvider applicationFeatureProvider;
46 * Call this in {@code @Before} method of the test class to use fake factory.
48 * @param context The context must be a deep mock.
50 public static void setupForTest(Context context) {
52 when(context.getString(com.android.settings.R.string.config_featureFactory))
53 .thenReturn(FakeFeatureFactory.class.getName());
55 Class c = FakeFeatureFactory.class;
56 when(context.getClassLoader().loadClass(anyString())).thenReturn(c);
57 } catch (ClassNotFoundException e) {
63 * Used by reflection. Do not call directly.
65 public FakeFeatureFactory() {
66 supportFeatureProvider = mock(SupportFeatureProvider.class);
67 metricsFeatureProvider = mock(MetricsFeatureProvider.class);
68 powerUsageFeatureProvider = mock(PowerUsageFeatureProvider.class);
69 dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
70 localeFeatureProvider = mock(LocaleFeatureProvider.class);
71 applicationFeatureProvider = mock(ApplicationFeatureProvider.class);
75 public SupportFeatureProvider getSupportFeatureProvider(Context context) {
76 return supportFeatureProvider;
80 public MetricsFeatureProvider getMetricsFeatureProvider() {
81 return metricsFeatureProvider;
85 public PowerUsageFeatureProvider getPowerUsageFeatureProvider() {
86 return powerUsageFeatureProvider;
90 public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
91 return dashboardFeatureProvider;
95 public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) {
96 return applicationFeatureProvider;
100 public LocaleFeatureProvider getLocaleFeatureProvider() {
101 return localeFeatureProvider;