New ConditionManager
- Create a new ConditionManager that loads data and filters displayable condtionals in memory - Separete conditional controller logic and ui model - Plumb new ui model into DashboardAdapater, and create a new ConditionAdapter to manage UI. Bug: 112485407 Test: robotests Change-Id: If56d141d135341e9b8c2dc80e43c3d40b1de1340
This commit is contained in:
@@ -104,7 +104,8 @@ public class DashboardAdapterTest {
|
||||
mConditionList.add(mCondition);
|
||||
when(mCondition.shouldShow()).thenReturn(true);
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
mConditionList, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
mConditionList, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
when(mView.getTag()).thenReturn(mCondition);
|
||||
}
|
||||
|
||||
@@ -112,7 +113,8 @@ public class DashboardAdapterTest {
|
||||
public void onSuggestionClosed_notOnlySuggestion_updateSuggestionOnly() {
|
||||
final DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3");
|
||||
adapter.setSuggestions(suggestions);
|
||||
@@ -144,8 +146,8 @@ public class DashboardAdapterTest {
|
||||
public void onSuggestionClosed_onlySuggestion_updateDashboardData() {
|
||||
final DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
adapter.setSuggestions(suggestions);
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
@@ -161,8 +163,8 @@ public class DashboardAdapterTest {
|
||||
public void onSuggestionClosed_notInSuggestionList_shouldNotUpdateSuggestionList() {
|
||||
final DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
adapter.setSuggestions(suggestions);
|
||||
|
||||
@@ -176,7 +178,8 @@ public class DashboardAdapterTest {
|
||||
@Test
|
||||
public void onBindSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
|
||||
mDashboardAdapter.setSuggestions(suggestions);
|
||||
@@ -212,7 +215,8 @@ public class DashboardAdapterTest {
|
||||
.thenReturn(context.getDrawable(R.drawable.ic_settings));
|
||||
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
@@ -232,7 +236,8 @@ public class DashboardAdapterTest {
|
||||
final IconCache iconCache = new IconCache(context);
|
||||
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
doReturn("another.package").when(context).getPackageName();
|
||||
@@ -256,7 +261,8 @@ public class DashboardAdapterTest {
|
||||
when(iconCache.getIcon(tile.getIcon(context))).thenReturn(mock(RoundedHomepageIcon.class));
|
||||
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* conditionManager */,
|
||||
null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.homepage.conditional.v2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.homepage.conditional.ConditionListener;
|
||||
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 ConditionManagerTest {
|
||||
|
||||
private static final long ID = 123L;
|
||||
|
||||
@Mock
|
||||
private ConditionalCard mCard;
|
||||
@Mock
|
||||
private ConditionalCardController mController;
|
||||
@Mock
|
||||
private ConditionListener mConditionListener;
|
||||
|
||||
private Context mContext;
|
||||
private ConditionManager mManager;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mManager = new ConditionManager(mContext, mConditionListener);
|
||||
|
||||
assertThat(mManager.mCandidates.size()).isEqualTo(mManager.mCardControllers.size());
|
||||
|
||||
when(mController.getId()).thenReturn(ID);
|
||||
when(mCard.getId()).thenReturn(ID);
|
||||
|
||||
mManager.mCandidates.clear();
|
||||
mManager.mCardControllers.clear();
|
||||
mManager.mCandidates.add(mCard);
|
||||
mManager.mCardControllers.add(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisplayableCards_nothingDisplayable() {
|
||||
assertThat(mManager.getDisplayableCards()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisplayableCards_hasDisplayable() {
|
||||
when(mController.isDisplayable()).thenReturn(true);
|
||||
|
||||
assertThat(mManager.getDisplayableCards()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPrimaryClick_shouldRelayToController() {
|
||||
mManager.onPrimaryClick(mContext, ID);
|
||||
|
||||
verify(mController).onPrimaryClick(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActionClick_shouldRelayToController() {
|
||||
mManager.onActionClick(ID);
|
||||
|
||||
verify(mController).onActionClick();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startMonitoringStateChange_multipleTimes_shouldRegisterOnce() {
|
||||
mManager.startMonitoringStateChange();
|
||||
mManager.startMonitoringStateChange();
|
||||
mManager.startMonitoringStateChange();
|
||||
|
||||
verify(mController).startMonitoringStateChange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopMonitoringStateChange_beforeStart_shouldDoNothing() {
|
||||
mManager.stopMonitoringStateChange();
|
||||
mManager.stopMonitoringStateChange();
|
||||
mManager.stopMonitoringStateChange();
|
||||
|
||||
verify(mController, never()).startMonitoringStateChange();
|
||||
verify(mController, never()).stopMonitoringStateChange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopMonitoringStateChange_multipleTimes_shouldUnregisterOnce() {
|
||||
mManager.startMonitoringStateChange();
|
||||
|
||||
mManager.stopMonitoringStateChange();
|
||||
mManager.stopMonitoringStateChange();
|
||||
mManager.stopMonitoringStateChange();
|
||||
|
||||
verify(mController).startMonitoringStateChange();
|
||||
verify(mController).stopMonitoringStateChange();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onConditionChanged_shouldNotifyListener() {
|
||||
mManager.onConditionChanged();
|
||||
|
||||
verify(mConditionListener).onConditionsChanged();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.homepage.conditional.v2;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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 DndConditionalCardControllerTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mConditionManager;
|
||||
private Context mContext;
|
||||
private DndConditionCardController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = new DndConditionCardController(mContext, mConditionManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cycleMonitoring_shouldRegisterAndUnregisterReceiver() {
|
||||
mController.startMonitoringStateChange();
|
||||
mController.stopMonitoringStateChange();
|
||||
|
||||
verify(mContext).registerReceiver(any(DndConditionCardController.Receiver.class),
|
||||
eq(DndConditionCardController.DND_FILTER));
|
||||
verify(mContext).unregisterReceiver(any(DndConditionCardController.Receiver.class));
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.homepage.conditional.v2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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 DndConditionalCardTest {
|
||||
|
||||
@Mock
|
||||
private ConditionManager mManager;
|
||||
private DndConditionCardController mController;
|
||||
|
||||
private Context mContext;
|
||||
private DndConditionCard mCard;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
mController = new DndConditionCardController(mContext, mManager);
|
||||
when(mManager.getController(anyLong())).thenReturn(mController);
|
||||
|
||||
mCard = new DndConditionCard(mContext, mManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getId_sameAsController() {
|
||||
assertThat(mCard.getId()).isEqualTo(mController.getId());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user