Move conditional stuff from dashboard/ to homepage package.
dashboard package is not a real place for homepage stuff. Putting Conditionals here makes it easier to refactor it for new homepage in the future Bug: 110405144 Bug: 112485407 Test: robotests Change-Id: If433aeac8766124f0f4f6e5786b93ac1372bb745
This commit is contained in:
@@ -45,7 +45,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.homepage.conditional.Condition;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
@@ -33,8 +33,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||
|
||||
import com.android.settings.dashboard.conditional.AirplaneModeCondition;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.homepage.conditional.AirplaneModeCondition;
|
||||
import com.android.settings.homepage.conditional.Condition;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
|
@@ -30,8 +30,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||
import com.android.settings.homepage.conditional.ConditionManager;
|
||||
import com.android.settings.homepage.conditional.FocusRecyclerView;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AbnormalRingerConditionBaseTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private Context mContext;
|
||||
private TestCondition mCondition;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mCondition = new TestCondition(mConditionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newInstance_shouldMonitorRingerStateChangeBroadcast() {
|
||||
final Intent broadcast1 = new Intent("foo.bar.action");
|
||||
final Intent broadcast2 = new Intent(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
||||
|
||||
mContext.sendBroadcast(broadcast1);
|
||||
assertThat(mCondition.mRefreshCalled).isFalse();
|
||||
|
||||
mContext.sendBroadcast(broadcast2);
|
||||
assertThat(mCondition.mRefreshCalled).isTrue();
|
||||
}
|
||||
|
||||
private static class TestCondition extends AbnormalRingerConditionBase {
|
||||
private boolean mRefreshCalled;
|
||||
|
||||
TestCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
mRefreshCalled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BackgroundDataConditionTest {
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPrimaryClick_shouldReturn2SummaryActivity() {
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
BackgroundDataCondition backgroundDataCondition
|
||||
= new BackgroundDataCondition(mConditionManager);
|
||||
backgroundDataCondition.onPrimaryClick();
|
||||
verify(mContext).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(
|
||||
Settings.DataUsageSummaryActivity.class.getName());
|
||||
}
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.BatterySaverReceiver;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowPowerManager;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class BatterySaverConditionTest {
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private ShadowPowerManager mPowerManager;
|
||||
private Context mContext;
|
||||
private BatterySaverCondition mCondition;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mCondition = spy(new BatterySaverCondition(mConditionManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyText() {
|
||||
assertThat(mCondition.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.condition_battery_title));
|
||||
assertThat(mCondition.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.condition_battery_summary));
|
||||
assertThat(mCondition.getActions()[0]).isEqualTo(
|
||||
mContext.getText(R.string.condition_turn_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldRegisterReceiver() {
|
||||
mCondition.onResume();
|
||||
|
||||
verify(mContext).registerReceiver(any(BatterySaverReceiver.class), any(IntentFilter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUnregisterReceiver() {
|
||||
mCondition.onResume();
|
||||
mCondition.onPause();
|
||||
|
||||
verify(mContext).unregisterReceiver(any(BatterySaverReceiver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshState_PowerSaverOn_shouldActivate() {
|
||||
mPowerManager.setIsPowerSaveMode(true);
|
||||
|
||||
mCondition.refreshState();
|
||||
|
||||
assertThat(mCondition.isActive()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshState_PowerSaverOff_shouldNotActivate() {
|
||||
mPowerManager.setIsPowerSaveMode(false);
|
||||
|
||||
mCondition.refreshState();
|
||||
|
||||
assertThat(mCondition.isActive()).isFalse();
|
||||
}
|
||||
}
|
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardAdapter;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ConditionAdapterTest {
|
||||
|
||||
@Mock
|
||||
private Condition mCondition1;
|
||||
@Mock
|
||||
private Condition mCondition2;
|
||||
|
||||
private Context mContext;
|
||||
private ConditionAdapter mConditionAdapter;
|
||||
private List<Condition> mOneCondition;
|
||||
private List<Condition> mTwoConditions;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
final CharSequence[] actions = new CharSequence[2];
|
||||
when(mCondition1.getActions()).thenReturn(actions);
|
||||
when(mCondition1.shouldShow()).thenReturn(true);
|
||||
mOneCondition = new ArrayList<>();
|
||||
mOneCondition.add(mCondition1);
|
||||
mTwoConditions = new ArrayList<>();
|
||||
mTwoConditions.add(mCondition1);
|
||||
mTwoConditions.add(mCondition2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_notExpanded_shouldReturn0() {
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mOneCondition, false);
|
||||
assertThat(mConditionAdapter.getItemCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_expanded_shouldReturnListSize() {
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mOneCondition, true);
|
||||
assertThat(mConditionAdapter.getItemCount()).isEqualTo(1);
|
||||
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mTwoConditions, true);
|
||||
assertThat(mConditionAdapter.getItemCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemViewType_shouldReturnConditionTile() {
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mTwoConditions, true);
|
||||
assertThat(mConditionAdapter.getItemViewType(0)).isEqualTo(R.layout.condition_tile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_shouldSetListener() {
|
||||
final View view = LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.condition_tile, new LinearLayout(mContext), true);
|
||||
final DashboardAdapter.DashboardItemHolder viewHolder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mOneCondition, true);
|
||||
|
||||
mConditionAdapter.onBindViewHolder(viewHolder, 0);
|
||||
final View card = view.findViewById(R.id.content);
|
||||
assertThat(card).isNotNull();
|
||||
assertThat(card.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewClick_shouldInvokeConditionPrimaryClick() {
|
||||
final View view = LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.condition_tile, new LinearLayout(mContext), true);
|
||||
final DashboardAdapter.DashboardItemHolder viewHolder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mOneCondition, true);
|
||||
|
||||
mConditionAdapter.onBindViewHolder(viewHolder, 0);
|
||||
final View card = view.findViewById(R.id.content);
|
||||
assertThat(card).isNotNull();
|
||||
card.performClick();
|
||||
verify(mCondition1).onPrimaryClick();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSwiped_nullCondition_shouldNotCrash() {
|
||||
final RecyclerView recyclerView = new RecyclerView(mContext);
|
||||
final View view = LayoutInflater.from(mContext).inflate(
|
||||
R.layout.condition_tile, new LinearLayout(mContext), true);
|
||||
final DashboardAdapter.DashboardItemHolder viewHolder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
mConditionAdapter = new ConditionAdapter(mContext, mOneCondition, true);
|
||||
mConditionAdapter.addDismissHandling(recyclerView);
|
||||
|
||||
// do not bind viewholder to simulate the null condition scenario
|
||||
mConditionAdapter.mSwipeCallback.onSwiped(viewHolder, 0);
|
||||
// no crash
|
||||
}
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class ConditionTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
@Mock
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
private Context mContext;
|
||||
private TestCondition mCondition;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mCondition = new TestCondition(mConditionManager, mMetricsFeatureProvider);
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_shouldNotBeSilenced() {
|
||||
assertThat(mCondition.isSilenced()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silence_shouldNotifyDataChangeAndLog() {
|
||||
mCondition.silence();
|
||||
|
||||
assertThat(mCondition.isSilenced()).isTrue();
|
||||
verify(mConditionManager).notifyChanged(mCondition);
|
||||
verify(mMetricsFeatureProvider).action(any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_CONDITION_DISMISS),
|
||||
eq(TestCondition.TEST_METRIC_CONSTANT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSilenceChanged_silenced_shouldRegisterReceiver() {
|
||||
mCondition.onSilenceChanged(true);
|
||||
|
||||
verify(mContext).registerReceiver(
|
||||
TestCondition.mReceiver, TestCondition.TESTS_INTENT_FILTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSilenceChanged_notSilenced_registered_shouldUnregisterReceiver() {
|
||||
mCondition.onSilenceChanged(true);
|
||||
|
||||
mCondition.onSilenceChanged(false);
|
||||
|
||||
verify(mContext).unregisterReceiver(TestCondition.mReceiver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSilenceChanged_notSilenced_notRegistered_shouldNotCrash() {
|
||||
mCondition.onSilenceChanged(false);
|
||||
|
||||
verify(mContext, never()).unregisterReceiver(TestCondition.mReceiver);
|
||||
// no crash
|
||||
}
|
||||
|
||||
private static final class TestCondition extends Condition {
|
||||
|
||||
private static final int TEST_METRIC_CONSTANT = 1234;
|
||||
private static final IntentFilter TESTS_INTENT_FILTER = new IntentFilter("TestIntent");
|
||||
private static final BroadcastReceiver mReceiver = mock(BroadcastReceiver.class);
|
||||
|
||||
TestCondition(ConditionManager manager, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
super(manager, metricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return TEST_METRIC_CONSTANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BroadcastReceiver getReceiver() {
|
||||
return mReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentFilter getIntentFilter() {
|
||||
return TESTS_INTENT_FILTER;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DndConditionTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_shouldNotDisableReceiver() {
|
||||
new DndCondition(mConditionManager);
|
||||
verify(mPackageManager, never()).setComponentEnabledSetting(any(ComponentName.class),
|
||||
eq(PackageManager.COMPONENT_ENABLED_STATE_DISABLED), eq(PackageManager.DONT_KILL_APP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_shouldRegisterReceiver() {
|
||||
new DndCondition(mConditionManager);
|
||||
verify(mContext).registerReceiver(any(DndCondition.Receiver.class),
|
||||
eq(DndCondition.DND_FILTER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silence_shouldNotDisableReceiver() {
|
||||
new DndCondition(mConditionManager).silence();
|
||||
|
||||
verify(mPackageManager, never()).setComponentEnabledSetting(any(ComponentName.class),
|
||||
eq(PackageManager.COMPONENT_ENABLED_STATE_DISABLED), eq(PackageManager.DONT_KILL_APP));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldRegisterReceiver() {
|
||||
DndCondition condition = new DndCondition(mConditionManager);
|
||||
condition.onPause();
|
||||
condition.onResume();
|
||||
|
||||
// one from constructor, one from onResume()
|
||||
verify(mContext, times(2)).registerReceiver(any(DndCondition.Receiver.class),
|
||||
eq(DndCondition.DND_FILTER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUnregisterReceiver() {
|
||||
new DndCondition(mConditionManager).onPause();
|
||||
|
||||
verify(mContext).unregisterReceiver(any(DndCondition.Receiver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_noReceiverRegistered_shouldNotUnregisterReceiver() {
|
||||
DndCondition condition = new DndCondition(mConditionManager);
|
||||
condition.onPause();
|
||||
reset(mContext);
|
||||
|
||||
condition.onPause();
|
||||
|
||||
verify(mContext, never()).unregisterReceiver(any(DndCondition.Receiver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullZenConfig_noCrash() {
|
||||
DndCondition condition = new DndCondition(mConditionManager);
|
||||
assertThat(condition.mConfig).isNull();
|
||||
|
||||
// should not crash, instead summary is null
|
||||
assertThat(condition.getSummary()).isNull();
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
||||
import com.android.settings.testutils.shadow.ShadowNotificationManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowNotificationManager.class, ShadowAudioManager.class})
|
||||
public class RingerMutedConditionTest {
|
||||
private static final String TAG = "RingerMutedConditionTest";
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private Context mContext;
|
||||
private ShadowNotificationManager mNotificationManager;
|
||||
private ShadowAudioManager mAudioManager;
|
||||
private RingerMutedCondition mCondition;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mAudioManager = Shadow.extract(mContext.getSystemService(Context.AUDIO_SERVICE));
|
||||
mNotificationManager = Shadow.extract(
|
||||
mContext.getSystemService(Context.NOTIFICATION_SERVICE));
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mCondition = spy(new RingerMutedCondition(mConditionManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyText() {
|
||||
assertThat(mCondition.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_muted_title));
|
||||
assertThat(mCondition.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_muted_summary));
|
||||
assertThat(mCondition.getActions()[0]).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_muted_action_turn_on_sound));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshState_zenModeOn_shouldNotActivate() {
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT);
|
||||
mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_NO_INTERRUPTIONS, null, TAG);
|
||||
|
||||
mCondition.refreshState();
|
||||
|
||||
verify(mCondition).setActive(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshState_zenModeOff_shouldActivate() {
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT);
|
||||
mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_OFF, null, TAG);
|
||||
|
||||
mCondition.refreshState();
|
||||
|
||||
verify(mCondition).setActive(true);
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class RingerVibrateConditionTest {
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private Context mContext;
|
||||
private RingerVibrateCondition mCondition;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mCondition = new RingerVibrateCondition(mConditionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyText() {
|
||||
assertThat(mCondition.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_vibrate_title));
|
||||
assertThat(mCondition.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_vibrate_summary));
|
||||
assertThat(mCondition.getActions()[0]).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_muted_action_turn_on_sound));
|
||||
}
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class WorkModeConditionTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
|
||||
private Context mContext;
|
||||
private WorkModeCondition mCondition;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
when(mConditionManager.getContext()).thenReturn(mContext);
|
||||
mCondition = new WorkModeCondition(mConditionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPrimaryClick_shouldLaunchAccountsSetting() {
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mContext, Settings.AccountDashboardActivity.class);
|
||||
|
||||
mCondition.onPrimaryClick();
|
||||
|
||||
verify(mContext).startActivity(
|
||||
argThat(intent-> intent.getComponent().equals(componentName)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user