Merge "Clean up ConditionalCards"
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -79,5 +80,10 @@ public class AbnormalRingerConditionControllerBaseTest {
|
||||
public boolean isDisplayable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextualCard buildContextualCard() {
|
||||
return new ConditionalContextualCard.Builder().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||
import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -74,8 +73,8 @@ public class ConditionContextualCardControllerTest {
|
||||
|
||||
@Test
|
||||
public void onConditionsChanged_listenerIsSet_shouldUpdateData() {
|
||||
final FakeConditionalCard fakeConditionalCard = new FakeConditionalCard(mContext);
|
||||
final List<ConditionalCard> conditionalCards = new ArrayList<>();
|
||||
final ContextualCard fakeConditionalCard = new ConditionalContextualCard.Builder().build();
|
||||
final List<ContextualCard> conditionalCards = new ArrayList<>();
|
||||
conditionalCards.add(fakeConditionalCard);
|
||||
when(mConditionManager.getDisplayableCards()).thenReturn(conditionalCards);
|
||||
mController.setCardUpdateListener(mListener);
|
||||
@@ -87,8 +86,8 @@ public class ConditionContextualCardControllerTest {
|
||||
|
||||
@Test
|
||||
public void onConditionsChanged_listenerNotSet_shouldNotUpdateData() {
|
||||
final FakeConditionalCard fakeConditionalCard = new FakeConditionalCard(mContext);
|
||||
final List<ConditionalCard> conditionalCards = new ArrayList<>();
|
||||
final ContextualCard fakeConditionalCard = new ConditionalContextualCard.Builder().build();
|
||||
final List<ContextualCard> conditionalCards = new ArrayList<>();
|
||||
conditionalCards.add(fakeConditionalCard);
|
||||
when(mConditionManager.getDisplayableCards()).thenReturn(conditionalCards);
|
||||
|
||||
@@ -96,43 +95,4 @@ public class ConditionContextualCardControllerTest {
|
||||
|
||||
verify(mListener, never()).onContextualCardUpdated(any());
|
||||
}
|
||||
|
||||
private class FakeConditionalCard implements ConditionalCard {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public FakeConditionalCard(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getActionText() {
|
||||
return "action_text_test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mContext.getDrawable(R.drawable.ic_do_not_disturb_on_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return "title_text_test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return "summary_text_test";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ public class ConditionManagerTest {
|
||||
|
||||
private static final long ID = 123L;
|
||||
|
||||
@Mock
|
||||
private ConditionalCard mCard;
|
||||
@Mock
|
||||
private ConditionalCardController mController;
|
||||
@Mock
|
||||
@@ -57,14 +55,11 @@ public class ConditionManagerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mManager = spy(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();
|
||||
when(mController.buildContextualCard()).thenReturn(
|
||||
new ConditionalContextualCard.Builder()
|
||||
.build());
|
||||
mManager.mCardControllers.clear();
|
||||
mManager.mCandidates.add(mCard);
|
||||
mManager.mCardControllers.add(mController);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +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.homepage.contextualcards.conditional;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +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.homepage.contextualcards.conditional;
|
||||
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class RingerVibrateConditionCardTest {
|
||||
|
||||
private Context mContext;
|
||||
private RingerVibrateConditionCard mCard;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mCard = new RingerVibrateConditionCard(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyText() {
|
||||
assertThat(mCard.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_vibrate_title));
|
||||
assertThat(mCard.getSummary()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_vibrate_summary));
|
||||
assertThat(mCard.getActionText()).isEqualTo(
|
||||
mContext.getText(R.string.condition_device_muted_action_turn_on_sound));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user