OSDN Git Service

Import translations. DO NOT MERGE am: bb6af9902d -s ours am: 061b294714 -s ours...
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / testutils / FakeFeatureFactory.java
1 /*
2  * Copyright (C) 2016 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  */
16 package com.android.settings.testutils;
17
18 import android.content.Context;
19
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.enterprise.EnterprisePrivacyFeatureProvider;
24 import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
25 import com.android.settings.localepicker.LocaleFeatureProvider;
26 import com.android.settings.overlay.FeatureFactory;
27 import com.android.settings.overlay.SupportFeatureProvider;
28 import com.android.settings.search2.SearchFeatureProvider;
29
30 import static org.mockito.Matchers.anyString;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33
34 /**
35  * Test util to provide fake FeatureFactory. To use this factory, call {@code setupForTest} in
36  * {@code @Before} method of the test class.
37  */
38 public class FakeFeatureFactory extends FeatureFactory {
39
40     public final SupportFeatureProvider supportFeatureProvider;
41     public final MetricsFeatureProvider metricsFeatureProvider;
42     public final PowerUsageFeatureProvider powerUsageFeatureProvider;
43     public final DashboardFeatureProvider dashboardFeatureProvider;
44     public final LocaleFeatureProvider localeFeatureProvider;
45     public final ApplicationFeatureProvider applicationFeatureProvider;
46     public final EnterprisePrivacyFeatureProvider enterprisePrivacyFeatureProvider;
47     public final SearchFeatureProvider searchFeatureProvider;
48
49     /**
50      * Call this in {@code @Before} method of the test class to use fake factory.
51      *
52      * @param context The context must be a deep mock.
53      */
54     public static void setupForTest(Context context) {
55         sFactory = null;
56         when(context.getString(com.android.settings.R.string.config_featureFactory))
57                 .thenReturn(FakeFeatureFactory.class.getName());
58         try {
59             Class c = FakeFeatureFactory.class;
60             when(context.getClassLoader().loadClass(anyString())).thenReturn(c);
61         } catch (ClassNotFoundException e) {
62             // Ignore.
63         }
64     }
65
66     /**
67      * Used by reflection. Do not call directly.
68      */
69     public FakeFeatureFactory() {
70         supportFeatureProvider = mock(SupportFeatureProvider.class);
71         metricsFeatureProvider = mock(MetricsFeatureProvider.class);
72         powerUsageFeatureProvider = mock(PowerUsageFeatureProvider.class);
73         dashboardFeatureProvider = mock(DashboardFeatureProvider.class);
74         localeFeatureProvider = mock(LocaleFeatureProvider.class);
75         applicationFeatureProvider = mock(ApplicationFeatureProvider.class);
76         enterprisePrivacyFeatureProvider = mock(EnterprisePrivacyFeatureProvider.class);
77         searchFeatureProvider = mock(SearchFeatureProvider.class);
78     }
79
80     @Override
81     public SupportFeatureProvider getSupportFeatureProvider(Context context) {
82         return supportFeatureProvider;
83     }
84
85     @Override
86     public MetricsFeatureProvider getMetricsFeatureProvider() {
87         return metricsFeatureProvider;
88     }
89
90     @Override
91     public PowerUsageFeatureProvider getPowerUsageFeatureProvider() {
92         return powerUsageFeatureProvider;
93     }
94
95     @Override
96     public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
97         return dashboardFeatureProvider;
98     }
99
100     @Override
101     public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) {
102         return applicationFeatureProvider;
103     }
104
105     @Override
106     public LocaleFeatureProvider getLocaleFeatureProvider() {
107         return localeFeatureProvider;
108     }
109
110     @Override
111     public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
112         return enterprisePrivacyFeatureProvider;
113     }
114
115     @Override
116     public SearchFeatureProvider getSearchFeatureProvider(Context context) {
117         return searchFeatureProvider;
118     }
119 }