1 /* 2 * Copyright (C) 2019 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 17 package com.android.settings.wallpaper; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.when; 22 23 import android.content.ContentResolver; 24 import android.content.Context; 25 import android.content.res.Resources; 26 import android.provider.Settings; 27 28 import com.android.settings.testutils.shadow.ShadowSecureSettings; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.mockito.Mock; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.RobolectricTestRunner; 36 import org.robolectric.annotation.Config; 37 38 @RunWith(RobolectricTestRunner.class) 39 public class StyleSuggestionActivityTest { 40 41 @Mock 42 private Context mContext; 43 @Mock 44 private Resources mResources; 45 @Mock 46 private ContentResolver mContentResolver; 47 48 @Before setUp()49 public void setUp() { 50 MockitoAnnotations.initMocks(this); 51 when(mContext.getResources()).thenReturn(mResources); 52 when(mContext.getContentResolver()).thenReturn(mContentResolver); 53 } 54 55 @Test wallpaperServiceEnabled_no_shouldReturnTrue()56 public void wallpaperServiceEnabled_no_shouldReturnTrue() { 57 when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService)) 58 .thenReturn(false); 59 assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isTrue(); 60 } 61 62 @Test 63 @Config(shadows = ShadowSecureSettings.class) hasStyleSet_yes_shouldReturnTrue()64 public void hasStyleSet_yes_shouldReturnTrue() { 65 when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService)) 66 .thenReturn(true); 67 68 Settings.Secure.putString(mContentResolver, 69 Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, "test"); 70 assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isTrue(); 71 } 72 73 @Test 74 @Config(shadows = ShadowSecureSettings.class) hasStyleSet_no_shouldReturnFalse()75 public void hasStyleSet_no_shouldReturnFalse() { 76 when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService)) 77 .thenReturn(true); 78 79 Settings.Secure.putString(mContentResolver, 80 Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, null); 81 assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isFalse(); 82 } 83 } 84