• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.accounts;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 import static org.mockito.Mockito.mock;
20 
21 import android.accounts.Account;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.UserHandle;
25 import android.support.v7.preference.Preference;
26 
27 import com.android.settings.R;
28 import com.android.settings.SettingsActivity;
29 import com.android.settings.SettingsRobolectricTestRunner;
30 import com.android.settings.TestConfig;
31 
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.robolectric.annotation.Config;
35 import org.robolectric.shadows.ShadowApplication;
36 
37 @RunWith(SettingsRobolectricTestRunner.class)
38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
39 public class AccountSyncPreferenceControllerTest {
40 
41     @Test
handlePreferenceTreeClick_shouldStartFragment()42     public void handlePreferenceTreeClick_shouldStartFragment() {
43         final ShadowApplication application = ShadowApplication.getInstance();
44         final Context context = application.getApplicationContext();
45         final Preference preference = new Preference(context);
46         preference.setKey("account_sync");
47 
48         final AccountSyncPreferenceController controller =
49                 new AccountSyncPreferenceController(context);
50         controller.init(new Account("acct1", "type1"), mock(UserHandle.class));
51         controller.handlePreferenceTreeClick(preference);
52 
53         final Intent nextActivity = application.getNextStartedActivity();
54 
55         assertThat(nextActivity.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
56                 .isEqualTo(AccountSyncSettings.class.getName());
57         assertThat(nextActivity.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
58                 .isEqualTo(R.string.account_sync_title);
59     }
60 
61 }
62