summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-06-25 05:25:25 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-06-25 05:25:25 +0000
commite2b91369fed510780ffb3643edafde0e95bea1b9 (patch)
treec185245b31ba16567f69e499d21810173e1b0ce8
parent92ee1c4e91c8c1a9880af75f903b438d196fc9b6 (diff)
parent788bb708dd234f5056d265192f8306604f5698bf (diff)
downloadDialer-e2b91369fed510780ffb3643edafde0e95bea1b9.tar.gz
Snap for 7491908 from 788bb708dd234f5056d265192f8306604f5698bf to sc-release
Change-Id: Ib8dc320d08e69eb44cf7030ed1a18b13428d28fa
-rw-r--r--res/drawable/on_hold_background.xml20
-rw-r--r--res/layout/onhold_user_profile.xml7
-rw-r--r--res/values/overlayable.xml1
-rw-r--r--tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java93
-rw-r--r--tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataTest.java (renamed from tests/robotests/src/com/android/car/dialer/livedata/CallStateLiveDataTest.java)16
-rw-r--r--tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataUnitTest.java36
-rw-r--r--tests/unittests/src/com/android/car/dialer/livedata/HeartBeatLiveDataTest.java (renamed from tests/robotests/src/com/android/car/dialer/livedata/HeartBeatLiveDataTest.java)43
-rw-r--r--tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java139
-rw-r--r--tests/unittests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java (renamed from tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java)79
-rw-r--r--tests/unittests/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveDataTest.java (renamed from tests/robotests/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveDataTest.java)44
10 files changed, 265 insertions, 213 deletions
diff --git a/res/drawable/on_hold_background.xml b/res/drawable/on_hold_background.xml
new file mode 100644
index 00000000..6a7bf1ab
--- /dev/null
+++ b/res/drawable/on_hold_background.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2021 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.
+ -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <corners android:radius="@dimen/onhold_profile_corner_radius"/>
+ <solid android:color="@color/onhold_call_background"/>
+</shape>
diff --git a/res/layout/onhold_user_profile.xml b/res/layout/onhold_user_profile.xml
index 15b2af88..7773a557 100644
--- a/res/layout/onhold_user_profile.xml
+++ b/res/layout/onhold_user_profile.xml
@@ -16,12 +16,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <androidx.cardview.widget.CardView
+ <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="@dimen/dialer_card_elevation"
- app:cardBackgroundColor="@color/onhold_call_background"
- app:cardCornerRadius="@dimen/onhold_profile_corner_radius">
+ android:background="@drawable/on_hold_background">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
@@ -125,6 +124,6 @@
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
- </androidx.cardview.widget.CardView>
+ </FrameLayout>
</com.android.car.ui.FocusArea>
diff --git a/res/values/overlayable.xml b/res/values/overlayable.xml
index fcf30bb3..f04baa7f 100644
--- a/res/values/overlayable.xml
+++ b/res/values/overlayable.xml
@@ -209,6 +209,7 @@ REGENERATE USING packages/apps/Car/tests/tools/rro/generate-overlayable.py
<item type="drawable" name="ic_speaker_phone_activatable"/>
<item type="drawable" name="icon_call_button"/>
<item type="drawable" name="list_divider"/>
+ <item type="drawable" name="on_hold_background"/>
<item type="drawable" name="restricted_dialing_mode_label_background"/>
<item type="id" name="address_button"/>
<item type="id" name="answer_call_button"/>
diff --git a/tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java b/tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java
deleted file mode 100644
index 4c6c0289..00000000
--- a/tests/robotests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java
+++ /dev/null
@@ -1,93 +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.car.dialer.ui.activecall;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.view.View;
-
-import androidx.fragment.app.Fragment;
-
-import com.android.car.dialer.CarDialerRobolectricTestRunner;
-import com.android.car.dialer.FragmentTestActivity;
-import com.android.car.dialer.R;
-import com.android.car.dialer.TestDialerApplication;
-import com.android.car.telephony.common.InMemoryPhoneBook;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(CarDialerRobolectricTestRunner.class)
-public class OngoingCallFragmentTest {
-
- private OngoingCallFragment mOngoingCallFragment;
- private FragmentTestActivity mFragmentTestActivity;
- private View mUserProfileContainerView;
- private Fragment mInCallDialpadFragment;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
-
- Context context = RuntimeEnvironment.application;
- ((TestDialerApplication) context).setupInCallServiceImpl();
- InMemoryPhoneBook.init(context);
-
- mOngoingCallFragment = new OngoingCallFragment();
- mFragmentTestActivity = Robolectric.buildActivity(
- FragmentTestActivity.class).create().start().resume().get();
- mFragmentTestActivity.setFragment(mOngoingCallFragment);
-
- mUserProfileContainerView = mOngoingCallFragment.getView().findViewById(
- R.id.user_profile_container);
- mInCallDialpadFragment = mOngoingCallFragment.getChildFragmentManager().findFragmentById(
- R.id.incall_dialpad_fragment);
- }
-
- @After
- public void tearDown() {
- InMemoryPhoneBook.tearDown();
- }
-
- @Test
- public void testOnCreateView() {
- assertThat(mInCallDialpadFragment.isHidden()).isTrue();
- assertThat(mUserProfileContainerView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void testOnOpenDialpad() {
- mOngoingCallFragment.onOpenDialpad();
-
- assertThat(mInCallDialpadFragment.isHidden()).isFalse();
- assertThat(mUserProfileContainerView.getVisibility()).isEqualTo(View.GONE);
- }
-
- @Test
- public void testOnCloseDialpad() {
- mOngoingCallFragment.onCloseDialpad();
-
- assertThat(mInCallDialpadFragment.isHidden()).isTrue();
- assertThat(mUserProfileContainerView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-}
diff --git a/tests/robotests/src/com/android/car/dialer/livedata/CallStateLiveDataTest.java b/tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataTest.java
index b9e4c287..11cad651 100644
--- a/tests/robotests/src/com/android/car/dialer/livedata/CallStateLiveDataTest.java
+++ b/tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2021 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.
@@ -29,9 +29,9 @@ import android.telecom.Call;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
-
-import com.android.car.dialer.CarDialerRobolectricTestRunner;
-import com.android.car.dialer.LiveDataObserver;
+import androidx.lifecycle.Observer;
+import androidx.test.annotation.UiThreadTest;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
@@ -41,7 +41,7 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-@RunWith(CarDialerRobolectricTestRunner.class)
+@RunWith(AndroidJUnit4.class)
public class CallStateLiveDataTest {
private CallStateLiveData mCallStateLiveData;
@@ -51,7 +51,7 @@ public class CallStateLiveDataTest {
@Mock
private LifecycleOwner mMockLifecycleOwner;
@Mock
- private LiveDataObserver<Integer> mMockObserver;
+ private Observer<Integer> mMockObserver;
@Captor
private ArgumentCaptor<Call.Callback> mCallbackCaptor;
@@ -68,6 +68,7 @@ public class CallStateLiveDataTest {
}
@Test
+ @UiThreadTest
public void testOnActiveRegistry() {
mCallStateLiveData.onActive();
@@ -75,6 +76,7 @@ public class CallStateLiveDataTest {
}
@Test
+ @UiThreadTest
public void testOnLifecycleStart() {
mCallStateLiveData.observe(mMockLifecycleOwner, (value) -> mMockObserver.onChanged(value));
verify(mMockObserver, never()).onChanged(any());
@@ -88,6 +90,7 @@ public class CallStateLiveDataTest {
}
@Test
+ @UiThreadTest
public void testOnStateChanged() {
ArgumentCaptor<Integer> valueCaptor = ArgumentCaptor.forClass(Integer.class);
doNothing().when(mMockObserver).onChanged(valueCaptor.capture());
@@ -101,6 +104,7 @@ public class CallStateLiveDataTest {
}
@Test
+ @UiThreadTest
public void testOnInactiveUnregister() {
mCallStateLiveData.observe(mMockLifecycleOwner, (value) -> mMockObserver.onChanged(value));
mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
diff --git a/tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataUnitTest.java b/tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataUnitTest.java
deleted file mode 100644
index 9488040c..00000000
--- a/tests/unittests/src/com/android/car/dialer/livedata/CallStateLiveDataUnitTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2020 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.car.dialer.livedata;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class CallStateLiveDataUnitTest {
-
- @Before
- public void setup() {
- }
-
- @Test
- public void testOnActiveRegistry() {
- }
-}
-
diff --git a/tests/robotests/src/com/android/car/dialer/livedata/HeartBeatLiveDataTest.java b/tests/unittests/src/com/android/car/dialer/livedata/HeartBeatLiveDataTest.java
index d5c421e4..0d2374bd 100644
--- a/tests/robotests/src/com/android/car/dialer/livedata/HeartBeatLiveDataTest.java
+++ b/tests/unittests/src/com/android/car/dialer/livedata/HeartBeatLiveDataTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2021 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.
@@ -16,50 +16,47 @@
package com.android.car.dialer.livedata;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import android.text.format.DateUtils;
import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleOwner;
-import androidx.lifecycle.LifecycleRegistry;
+import androidx.lifecycle.Observer;
+import androidx.test.core.app.ActivityScenario;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.android.car.dialer.LiveDataObserver;
+import com.android.car.dialer.testing.TestActivity;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.shadows.ShadowLooper;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
-@RunWith(RobolectricTestRunner.class)
+@RunWith(AndroidJUnit4.class)
public class HeartBeatLiveDataTest {
private HeartBeatLiveData mHeartBeatLiveData;
-
- private LifecycleRegistry mLifecycleRegistry;
- private LifecycleOwner mLifecycleOwner;
+ @Mock
+ private Observer<Boolean> mMockObserver;
@Before
public void setup() {
+ MockitoAnnotations.initMocks(this);
mHeartBeatLiveData = new HeartBeatLiveData(DateUtils.SECOND_IN_MILLIS);
- mLifecycleOwner = mock(LifecycleOwner.class);
- mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
- when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
}
@Test
public void active_onLifecycleStart() {
- LiveDataObserver<HeartBeatLiveData> mockObserver = mock(LiveDataObserver.class);
- mHeartBeatLiveData.observe(mLifecycleOwner, (value) -> mockObserver.onChanged(value));
- verify(mockObserver, never()).onChanged(any());
-
- mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
- ShadowLooper.runUiThreadTasks();
-
- verify(mockObserver).onChanged(any());
+ ActivityScenario<TestActivity> activityScenario = ActivityScenario.launch(
+ TestActivity.class);
+ activityScenario.moveToState(Lifecycle.State.CREATED);
+ activityScenario.onActivity(activity ->
+ mHeartBeatLiveData.observe(activity, (value) -> mMockObserver.onChanged(value)));
+ verify(mMockObserver, never()).onChanged(any());
+
+ activityScenario.moveToState(Lifecycle.State.STARTED);
+ verify(mMockObserver).onChanged(any());
}
}
diff --git a/tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java b/tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java
new file mode 100644
index 00000000..947c5b22
--- /dev/null
+++ b/tests/unittests/src/com/android/car/dialer/ui/activecall/OngoingCallFragmentTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2021 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.car.dialer.ui.activecall;
+
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.assertion.ViewAssertions.matches;
+import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+
+import static org.mockito.Mockito.when;
+
+import android.telecom.Call;
+import android.telecom.CallAudioState;
+
+import androidx.core.util.Pair;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.test.core.app.ActivityScenario;
+import androidx.test.espresso.matcher.ViewMatchers;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.car.dialer.R;
+import com.android.car.dialer.livedata.CallDetailLiveData;
+import com.android.car.dialer.testing.TestActivity;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.Collections;
+
+@RunWith(AndroidJUnit4.class)
+public class OngoingCallFragmentTest {
+
+ private OngoingCallFragment mOngoingCallFragment;
+ private Call mMockCall;
+ @Mock
+ private CallAudioState mMockCallAudioState;
+ private CallDetailLiveData mMockCallDetailLiveData;
+ private LiveData<Pair<Integer, Long>> mCallStateAndConnectTimeLiveData;
+ private LiveData<Boolean> mShouldShowOnHoldCall;
+
+ private ActivityScenario<TestActivity> mActivityScenario;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ startFragment();
+ }
+
+ @Test
+ public void testOnCreateView() {
+ onView(withId(R.id.incall_dialpad_fragment))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
+ onView(withId(R.id.user_profile_container))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
+ }
+
+ @Test
+ public void testOnOpenDialpad() {
+ mActivityScenario.onActivity(activity -> {
+ mOngoingCallFragment.onOpenDialpad();
+ });
+
+ onView(withId(R.id.incall_dialpad_fragment))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
+ onView(withId(R.id.user_profile_container))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
+ }
+
+ @Test
+ public void testOnCloseDialpad() {
+ mActivityScenario.onActivity(activity -> {
+ mOngoingCallFragment.onCloseDialpad();
+ });
+
+ onView(withId(R.id.incall_dialpad_fragment))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
+ onView(withId(R.id.user_profile_container))
+ .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
+ }
+
+ private void startFragment() {
+ mActivityScenario = ActivityScenario.launch(TestActivity.class);
+ mActivityScenario.onActivity(activity -> {
+ InCallViewModel mockInCallViewModel = new ViewModelProvider(activity).get(
+ InCallViewModel.class);
+ mMockCallDetailLiveData = new CallDetailLiveData();
+ mMockCallDetailLiveData.setTelecomCall(mMockCall);
+ mShouldShowOnHoldCall = new MutableLiveData<>(false);
+ mCallStateAndConnectTimeLiveData =
+ new MutableLiveData<>(new Pair<>(Call.STATE_ACTIVE, 1000L));
+ when(mockInCallViewModel.getPrimaryCallState())
+ .thenReturn(new MutableLiveData<>(Call.STATE_ACTIVE));
+ when(mockInCallViewModel.getPrimaryCallDetail()).thenReturn(mMockCallDetailLiveData);
+ when(mockInCallViewModel.getCallStateAndConnectTime())
+ .thenReturn(mCallStateAndConnectTimeLiveData);
+ when(mockInCallViewModel.shouldShowOnholdCall()).thenReturn(mShouldShowOnHoldCall);
+ when(mockInCallViewModel.getCallAudioState())
+ .thenReturn(new MutableLiveData<>(mMockCallAudioState));
+ when(mockInCallViewModel.getAudioRoute()).thenReturn(new MutableLiveData<>(1));
+ when(mockInCallViewModel.getSupportedAudioRoutes())
+ .thenReturn(new MutableLiveData<>(Collections.EMPTY_LIST));
+ when(mockInCallViewModel.getSecondaryCallDetail()).thenReturn(mMockCallDetailLiveData);
+ when(mockInCallViewModel.getPrimaryCall()).thenReturn(new MutableLiveData<>(mMockCall));
+ when(mockInCallViewModel.getSecondaryCallConnectTime())
+ .thenReturn(new MutableLiveData<>(1000L));
+ when(mockInCallViewModel.getAllCallList())
+ .thenReturn(new MutableLiveData<>(Collections.EMPTY_LIST));
+ when(mockInCallViewModel.getOngoingCallPair())
+ .thenReturn(new MutableLiveData<>(new Pair<>(mMockCall, mMockCall)));
+ when(mockInCallViewModel.getOngoingCallList())
+ .thenReturn(new MutableLiveData<>(Collections.EMPTY_LIST));
+ when(mockInCallViewModel.getDialpadOpenState())
+ .thenReturn(new MutableLiveData<>(false));
+
+ mOngoingCallFragment = new OngoingCallFragment();
+ activity.getSupportFragmentManager().beginTransaction().add(
+ R.id.test_fragment_container, mOngoingCallFragment).commit();
+ });
+ }
+}
diff --git a/tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java b/tests/unittests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java
index 5169002c..1c8141ce 100644
--- a/tests/robotests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java
+++ b/tests/unittests/src/com/android/car/dialer/ui/favorite/FavoriteFragmentTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2021 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.
@@ -16,6 +16,10 @@
package com.android.car.dialer.ui.favorite;
+import static androidx.test.espresso.Espresso.onView;
+import static androidx.test.espresso.action.ViewActions.click;
+import static androidx.test.espresso.matcher.ViewMatchers.withId;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -25,18 +29,17 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.test.core.app.ActivityScenario;
+import androidx.test.espresso.contrib.RecyclerViewActions;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.car.arch.common.FutureData;
-import com.android.car.arch.common.LiveDataFunctions;
-import com.android.car.dialer.CarDialerRobolectricTestRunner;
-import com.android.car.dialer.FragmentTestActivity;
import com.android.car.dialer.R;
import com.android.car.dialer.telecom.UiCallManager;
-import com.android.car.dialer.testutils.ShadowAndroidViewModelFactory;
+import com.android.car.dialer.testing.TestActivity;
import com.android.car.telephony.common.Contact;
import com.android.car.telephony.common.PhoneNumber;
-import com.android.car.telephony.common.TelecomUtils;
-import com.android.car.ui.recyclerview.CarUiRecyclerView;
import org.junit.Before;
import org.junit.Test;
@@ -44,51 +47,53 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowLooper;
import java.util.Arrays;
import java.util.List;
-@Config(shadows = {ShadowAndroidViewModelFactory.class})
-@RunWith(CarDialerRobolectricTestRunner.class)
+@RunWith(AndroidJUnit4.class)
public class FavoriteFragmentTest {
private static final String RAW_NUMBER = "6502530000";
private FavoriteFragment mFavoriteFragment;
- private FavoriteContactViewHolder mViewHolder;
@Mock
private UiCallManager mMockUiCallManager;
@Mock
private Contact mMockContact;
- @Mock
- private FavoriteViewModel mMockFavoriteViewModel;
+
+ private FavoriteViewModel mFavoriteViewModel;
@Mock
private PhoneNumber mMockPhoneNumber;
+ ActivityScenario<TestActivity> mActivityScenario;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ startActivity();
+ }
+ private void startActivity() {
when(mMockPhoneNumber.getRawNumber()).thenReturn(RAW_NUMBER);
- MutableLiveData<FutureData<List<Object>>> favoriteContacts = new MutableLiveData<>();
- favoriteContacts.setValue(new FutureData<>(false, Arrays.asList(mMockContact)));
- ShadowAndroidViewModelFactory.add(FavoriteViewModel.class, mMockFavoriteViewModel);
- when(mMockFavoriteViewModel.getFavoriteContacts()).thenReturn(favoriteContacts);
- when(mMockFavoriteViewModel.getSortOrderLiveData()).thenReturn(
- LiveDataFunctions.dataOf(TelecomUtils.SORT_BY_FIRST_NAME));
-
- mFavoriteFragment = FavoriteFragment.newInstance();
- mFavoriteFragment.mUiCallManager = mMockUiCallManager;
- FragmentTestActivity fragmentTestActivity = Robolectric.buildActivity(
- FragmentTestActivity.class).create().resume().get();
- fragmentTestActivity.setFragment(mFavoriteFragment);
-
- CarUiRecyclerView recyclerView = mFavoriteFragment.getView().findViewById(R.id.list_view);
- // set up layout for recyclerView
- recyclerView.layout(0, 0, 100, 1000);
- mViewHolder = (FavoriteContactViewHolder) recyclerView.findViewHolderForLayoutPosition(0);
+ MutableLiveData<FutureData<List<Object>>> favoriteContacts = new MutableLiveData<>(
+ new FutureData<>(false, Arrays.asList(mMockContact)));
+
+ mActivityScenario = ActivityScenario.launch(TestActivity.class);
+ mActivityScenario.onActivity(activity -> {
+ mFavoriteViewModel = new ViewModelProvider(activity).get(
+ FavoriteViewModel.class);
+ when(mFavoriteViewModel.getFavoriteContacts()).thenReturn(favoriteContacts);
+ when(mFavoriteViewModel.getSortOrderLiveData()).thenReturn(new MutableLiveData<>(1));
+
+ mFavoriteFragment = FavoriteFragment.newInstance();
+
+ activity.getSupportFragmentManager().beginTransaction().add(
+ R.id.test_fragment_container, mFavoriteFragment).commit();
+ });
+
+ mActivityScenario.onActivity(activity -> {
+ mFavoriteFragment.mUiCallManager = mMockUiCallManager;
+ });
}
@Test
@@ -97,7 +102,8 @@ public class FavoriteFragmentTest {
when(mMockContact.hasPrimaryPhoneNumber()).thenReturn(true);
when(mMockContact.getPrimaryPhoneNumber()).thenReturn(mMockPhoneNumber);
- mViewHolder.itemView.performClick();
+ onView(withId(R.id.list_view)).perform(
+ RecyclerViewActions.actionOnItemAtPosition(0, click()));
ArgumentCaptor<String> mCaptor = ArgumentCaptor.forClass(String.class);
verify(mMockUiCallManager).placeCall(mCaptor.capture());
@@ -109,7 +115,8 @@ public class FavoriteFragmentTest {
when(mMockContact.hasPrimaryPhoneNumber()).thenReturn(false);
when(mMockContact.getNumbers()).thenReturn(Arrays.asList(mMockPhoneNumber));
- mViewHolder.itemView.performClick();
+ onView(withId(R.id.list_view)).perform(
+ RecyclerViewActions.actionOnItemAtPosition(0, click()));
ArgumentCaptor<String> mCaptor = ArgumentCaptor.forClass(String.class);
verify(mMockUiCallManager).placeCall(mCaptor.capture());
@@ -123,8 +130,8 @@ public class FavoriteFragmentTest {
when(mMockContact.getNumbers()).thenReturn(
Arrays.asList(mMockPhoneNumber, otherMockPhoneNumber));
- ShadowLooper.pauseMainLooper();
- mViewHolder.itemView.performClick();
+ onView(withId(R.id.list_view)).perform(
+ RecyclerViewActions.actionOnItemAtPosition(0, click()));
verify(mMockUiCallManager, never()).placeCall(any());
}
diff --git a/tests/robotests/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveDataTest.java b/tests/unittests/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveDataTest.java
index 32243133..14ea4a31 100644
--- a/tests/robotests/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveDataTest.java
+++ b/tests/unittests/src/com/android/car/dialer/ui/warning/BluetoothErrorStringLiveDataTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 The Android Open Source Project
+ * Copyright (C) 2021 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.
@@ -25,28 +25,31 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.Observer;
+import androidx.test.annotation.UiThreadTest;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.android.car.dialer.CarDialerRobolectricTestRunner;
import com.android.car.dialer.R;
import com.android.car.dialer.bluetooth.BluetoothState;
-import com.android.car.dialer.testutils.ShadowBluetoothAdapterForDialer;
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 java.util.Collections;
import java.util.List;
import java.util.Set;
-@RunWith(CarDialerRobolectricTestRunner.class)
-@Config(shadows = ShadowBluetoothAdapterForDialer.class)
+@RunWith(AndroidJUnit4.class)
public class BluetoothErrorStringLiveDataTest {
+ @Mock
private Context mContext;
+ @Mock
+ private Observer<String> mMockObserver;
+ private BluetoothAdapter mBluetoothAdapter;
private MutableLiveData<List<BluetoothDevice>> mHfpDeviceListLiveData;
private MutableLiveData<Set<BluetoothDevice>> mPairedListLiveData;
private MutableLiveData<Integer> mBluetoothStateLiveData;
@@ -55,13 +58,15 @@ public class BluetoothErrorStringLiveDataTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
-
- mContext = RuntimeEnvironment.application;
+ mHfpDeviceListLiveData = new MutableLiveData<>(Collections.emptyList());
+ mPairedListLiveData = new MutableLiveData<>(Collections.emptySet());
+ mBluetoothStateLiveData = new MutableLiveData<>(0);
}
@Test
+ @UiThreadTest
public void testDialerAppState_defaultBluetoothAdapterIsNull_bluetoothError() {
- ShadowBluetoothAdapterForDialer.setBluetoothAvailable(false);
+ mBluetoothAdapter = null;
initializeBluetoothErrorStringLiveData();
@@ -70,8 +75,9 @@ public class BluetoothErrorStringLiveDataTest {
}
@Test
+ @UiThreadTest
public void testDialerAppState_bluetoothNotEnabled_bluetoothError() {
- ShadowBluetoothAdapterForDialer.setBluetoothAvailable(true);
+ mBluetoothAdapter = mock(BluetoothAdapter.class);
mBluetoothStateLiveData.setValue(BluetoothState.DISABLED);
initializeBluetoothErrorStringLiveData();
@@ -81,8 +87,9 @@ public class BluetoothErrorStringLiveDataTest {
}
@Test
+ @UiThreadTest
public void testDialerAppState_noPairedDevices_bluetoothError() {
- ShadowBluetoothAdapterForDialer.setBluetoothAvailable(true);
+ mBluetoothAdapter = mock(BluetoothAdapter.class);
mBluetoothStateLiveData.setValue(BluetoothState.ENABLED);
mPairedListLiveData.setValue(Collections.emptySet());
@@ -93,8 +100,9 @@ public class BluetoothErrorStringLiveDataTest {
}
@Test
+ @UiThreadTest
public void testDialerAppState_hfpNoConnected_bluetoothError() {
- ShadowBluetoothAdapterForDialer.setBluetoothAvailable(true);
+ mBluetoothAdapter = mock(BluetoothAdapter.class);
mBluetoothStateLiveData.setValue(BluetoothState.ENABLED);
BluetoothDevice mockBluetoothDevice = mock(BluetoothDevice.class);
mPairedListLiveData.setValue(Collections.singleton(mockBluetoothDevice));
@@ -107,8 +115,9 @@ public class BluetoothErrorStringLiveDataTest {
}
@Test
+ @UiThreadTest
public void testDialerAppState_bluetoothAllSet_dialerAppNoError() {
- ShadowBluetoothAdapterForDialer.setBluetoothAvailable(true);
+ mBluetoothAdapter = mock(BluetoothAdapter.class);
mBluetoothStateLiveData.setValue(BluetoothState.ENABLED);
BluetoothDevice mockBluetoothDevice = mock(BluetoothDevice.class);
mPairedListLiveData.setValue(Collections.singleton(mockBluetoothDevice));
@@ -123,9 +132,14 @@ public class BluetoothErrorStringLiveDataTest {
private void initializeBluetoothErrorStringLiveData() {
mBluetoothErrorStringLiveData = new BluetoothErrorStringLiveData(mContext,
mHfpDeviceListLiveData, mPairedListLiveData, mBluetoothStateLiveData,
- BluetoothAdapter.getDefaultAdapter());
+ mBluetoothAdapter);
// Observers needed so that the liveData's internal initialization is triggered
mBluetoothStateLiveData.observeForever(error -> {
});
+ mHfpDeviceListLiveData.observeForever(error -> {
+ });
+ mPairedListLiveData.observeForever(error -> {
+ });
+ mBluetoothErrorStringLiveData.observeForever(mMockObserver);
}
}