Revert "Use the run script from external/robolectric-shadows"
This reverts commit c09ba5f84d50c7515300c9bfa2b7f9b3339bd993.
Reason for revert: we're cutting the feature from P
Change-Id: I5310754bbedd597e742b6bc3eeedaa1f025afe03
diff --git a/tests/robotests/Android.mk b/tests/robotests/Android.mk
index 1aee1e3..d686e42 100644
--- a/tests/robotests/Android.mk
+++ b/tests/robotests/Android.mk
@@ -1,40 +1,46 @@
-##############################################
-# Compile TeleService robolectric tests
-##############################################
-LOCAL_PATH := $(call my-dir)
+#############################################
+# Telephony Robolectric test target. #
+#############################################
+LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_MODULE := TeleService_robotests
-
LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_PRIVILEGED_MODULE := true
-LOCAL_JAVA_RESOURCE_DIRS := res
+# Include the testing libraries (JUnit4 + Robolectric libs).
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ platform-robolectric-android-all-stubs \
+ android-support-test \
+ mockito-robolectric-prebuilt \
+ platform-test-annotations \
+ truth-prebuilt \
+ testng
LOCAL_JAVA_LIBRARIES := \
- robolectric_android-all-stub \
- Robolectric_all-target \
- truth-prebuilt
+ junit \
+ platform-robolectric-3.6.1-prebuilt \
+ telephony-common \
+ sdk_vcurrent
LOCAL_INSTRUMENTATION_FOR := TeleService
+LOCAL_MODULE := TeleRobo
+
+LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_JAVA_LIBRARY)
-##############################################
-# Execute TeleService robolectric tests
-##############################################
+#############################################################
+# Telephony runner target to run the previous target. #
+#############################################################
include $(CLEAR_VARS)
-LOCAL_MODULE := Run_TeleService_robotests
+LOCAL_MODULE := TelephonyRoboTests
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ TeleRobo \
LOCAL_TEST_PACKAGE := TeleService
-LOCAL_JAVA_LIBRARIES := \
- TeleService_robotests \
- robolectric_android-all-stub \
- Robolectric_all-target \
- truth-prebuilt
-
-LOCAL_ROBOTEST_FILES := $(filter-out %/BaseRobolectricTest.java,\
- $(call find-files-in-subdirs, $(LOCAL_PATH)/src, *Test.java, .))
-
-include external/robolectric-shadows/run_robotests.mk
\ No newline at end of file
+include prebuilts/misc/common/robolectric/3.6.1/run_robotests.mk
\ No newline at end of file
diff --git a/tests/robotests/res/robolectric.properties b/tests/robotests/res/robolectric.properties
deleted file mode 100644
index d83f967..0000000
--- a/tests/robotests/res/robolectric.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-manifest=/packages/services/Telephony/AndroidManifest.xml
-sdk=NEWEST_SDK
-shadows=com.android.phone.ShadowPhoneGlobals
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/phone/ShadowPhoneGlobals.java b/tests/robotests/src/com/android/phone/ShadowPhoneGlobals.java
deleted file mode 100644
index fb38d10..0000000
--- a/tests/robotests/src/com/android/phone/ShadowPhoneGlobals.java
+++ /dev/null
@@ -1,41 +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.phone;
-
-import android.os.Build;
-
-import com.android.i18n.phonenumbers.PhoneNumberUtil;
-
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-
-@Implements(PhoneGlobals.class)
-public class ShadowPhoneGlobals {
-
- private final PhoneNumberUtil mPhoneNumberUtil = PhoneNumberUtil.getInstance();
-
- @Implementation
- public static PhoneGlobals getInstance() {
- return new PhoneGlobals(RuntimeEnvironment.application);
- }
-
- @Implementation(minSdk = Build.VERSION_CODES.P)
- public PhoneNumberUtil getPhoneNumberUtil() {
- return mPhoneNumberUtil;
- }
-}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/phone/TestPhoneApp.java b/tests/robotests/src/com/android/phone/TestPhoneApp.java
deleted file mode 100644
index ce4a576..0000000
--- a/tests/robotests/src/com/android/phone/TestPhoneApp.java
+++ /dev/null
@@ -1,33 +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.phone;
-
-import android.app.Application;
-
-/**
- * TestPhoneApp replaces {@link PhoneApp} when TelephonyService robolectric tests are executed.
- */
-@SuppressWarnings("unused")
-public class TestPhoneApp extends Application {
-
- @Override
- public void onCreate() {
- // Obscure the call to PhoneApp.onCreate(). It triggers a lot of static initialization that:
- // a) does not like to execute more than once in a process
- // b) relies on many values found in Android that would have to be mocked
- }
-}
diff --git a/tests/robotests/src/com/android/phone/assisteddialing/AssistedDialingMediatorStubTest.java b/tests/robotests/src/com/android/phone/assisteddialing/AssistedDialingMediatorStubTest.java
index 225776f..57bf127 100755
--- a/tests/robotests/src/com/android/phone/assisteddialing/AssistedDialingMediatorStubTest.java
+++ b/tests/robotests/src/com/android/phone/assisteddialing/AssistedDialingMediatorStubTest.java
@@ -16,24 +16,28 @@
package com.android.phone.assisteddialing;
-import static com.google.common.truth.Truth.assertThat;
-
import android.content.Context;
import android.telephony.TelephonyManager;
+import static com.google.common.truth.Truth.assertThat;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowTelephonyManager;
import java.util.Optional;
-
/**
* Unit Tests for AssistedDialingMediator.
*/
@RunWith(RobolectricTestRunner.class)
+@Config(
+ manifest = Config.NONE,
+ shadows = {ShadowTelephonyManager.class}
+)
public class AssistedDialingMediatorStubTest {
private final TelephonyManager mTelephonyManager =
diff --git a/tests/robotests/src/com/android/phone/assisteddialing/ConstraintsTest.java b/tests/robotests/src/com/android/phone/assisteddialing/ConstraintsTest.java
deleted file mode 100644
index f67e06f..0000000
--- a/tests/robotests/src/com/android/phone/assisteddialing/ConstraintsTest.java
+++ /dev/null
@@ -1,147 +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.phone.assisteddialing;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-/**
- * Unit Tests for Constraints.
- */
-@RunWith(RobolectricTestRunner.class)
-public class ConstraintsTest {
-
- public final Context mContext = RuntimeEnvironment.application.getBaseContext();
- private final CountryCodeProvider mCountryCodeProvider = new CountryCodeProvider();
- private Constraints mConstraints = new Constraints(mContext, mCountryCodeProvider);
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_countryCodesEquivalent() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.TEST_NUMBER_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_countryCodesUnsupported() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.TEST_NUMBER_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.UNSUPPORTED_COUNTRY_CODE_NORTH_KOREA))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_numberIsAlreadyInternational() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.INTERNATIONAL_TEST_NUMBER_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_conditionsAreCorrect() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.TEST_NUMBER_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM))
- .isTrue();
- }
-
- @Test
- public void testLocalesAreAlwaysUpperCase() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.TEST_NUMBER_UNITED_STATES,
- AssistedDialingTestHelper
- .SUPPORTED_COUNTRY_CODE_UNITED_STATES.toLowerCase(),
- AssistedDialingTestHelper
- .SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM.toLowerCase()))
- .isTrue();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_nullNumber() {
- assertThat(
- mConstraints.meetsPreconditions(
- null,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_hasExtension() {
- assertThat(
- mConstraints.meetsPreconditions(AssistedDialingTestHelper
- .TEST_NUMBER_UNITED_STATES_WITH_POST_DIAL_EXTENSION,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_nullCountryCodes() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.TEST_NUMBER_UNITED_STATES, null, null))
- .isFalse();
- }
-
- @Test
- public void testnumberPreconditionsForAssistedDialing_isLocalEmergencyNumber_unitedStates() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.TEST_NUMBER_EMERGENCY_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_numberIsInvalid() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.INVALID_TEST_NUMBER_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM))
- .isFalse();
- }
-
- @Test
- public void testnumberMeetsPreconditionsForAssistedDialing_numberShouldNotParse() {
- assertThat(
- mConstraints.meetsPreconditions(
- AssistedDialingTestHelper.INVALID_NUMBER_ENCODING,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_STATES,
- AssistedDialingTestHelper.SUPPORTED_COUNTRY_CODE_UNITED_KINGDOM))
- .isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/phone/assisteddialing/CountryCodeProviderTest.java b/tests/robotests/src/com/android/phone/assisteddialing/CountryCodeProviderTest.java
index 028b0f2..3afbc76 100755
--- a/tests/robotests/src/com/android/phone/assisteddialing/CountryCodeProviderTest.java
+++ b/tests/robotests/src/com/android/phone/assisteddialing/CountryCodeProviderTest.java
@@ -21,11 +21,13 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
/**
* Unit Tests for CountryCodeProvider.
*/
@RunWith(RobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
public class CountryCodeProviderTest {
private final CountryCodeProvider mCountryCodeProvider = new CountryCodeProvider();
@@ -36,4 +38,5 @@
assertThat(mCountryCodeProvider.isSupportedCountryCode(country)).isTrue();
}
}
+
}
diff --git a/tests/robotests/src/com/android/phone/assisteddialing/LocationDetectorTest.java b/tests/robotests/src/com/android/phone/assisteddialing/LocationDetectorTest.java
index 70dc5b0..4b19f71 100755
--- a/tests/robotests/src/com/android/phone/assisteddialing/LocationDetectorTest.java
+++ b/tests/robotests/src/com/android/phone/assisteddialing/LocationDetectorTest.java
@@ -16,15 +16,16 @@
package com.android.phone.assisteddialing;
-import static com.google.common.truth.Truth.assertThat;
-
import android.content.Context;
import android.telephony.TelephonyManager;
+import static com.google.common.truth.Truth.assertThat;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowTelephonyManager;
@@ -35,6 +36,10 @@
* Unit Tests for LocationDetector.
*/
@RunWith(RobolectricTestRunner.class)
+@Config(
+ manifest = Config.NONE,
+ shadows = {ShadowTelephonyManager.class}
+)
public class LocationDetectorTest {
private final TelephonyManager mTelephonyManager =