From 6a78b32878aea1b0dac98ff36378fb9392d4aeb1 Mon Sep 17 00:00:00 2001 From: Joshua Selbo Date: Tue, 26 May 2020 20:36:38 -0700 Subject: [PATCH] Migrate react-native Android tests to Robolectric v4 (#28927) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/28927 Changelog: [Android] [Changed] Test Modernization Reviewed By: mdvacca Differential Revision: D21598788 fbshipit-source-id: 6fd9c30220d6d69cc68f13bf1f5ad5a4bc2b039a --- ReactAndroid/build.gradle | 2 +- ReactAndroid/gradle.properties | 6 +- .../src/test/java/com/facebook/powermock/BUCK | 166 +++++++------- .../main/third-party/android/androidx/BUCK | 20 ++ .../src/main/third-party/java/asm/BUCK | 20 +- .../src/main/third-party/java/mockito2/BUCK | 60 +++++ .../third-party/java/robolectric/4.3.1/BUCK | 216 ++++++++++++++++++ .../java/robolectric3/robolectric/BUCK | 180 --------------- .../src/test/java/com/facebook/react/BUCK | 3 - .../java/com/facebook/react/animated/BUCK | 3 - .../test/java/com/facebook/react/bridge/BUCK | 9 +- .../react/bridge/BaseJavaModuleTest.java | 11 +- .../java/com/facebook/react/devsupport/BUCK | 3 - .../JSDebuggerWebSocketClientTest.java | 9 +- .../test/java/com/facebook/react/modules/BUCK | 3 - .../modules/dialog/DialogModuleTest.java | 2 +- .../modules/network/NetworkingModuleTest.java | 10 +- .../network/ReactCookieJarContainerTest.java | 12 +- .../react/modules/share/ShareModuleTest.java | 27 ++- .../storage/AsyncStorageModuleTest.java | 2 +- .../facebook/react/packagerconnection/BUCK | 3 - .../java/com/facebook/react/uimanager/BUCK | 3 - .../react/uimanager/layoutanimation/BUCK | 1 - .../test/java/com/facebook/react/util/BUCK | 3 - .../test/java/com/facebook/react/views/BUCK | 3 - .../test/java/org/mockito/configuration/BUCK | 4 +- tools/build_defs/oss/rn_defs.bzl | 13 +- 27 files changed, 460 insertions(+), 334 deletions(-) create mode 100644 ReactAndroid/src/main/third-party/java/mockito2/BUCK create mode 100644 ReactAndroid/src/main/third-party/java/robolectric/4.3.1/BUCK delete mode 100644 ReactAndroid/src/main/third-party/java/robolectric3/robolectric/BUCK diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index c28a02dba7da41..23d9fd5912bc9a 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -454,7 +454,7 @@ dependencies { extractJNI("com.facebook.fbjni:fbjni:0.0.2") testImplementation("junit:junit:${JUNIT_VERSION}") - testImplementation("org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}") + testImplementation("org.powermock:powermock-api-mockito2:${POWERMOCK_VERSION}") testImplementation("org.powermock:powermock-module-junit4-rule:${POWERMOCK_VERSION}") testImplementation("org.powermock:powermock-classloading-xstream:${POWERMOCK_VERSION}") testImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}") diff --git a/ReactAndroid/gradle.properties b/ReactAndroid/gradle.properties index 1d065d7d581765..e3e6285dcce59e 100644 --- a/ReactAndroid/gradle.properties +++ b/ReactAndroid/gradle.properties @@ -5,9 +5,9 @@ POM_NAME=ReactNative POM_ARTIFACT_ID=react-native POM_PACKAGING=aar -MOCKITO_CORE_VERSION=2.19.1 -POWERMOCK_VERSION=1.6.2 -ROBOLECTRIC_VERSION=3.0 +MOCKITO_CORE_VERSION=2.26.0 +POWERMOCK_VERSION=2.0.2 +ROBOLECTRIC_VERSION=4.3.1 JUNIT_VERSION=4.12 FEST_ASSERT_CORE_VERSION=2.0M10 diff --git a/ReactAndroid/src/main/libraries/fbcore/src/test/java/com/facebook/powermock/BUCK b/ReactAndroid/src/main/libraries/fbcore/src/test/java/com/facebook/powermock/BUCK index 1473f92d1099f4..2a86bc6af780b5 100644 --- a/ReactAndroid/src/main/libraries/fbcore/src/test/java/com/facebook/powermock/BUCK +++ b/ReactAndroid/src/main/libraries/fbcore/src/test/java/com/facebook/powermock/BUCK @@ -2,164 +2,174 @@ load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library", "rn_prebuilt_jar") rn_android_library( - name = "powermock", - visibility = ["//ReactAndroid/..."], + name = "powermock2", + visibility = ["PUBLIC"], exported_deps = [ - ":javassist", - ":mockito-all", - ":powermock-api-mockito", + ":javassist-prebuilt", + ":powermock-api-mockito2", ":powermock-api-support", ":powermock-classloading-base", - ":powermock-classloading-xstream", + ":powermock-classloading-xstream-prebuilt", ":powermock-core", - ":powermock-module-junit4-rule", + ":powermock-module-junit-common-prebuilt", + ":powermock-module-junit-rule-prebuilt", ":powermock-reflect", - ":xmlpull", - ":xpp3", - ":xstream", + ":xstream-prebuilt", + ], +) + +rn_android_library( + name = "powermock-reflect", + visibility = ["PUBLIC"], + exported_deps = [ + ":byte-buddy", + ":objenesis", + ":powermock-reflect-prebuilt", ], ) rn_prebuilt_jar( - name = "powermock-core", - binary_jar = ":download-powermock-core.jar", + name = "byte-buddy", + binary_jar = ":byte-buddy-binary.jar", visibility = ["//ReactAndroid/..."], ) fb_native.remote_file( - name = "download-powermock-core.jar", - sha1 = "ea04e79244e19dcf0c3ccf6863c5b028b4b58c9c", - url = "mvn:org.powermock:powermock-core:jar:1.6.2", + name = "byte-buddy-binary.jar", + sha1 = "211a2b4d3df1eeef2a6cacf78d74a1f725e7a840", + url = "mvn:net.bytebuddy:byte-buddy:jar:1.9.10", ) rn_prebuilt_jar( - name = "powermock-api-mockito", - binary_jar = ":download-powermock-api-mockito.jar", + name = "byte-buddy-agent", + binary_jar = ":byte-buddy-agent-binary.jar", visibility = ["//ReactAndroid/..."], ) fb_native.remote_file( - name = "download-powermock-api-mockito.jar", - sha1 = "c213230ae20a7b422f3d622a261d0e3427d2464c", - url = "mvn:org.powermock:powermock-api-mockito:jar:1.6.2", + name = "byte-buddy-agent-binary.jar", + sha1 = "9674aba5ee793e54b864952b001166848da0f26b", + url = "mvn:net.bytebuddy:byte-buddy-agent:jar:1.9.10", ) rn_prebuilt_jar( - name = "powermock-api-support", - binary_jar = ":download-powermock-api-support.jar", + name = "objenesis", + binary_jar = ":objenesis-binary.jar", visibility = ["//ReactAndroid/..."], ) fb_native.remote_file( - name = "download-powermock-api-support.jar", - sha1 = "93b21413b4ee99b7bc0dd34e1416fdca96866aaf", - url = "mvn:org.powermock:powermock-api-support:jar:1.6.2", + name = "objenesis-binary.jar", + sha1 = "639033469776fd37c08358c6b92a4761feb2af4b", + url = "mvn:org.objenesis:objenesis:jar:2.6", ) rn_prebuilt_jar( - name = "powermock-module-junit4-rule", - binary_jar = ":download-powermock-module-junit4-rule.jar", - visibility = ["//ReactAndroid/..."], + name = "powermock-reflect-prebuilt", + binary_jar = ":powermock-reflect.jar", ) fb_native.remote_file( - name = "download-powermock-module-junit4-rule.jar", - sha1 = "4847638c5729b9f203e21144b0bdb5d34d888473", - url = "mvn:org.powermock:powermock-module-junit4-rule:jar:1.6.2", + name = "powermock-reflect.jar", + sha1 = "9a8b85397c5a72923962ee9e6bf774e8458803bb", + url = "mvn:org.powermock:powermock-reflect:jar:2.0.7", ) rn_prebuilt_jar( - name = "powermock-classloading-xstream", - binary_jar = ":download-powermock-classloading-xstream.jar", - visibility = ["//ReactAndroid/..."], + name = "powermock-api-mockito2", + binary_jar = ":powermock-api-mockito2.jar", ) fb_native.remote_file( - name = "download-powermock-classloading-xstream.jar", - sha1 = "3ced31cd7024fe365b9f3c8082d22c02434577da", - url = "mvn:org.powermock:powermock-classloading-xstream:jar:1.6.2", + name = "powermock-api-mockito2.jar", + sha1 = "9f40156d9f6f65c6459a65e34f3c7c4fef8b3c49", + url = "mvn:org.powermock:powermock-api-mockito2:jar:2.0.7", +) + +rn_prebuilt_jar( + name = "powermock-api-support", + binary_jar = ":powermock-api-support.jar", +) + +fb_native.remote_file( + name = "powermock-api-support.jar", + sha1 = "e311918de98f5d8b726031ca840664691599fd71", + url = "mvn:org.powermock:powermock-api-support:jar:2.0.7", ) rn_prebuilt_jar( name = "powermock-classloading-base", - binary_jar = ":download-powermock-classloading-base.jar", - visibility = ["//ReactAndroid/..."], + binary_jar = ":powermock-classloading-base.jar", ) fb_native.remote_file( - name = "download-powermock-classloading-base.jar", - sha1 = "c8bfc10731a02d3b241892cf2c334a754d473ca7", - url = "mvn:org.powermock:powermock-classloading-base:jar:1.6.2", + name = "powermock-classloading-base.jar", + sha1 = "58ae5d3087ddfee5a591131d337907401276f7d4", + url = "mvn:org.powermock:powermock-classloading-base:jar:2.0.7", ) rn_prebuilt_jar( - name = "xstream", - binary_jar = ":download-xstream.jar", - visibility = ["//ReactAndroid/..."], + name = "powermock-classloading-xstream-prebuilt", + binary_jar = ":powermock-classloading-xstream.jar", ) fb_native.remote_file( - name = "download-xstream.jar", - sha1 = "97e5013f391487cce4de6b0eebcde21549e91872", - url = "mvn:com.thoughtworks.xstream:xstream:jar:1.4.2", + name = "powermock-classloading-xstream.jar", + sha1 = "2ec4d94a584f12b0aa1165279e92ef3d5fda1b93", + url = "mvn:org.powermock:powermock-classloading-xstream:jar:2.0.7", ) rn_prebuilt_jar( - name = "powermock-reflect", - binary_jar = ":download-powermock-reflect.jar", - visibility = ["//ReactAndroid/..."], + name = "powermock-core", + binary_jar = ":powermock-core.jar", ) fb_native.remote_file( - name = "download-powermock-reflect.jar", - sha1 = "1af1bbd1207c3ecdcf64973e6f9d57dcd17cc145", - url = "mvn:org.powermock:powermock-reflect:jar:1.6.2", + name = "powermock-core.jar", + sha1 = "484c06b406c5a21a4a2ad39f6fe36a0f77834aa9", + url = "mvn:org.powermock:powermock-core:jar:2.0.7", ) rn_prebuilt_jar( - name = "javassist", - binary_jar = ":download-javassist.jar", - visibility = ["//ReactAndroid/..."], + name = "powermock-module-junit-common-prebuilt", + binary_jar = ":powermock-module-junit-common.jar", ) fb_native.remote_file( - name = "download-javassist.jar", - sha1 = "a9cbcdfb7e9f86fbc74d3afae65f2248bfbf82a0", - url = "mvn:org.javassist:javassist:jar:3.20.0-GA", + name = "powermock-module-junit-common.jar", + sha1 = "e890f92292aa525000a8fa95a8ca4015e3eb78b8", + url = "mvn:org.powermock:powermock-module-junit4-common:jar:2.0.7", ) rn_prebuilt_jar( - name = "mockito-all", - binary_jar = ":download-mockito-all.jar", - visibility = ["//ReactAndroid/..."], + name = "powermock-module-junit-rule-prebuilt", + binary_jar = ":powermock-module-junit-rule.jar", ) fb_native.remote_file( - name = "download-mockito-all.jar", - sha1 = "539df70269cc254a58cccc5d8e43286b4a73bf30", - url = "mvn:org.mockito:mockito-all:jar:1.10.19", + name = "powermock-module-junit-rule.jar", + sha1 = "d0d14709ffec2c3cbad0e3d6256bc8ace682398d", + url = "mvn:org.powermock:powermock-module-junit4-rule:jar:2.0.7", ) rn_prebuilt_jar( - name = "xmlpull", - binary_jar = ":download-xmlpull.jar", - visibility = ["//ReactAndroid/..."], + name = "javassist-prebuilt", + binary_jar = ":javassist.jar", ) fb_native.remote_file( - name = "download-xmlpull.jar", - sha1 = "2b8e230d2ab644e4ecaa94db7cdedbc40c805dfa", - url = "mvn:xmlpull:xmlpull:jar:1.1.3.1", + name = "javassist.jar", + sha1 = "f63e6aa899e15eca8fdaa402a79af4c417252213", + url = "mvn:org.javassist:javassist:jar:3.27.0-GA", ) rn_prebuilt_jar( - name = "xpp3", - binary_jar = ":download-xpp3.jar", - visibility = ["//ReactAndroid/..."], + name = "xstream-prebuilt", + binary_jar = ":xstream.jar", ) fb_native.remote_file( - name = "download-xpp3.jar", - sha1 = "19d4e90b43059058f6e056f794f0ea4030d60b86", - url = "mvn:xpp3:xpp3_min:jar:1.1.4c", + name = "xstream.jar", + sha1 = "6c120c45a8c480bb2fea5b56502e3993ddd74fd2", + url = "mvn:com.thoughtworks.xstream:xstream:jar:1.4.11.1", ) diff --git a/ReactAndroid/src/main/third-party/android/androidx/BUCK b/ReactAndroid/src/main/third-party/android/androidx/BUCK index 1f1d33cbc103e2..2eec208a3e473f 100644 --- a/ReactAndroid/src/main/third-party/android/androidx/BUCK +++ b/ReactAndroid/src/main/third-party/android/androidx/BUCK @@ -281,6 +281,15 @@ fb_native.android_library( ], ) +fb_native.android_library( + name = "test-monitor", + visibility = ["PUBLIC"], + exported_deps = [ + ":annotation", + ":test-monitor-binary", + ], +) + fb_native.android_library( name = "vectordrawable", visibility = ["PUBLIC"], @@ -448,6 +457,11 @@ fb_native.android_prebuilt_aar( aar = ":swiperefreshlayout-binary-aar", ) +fb_native.android_prebuilt_aar( + name = "test-monitor-binary", + aar = ":test-monitor-binary-aar", +) + fb_native.android_prebuilt_aar( name = "vectordrawable-binary", aar = ":vectordrawable-binary-aar", @@ -625,6 +639,12 @@ fb_native.remote_file( url = "mvn:androidx.swiperefreshlayout:swiperefreshlayout:aar:1.0.0", ) +fb_native.remote_file( + name = "test-monitor-binary-aar", + sha1 = "d2f75d117c055f35c8ebbd4f96fabc2137df9e4d", + url = "mvn:androidx.test:monitor:aar:1.2.0", +) + fb_native.remote_file( name = "vectordrawable-binary-aar", sha1 = "33d1eb71849dffbad12add134a25eb63cad4a1eb", diff --git a/ReactAndroid/src/main/third-party/java/asm/BUCK b/ReactAndroid/src/main/third-party/java/asm/BUCK index c56db5422144ea..f344506a49ca34 100644 --- a/ReactAndroid/src/main/third-party/java/asm/BUCK +++ b/ReactAndroid/src/main/third-party/java/asm/BUCK @@ -21,8 +21,8 @@ rn_prebuilt_jar( fb_native.remote_file( name = "download-asm.jar", - sha1 = "2fd56467a018aafe6ec6a73ccba520be4a7e1565", - url = "mvn:org.ow2.asm:asm:jar:5.0.1", + sha1 = "d74d4ba0dee443f68fb2dcb7fcdb945a2cd89912", + url = "mvn:org.ow2.asm:asm:jar:7.0", ) rn_prebuilt_jar( @@ -33,8 +33,8 @@ rn_prebuilt_jar( fb_native.remote_file( name = "download-asm-commons.jar", - sha1 = "7b7147a390a93a14d2edfdcf3f7b0e87a0939c3e", - url = "mvn:org.ow2.asm:asm-commons:jar:5.0.1", + sha1 = "478006d07b7c561ae3a92ddc1829bca81ae0cdd1", + url = "mvn:org.ow2.asm:asm-commons:jar:7.0", ) rn_prebuilt_jar( @@ -45,8 +45,8 @@ rn_prebuilt_jar( fb_native.remote_file( name = "download-asm-tree.jar", - sha1 = "1b1e6e9d869acd704056d0a4223071a511c619e6", - url = "mvn:org.ow2.asm:asm-tree:jar:5.0.1", + sha1 = "29bc62dcb85573af6e62e5b2d735ef65966c4180", + url = "mvn:org.ow2.asm:asm-tree:jar:7.0", ) rn_prebuilt_jar( @@ -57,8 +57,8 @@ rn_prebuilt_jar( fb_native.remote_file( name = "download-asm-util.jar", - sha1 = "7c8caddfbd0b2d7b844f8fcc75175b9cb9cf4724", - url = "mvn:org.ow2.asm:asm-util:jar:5.0.1", + sha1 = "18d4d07010c24405129a6dbb0e92057f8779fb9d", + url = "mvn:org.ow2.asm:asm-util:jar:7.0", ) rn_prebuilt_jar( @@ -69,6 +69,6 @@ rn_prebuilt_jar( fb_native.remote_file( name = "download-asm-analysis.jar", - sha1 = "e286fbee48efacb4e7c175f7948d9d8b2ab52352", - url = "mvn:org.ow2.asm:asm-analysis:jar:5.0.1", + sha1 = "4b310d20d6f1c6b7197a75f1b5d69f169bc8ac1f", + url = "mvn:org.ow2.asm:asm-analysis:jar:7.0", ) diff --git a/ReactAndroid/src/main/third-party/java/mockito2/BUCK b/ReactAndroid/src/main/third-party/java/mockito2/BUCK new file mode 100644 index 00000000000000..2427938b973112 --- /dev/null +++ b/ReactAndroid/src/main/third-party/java/mockito2/BUCK @@ -0,0 +1,60 @@ +load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") +load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library", "rn_prebuilt_jar") + +rn_android_library( + name = "mockito2", + visibility = ["PUBLIC"], + exported_deps = [ + ":byte-buddy", + ":byte-buddy-agent", + ":mockito-core-prebuilt", + ":objenesis", + ], +) + +rn_prebuilt_jar( + name = "mockito-core-prebuilt", + binary_jar = ":mockito-core.jar", +) + +fb_native.remote_file( + name = "mockito-core.jar", + sha1 = "17fb1bf75af4f5a18d8dec73b3aa55f18e6fa21a", + url = "mvn:org.mockito:mockito-core:jar:2.26.0", +) + +rn_prebuilt_jar( + name = "byte-buddy", + binary_jar = ":byte-buddy-binary.jar", + visibility = ["//ReactAndroid/..."], +) + +fb_native.remote_file( + name = "byte-buddy-binary.jar", + sha1 = "211a2b4d3df1eeef2a6cacf78d74a1f725e7a840", + url = "mvn:net.bytebuddy:byte-buddy:jar:1.9.10", +) + +rn_prebuilt_jar( + name = "byte-buddy-agent", + binary_jar = ":byte-buddy-agent-binary.jar", + visibility = ["//ReactAndroid/..."], +) + +fb_native.remote_file( + name = "byte-buddy-agent-binary.jar", + sha1 = "9674aba5ee793e54b864952b001166848da0f26b", + url = "mvn:net.bytebuddy:byte-buddy-agent:jar:1.9.10", +) + +rn_prebuilt_jar( + name = "objenesis", + binary_jar = ":objenesis-binary.jar", + visibility = ["//ReactAndroid/..."], +) + +fb_native.remote_file( + name = "objenesis-binary.jar", + sha1 = "639033469776fd37c08358c6b92a4761feb2af4b", + url = "mvn:org.objenesis:objenesis:jar:2.6", +) diff --git a/ReactAndroid/src/main/third-party/java/robolectric/4.3.1/BUCK b/ReactAndroid/src/main/third-party/java/robolectric/4.3.1/BUCK new file mode 100644 index 00000000000000..aeca8ed4f5bd3a --- /dev/null +++ b/ReactAndroid/src/main/third-party/java/robolectric/4.3.1/BUCK @@ -0,0 +1,216 @@ +load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library", "rn_prebuilt_jar") + +rn_android_library( + name = "robolectric", + visibility = ["PUBLIC"], + exported_deps = [ + ":android-all-4.1.2_r1-robolectric-r1", + ":bouncycastle", + ":guava", + ":javax-annotation-api", + ":javax-inject", + ":robolectric4-annotations-prebuilt", + ":robolectric4-junit-prebuilt", + ":robolectric4-pluginapi-prebuilt", + ":robolectric4-plugins-maven-dependency-resolver-prebuilt", + ":robolectric4-prebuilt", + ":robolectric4-resources-prebuilt", + ":robolectric4-sandbox-prebuilt", + ":robolectric4-shadowapi-prebuilt", + ":robolectric4-shadows-framework-prebuilt", + ":robolectric4-utils-prebuilt", + ":robolectric4-utils-reflector-prebuilt", + react_native_dep("third-party/java/asm:asm"), + react_native_dep("third-party/java/sqlite:sqlite"), + react_native_dep("third-party/java/junit:junit"), + react_native_dep("third-party/android/androidx:test-monitor"), + ], +) + +rn_prebuilt_jar( + name = "android-all-4.1.2_r1-robolectric-r1", # name defines filename used by robolectric in runtime + binary_jar = ":robolectric-android-all-binary.jar", + visibility = ["//ReactAndroid/..."], +) + +# This new rule will make the .jar file appear in the "right" location, +# though that may change in the future +fb_native.export_file( + name = "robolectric-android-all-binary.jar", + src = ":robolectric-android-all-binary-remote.jar", + out = "../android-all-4.1.2_r1-robolectric-r1.jar", # name defines filename used by robolectric in runtime +) + +fb_native.remote_file( + name = "robolectric-android-all-binary-remote.jar", + sha1 = "8355a2da59fe0233ca45070ca32f08da98d0b806", + url = "mvn:org.robolectric:android-all:jar:4.1.2_r1-robolectric-r1", +) + +rn_prebuilt_jar( + name = "bouncycastle", + binary_jar = ":bouncycastle-binary.jar", + visibility = ["//ReactAndroid/..."], +) + +fb_native.remote_file( + name = "bouncycastle-binary.jar", + sha1 = "2507204241ab450456bdb8e8c0a8f986e418bd99", + url = "mvn:org.bouncycastle:bcprov-jdk15on:jar:1.59", +) + +rn_prebuilt_jar( + name = "guava", + binary_jar = ":guava-binary.jar", + visibility = ["//ReactAndroid/..."], +) + +fb_native.remote_file( + name = "guava-binary.jar", + sha1 = "ef69663836b339db335fde0df06fb3cd84e3742b", + url = "mvn:com.google.guava:guava:jar:26.0-android", +) + +rn_prebuilt_jar( + name = "robolectric4-prebuilt", + binary_jar = ":robolectric4.jar", +) + +fb_native.remote_file( + name = "robolectric4.jar", + sha1 = "66e4550b96285eadcb5a45a21ad6fbe8842fa960", + url = "mvn:org.robolectric:robolectric:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-annotations-prebuilt", + binary_jar = ":robolectric4-annotations.jar", +) + +fb_native.remote_file( + name = "robolectric4-annotations.jar", + sha1 = "3db63d633be908a18db18615b594f824c034ae6d", + url = "mvn:org.robolectric:annotations:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-junit-prebuilt", + binary_jar = ":robolectric4-junit.jar", +) + +fb_native.remote_file( + name = "robolectric4-junit.jar", + sha1 = "fcafc9942e8748c8bab832b022672ca21808c492", + url = "mvn:org.robolectric:junit:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-pluginapi-prebuilt", + binary_jar = ":robolectric4-pluginapi.jar", +) + +fb_native.remote_file( + name = "robolectric4-pluginapi.jar", + sha1 = "128acea3aed3bbe36f8fde865f3a26b920237718", + url = "mvn:org.robolectric:pluginapi:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-plugins-maven-dependency-resolver-prebuilt", + binary_jar = ":robolectric4-plugins-maven-dependency-resolver.jar", +) + +fb_native.remote_file( + name = "robolectric4-plugins-maven-dependency-resolver.jar", + sha1 = "b1ea126cb80dbba0c2947be9234bbe2877ce2a09", + url = "mvn:org.robolectric:plugins-maven-dependency-resolver:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-resources-prebuilt", + binary_jar = ":robolectric4-resources.jar", +) + +fb_native.remote_file( + name = "robolectric4-resources.jar", + sha1 = "e40030b0f6808ca378bd2c803713157ee4287ea0", + url = "mvn:org.robolectric:resources:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-sandbox-prebuilt", + binary_jar = ":robolectric4-sandbox.jar", +) + +fb_native.remote_file( + name = "robolectric4-sandbox.jar", + sha1 = "2302e406aebab5f6843dbf6c2f21952fa86ec26f", + url = "mvn:org.robolectric:sandbox:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-shadowapi-prebuilt", + binary_jar = ":robolectric4-shadowapi.jar", +) + +fb_native.remote_file( + name = "robolectric4-shadowapi.jar", + sha1 = "81dfcf4a45b623b7744e46358d01c7ce054d0fff", + url = "mvn:org.robolectric:shadowapi:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-shadows-framework-prebuilt", + binary_jar = ":robolectric4-shadows-framework.jar", +) + +fb_native.remote_file( + name = "robolectric4-shadows-framework.jar", + sha1 = "150103d5732c432906f6130b734e7452855dd67b", + url = "mvn:org.robolectric:shadows-framework:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-utils-prebuilt", + binary_jar = ":robolectric4-utils.jar", +) + +fb_native.remote_file( + name = "robolectric4-utils.jar", + sha1 = "97b0331b67d0e1dc8bf50e570b6feb017f62aed1", + url = "mvn:org.robolectric:utils:jar:4.3", +) + +rn_prebuilt_jar( + name = "robolectric4-utils-reflector-prebuilt", + binary_jar = ":robolectric4-utils-reflector.jar", +) + +fb_native.remote_file( + name = "robolectric4-utils-reflector.jar", + sha1 = "3428887d068b66e33026ac533ae4647355167658", + url = "mvn:org.robolectric:utils-reflector:jar:4.3", +) + +rn_prebuilt_jar( + name = "javax-annotation-api", + binary_jar = ":javax-annotation-api.jar", +) + +fb_native.remote_file( + name = "javax-annotation-api.jar", + sha1 = "934c04d3cfef185a8008e7bf34331b79730a9d43", + url = "mvn:javax.annotation:javax.annotation-api:jar:1.3.2", +) + +rn_prebuilt_jar( + name = "javax-inject", + binary_jar = ":javax-inject.jar", +) + +fb_native.remote_file( + name = "javax-inject.jar", + sha1 = "6975da39a7040257bd51d21a231b76c915872d38", + url = "mvn:javax.inject:javax.inject:jar:1", +) diff --git a/ReactAndroid/src/main/third-party/java/robolectric3/robolectric/BUCK b/ReactAndroid/src/main/third-party/java/robolectric3/robolectric/BUCK deleted file mode 100644 index 3e35f4a81a788c..00000000000000 --- a/ReactAndroid/src/main/third-party/java/robolectric3/robolectric/BUCK +++ /dev/null @@ -1,180 +0,0 @@ -load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library", "rn_prebuilt_jar") - -rn_android_library( - name = "robolectric", - visibility = ["//ReactAndroid/..."], - exported_deps = [ - ":android-all-4.1.2_r1-robolectric-0", - ":bouncycastle", - ":icu", - ":json-20080701", - ":robolectric-annotations", - ":robolectric-core", - ":robolectric-resources", - ":robolectric-utils", - ":shadows-core-3.0-16", - ":tagsoup-1.2", - ":vtd-xml", - react_native_dep("third-party/java/asm:asm"), - react_native_dep("third-party/java/sqlite:sqlite"), - ], -) - -rn_prebuilt_jar( - name = "robolectric-core", - binary_jar = ":robolectric-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "robolectric-binary.jar", - sha1 = "f888cea3bc1a24110e315eb9827ab593610ea62f", - url = "mvn:org.robolectric:robolectric:jar:3.0", -) - -rn_prebuilt_jar( - name = "robolectric-resources", - binary_jar = ":robolectric-resources-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "robolectric-resources-binary.jar", - sha1 = "1ab609054aab67cd13a434567467f4b4774f2465", - url = "mvn:org.robolectric:robolectric-resources:jar:3.0", -) - -rn_prebuilt_jar( - name = "robolectric-annotations", - binary_jar = ":robolectric-annotations-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "robolectric-annotations-binary.jar", - sha1 = "2a6cfc072d7680694c1ff893c5dc8fec33163110", - url = "mvn:org.robolectric:robolectric-annotations:jar:3.0", -) - -rn_prebuilt_jar( - name = "robolectric-utils", - binary_jar = ":robolectric-utils-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "robolectric-utils-binary.jar", - sha1 = "4bcecd8115fe7296088bb1636e6cbd7ae8927392", - url = "mvn:org.robolectric:robolectric-utils:jar:3.0", -) - -rn_prebuilt_jar( - name = "bouncycastle", - binary_jar = ":bouncycastle-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "bouncycastle-binary.jar", - sha1 = "2507204241ab450456bdb8e8c0a8f986e418bd99", - url = "mvn:org.bouncycastle:bcprov-jdk15on:jar:1.59", -) - -rn_prebuilt_jar( - name = "vtd-xml", - binary_jar = ":vtd-xml-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "vtd-xml-binary.jar", - sha1 = "ee5bcf62c1acf76434ee9f1c67a840bafef72a6d", - url = "mvn:com.ximpleware:vtd-xml:jar:2.11", -) - -rn_prebuilt_jar( - name = "icu", - binary_jar = ":icu-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.remote_file( - name = "icu-binary.jar", - sha1 = "786d9055d4ca8c1aab4a7d4ac8283f973fd7e41f", - url = "mvn:com.ibm.icu:icu4j:jar:53.1", -) - -rn_prebuilt_jar( - name = "android-all-4.1.2_r1-robolectric-0", # name defines filename used by robolectric in runtime - binary_jar = ":robolectric-android-all-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -# This new rule will make the .jar file appear in the "right" location, -# though that may change in the future -fb_native.export_file( - name = "robolectric-android-all-binary.jar", - src = ":robolectric-android-all-binary-remote.jar", - out = "../android-all-4.1.2_r1-robolectric-0.jar", # name defines filename used by robolectric in runtime -) - -fb_native.remote_file( - name = "robolectric-android-all-binary-remote.jar", - sha1 = "aecc8ce5119a25fcea1cdf8285469c9d1261a352", - url = "mvn:org.robolectric:android-all:jar:4.1.2_r1-robolectric-0", -) - -rn_prebuilt_jar( - name = "json-20080701", # name defines filename used by robolectric in runtime - binary_jar = ":json.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.export_file( - name = "json.jar", - src = ":json-remote.jar", - out = "../json-20080701.jar", # name defines filename used by robolectric in runtime -) - -fb_native.remote_file( - name = "json-remote.jar", - sha1 = "d652f102185530c93b66158b1859f35d45687258", - url = "mvn:org.json:json:jar:20080701", -) - -rn_prebuilt_jar( - name = "tagsoup-1.2", # name defines filename used by robolectric in runtime - binary_jar = ":tagsoup.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.export_file( - name = "tagsoup.jar", - src = ":tagsoup-remote.jar", - out = "../tagsoup-1.2.jar", # name defines filename used by robolectric in runtime -) - -fb_native.remote_file( - name = "tagsoup-remote.jar", - sha1 = "639fd364750d7363c85797dc944b4a80f78fa684", - url = "mvn:org.ccil.cowan.tagsoup:tagsoup:jar:1.2", -) - -rn_prebuilt_jar( - name = "shadows-core-3.0-16", # name defines filename used by robolectric in runtime - binary_jar = ":robolectric-shadows-binary.jar", - visibility = ["//ReactAndroid/..."], -) - -fb_native.export_file( - name = "robolectric-shadows-binary.jar", - src = ":robolectric-shadows-binary-remote.jar", - out = "../shadows-core-3.0-16.jar", # name defines filename used by robolectric in runtime -) - -fb_native.remote_file( - name = "robolectric-shadows-binary-remote.jar", - sha1 = "39d7a856bf91640b1a6d044333336a2b3f3c198f", - url = "https://repo1.maven.org/maven2/org/robolectric/shadows-core/3.0/shadows-core-3.0-16.jar", -) diff --git a/ReactAndroid/src/test/java/com/facebook/react/BUCK b/ReactAndroid/src/test/java/com/facebook/react/BUCK index 3b431158943706..036fe8a98d8bfb 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/BUCK @@ -6,7 +6,6 @@ rn_robolectric_test( contacts = ["oncall+react_native@xmail.facebook.com"], deps = [ YOGA_TARGET, - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/android/androidx:annotation"), react_native_dep("third-party/android/androidx:core"), react_native_dep("third-party/android/androidx:fragment"), @@ -15,10 +14,8 @@ rn_robolectric_test( react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), react_native_dep("third-party/java/okio:okio"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/animated/BUCK b/ReactAndroid/src/test/java/com/facebook/react/animated/BUCK index 76d35a6ce1c914..c62728d5814eb9 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/animated/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/animated/BUCK @@ -9,12 +9,9 @@ rn_robolectric_test( "PUBLIC", ], deps = [ - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react/animated:animated"), react_native_target("java/com/facebook/react/bridge:bridge"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/bridge/BUCK b/ReactAndroid/src/test/java/com/facebook/react/bridge/BUCK index 1f5f367286672e..2721f9cb923f4a 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/bridge/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/bridge/BUCK @@ -1,4 +1,4 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "react_native_tests_target", "rn_android_library", "rn_robolectric_test") +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_android_toplevel_dep", "react_native_dep", "react_native_target", "react_native_tests_target", "rn_android_library", "rn_robolectric_test") STANDARD_TEST_SRCS = [ "*Test.java", @@ -14,8 +14,8 @@ rn_android_library( "PUBLIC", ], deps = [ - react_native_dep("third-party/java/mockito:mockito"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), + react_native_android_toplevel_dep("third-party/java/mockito2:mockito2"), + react_native_dep("third-party/java/robolectric/4.3.1:robolectric"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_tests_target("java/org/mockito/configuration:configuration"), @@ -31,13 +31,10 @@ rn_robolectric_test( ], deps = [ ":testhelpers", - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/uimanager:uimanager"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/bridge/BaseJavaModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/bridge/BaseJavaModuleTest.java index 77a46c9fee4d63..d5b89b2465147c 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/bridge/BaseJavaModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/bridge/BaseJavaModuleTest.java @@ -7,13 +7,14 @@ package com.facebook.react.bridge; +import static org.mockito.Mockito.when; + import com.facebook.soloader.SoLoader; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -56,14 +57,14 @@ private int findMethod(String mname, List me @Test(expected = NativeArgumentsParseException.class) public void testCallMethodWithoutEnoughArgs() throws Exception { int methodId = findMethod("regularMethod", mMethods); - Mockito.stub(mArguments.size()).toReturn(1); + when(mArguments.size()).thenReturn(1); mWrapper.invoke(methodId, mArguments); } @Test public void testCallMethodWithEnoughArgs() { int methodId = findMethod("regularMethod", mMethods); - Mockito.stub(mArguments.size()).toReturn(2); + when(mArguments.size()).thenReturn(2); mWrapper.invoke(methodId, mArguments); } @@ -71,14 +72,14 @@ public void testCallMethodWithEnoughArgs() { public void testCallAsyncMethodWithEnoughArgs() { // Promise block evaluates to 2 args needing to be passed from JS int methodId = findMethod("asyncMethod", mMethods); - Mockito.stub(mArguments.size()).toReturn(3); + when(mArguments.size()).thenReturn(3); mWrapper.invoke(methodId, mArguments); } @Test public void testCallSyncMethod() { int methodId = findMethod("syncMethod", mMethods); - Mockito.stub(mArguments.size()).toReturn(2); + when(mArguments.size()).thenReturn(2); mWrapper.invoke(methodId, mArguments); } diff --git a/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK b/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK index 2bf74a64315a33..f720bc4aaf3f4b 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/devsupport/BUCK @@ -9,14 +9,11 @@ rn_robolectric_test( "PUBLIC", ], deps = [ - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), react_native_dep("third-party/java/okio:okio"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java b/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java index 0c6bbde0e8bdd0..f155eebbddd312 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/devsupport/JSDebuggerWebSocketClientTest.java @@ -76,7 +76,7 @@ public void test_onMessage_WithInvalidContentType_ShouldNotTriggerCallbacks() th client.onMessage(null, ByteString.encodeUtf8("{\"replyID\":0, \"result\":\"OK\"}")); PowerMockito.verifyPrivate(client, never()) - .invoke("triggerRequestSuccess", anyInt(), anyString()); + .invoke("triggerRequestSuccess", anyInt(), nullable(String.class)); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -86,7 +86,7 @@ public void test_onMessage_WithoutReplyId_ShouldNotTriggerCallbacks() throws Exc client.onMessage(null, "{\"result\":\"OK\"}"); PowerMockito.verifyPrivate(client, never()) - .invoke("triggerRequestSuccess", anyInt(), anyString()); + .invoke("triggerRequestSuccess", anyInt(), nullable(String.class)); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -96,7 +96,7 @@ public void test_onMessage_With_Null_ReplyId_ShouldNotTriggerCallbacks() throws client.onMessage(null, "{\"replyID\":null, \"result\":\"OK\"}"); PowerMockito.verifyPrivate(client, never()) - .invoke("triggerRequestSuccess", anyInt(), anyString()); + .invoke("triggerRequestSuccess", anyInt(), nullable(String.class)); PowerMockito.verifyPrivate(client, never()).invoke("triggerRequestFailure", anyInt(), any()); } @@ -131,6 +131,7 @@ public void test_onMessage_With_Null_Error_ShouldTriggerRequestSuccess() throws JSDebuggerWebSocketClient client = PowerMockito.spy(new JSDebuggerWebSocketClient()); client.onMessage(null, "{\"replyID\":0, \"error\":null}"); - PowerMockito.verifyPrivate(client).invoke("triggerRequestSuccess", anyInt(), anyString()); + PowerMockito.verifyPrivate(client) + .invoke("triggerRequestSuccess", anyInt(), nullable(String.class)); } } diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/BUCK b/ReactAndroid/src/test/java/com/facebook/react/modules/BUCK index 3b5337ebbb64f2..750600054fbf23 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/BUCK @@ -9,7 +9,6 @@ rn_robolectric_test( ], deps = [ YOGA_TARGET, - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/android/androidx:annotation"), react_native_dep("third-party/android/androidx:core"), react_native_dep("third-party/android/androidx:fragment"), @@ -18,10 +17,8 @@ rn_robolectric_test( react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), react_native_dep("third-party/java/okio:okio"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/dialog/DialogModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/modules/dialog/DialogModuleTest.java index b46488d299d486..619b464d1d7c0b 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/dialog/DialogModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/dialog/DialogModuleTest.java @@ -25,7 +25,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; -import org.robolectric.util.ActivityController; +import org.robolectric.android.controller.ActivityController; @RunWith(RobolectricTestRunner.class) @PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"}) diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java index 36104c1e285e87..a6e401ed9b0c8c 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java @@ -518,9 +518,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { /* withCredentials */ false); // verify RequestBodyPart for image - PowerMockito.verifyStatic(times(1)); + PowerMockito.verifyStatic(RequestBodyUtil.class, times(1)); RequestBodyUtil.getFileInputStream(any(ReactContext.class), eq("imageUri")); - PowerMockito.verifyStatic(times(1)); + PowerMockito.verifyStatic(RequestBodyUtil.class, times(1)); RequestBodyUtil.create(MediaType.parse("image/jpg"), inputStream); // verify body @@ -579,7 +579,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { verify(mHttpClient, times(3)).newCall(any(Request.class)); mNetworkingModule.onCatalystInstanceDestroy(); - PowerMockito.verifyStatic(times(3)); + PowerMockito.verifyStatic(OkHttpCallUtil.class, times(3)); ArgumentCaptor clientArguments = ArgumentCaptor.forClass(OkHttpClient.class); ArgumentCaptor requestIdArguments = ArgumentCaptor.forClass(Integer.class); OkHttpCallUtil.cancelTag(clientArguments.capture(), requestIdArguments.capture()); @@ -624,7 +624,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { verify(mHttpClient, times(3)).newCall(any(Request.class)); mNetworkingModule.abortRequest(requests); - PowerMockito.verifyStatic(times(1)); + PowerMockito.verifyStatic(OkHttpCallUtil.class, times(1)); ArgumentCaptor clientArguments = ArgumentCaptor.forClass(OkHttpClient.class); ArgumentCaptor requestIdArguments = ArgumentCaptor.forClass(Integer.class); OkHttpCallUtil.cancelTag(clientArguments.capture(), requestIdArguments.capture()); @@ -635,7 +635,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { // If `cancelTag` would've been called again for the aborted call, we would have had // `requests + 1` calls. mNetworkingModule.onCatalystInstanceDestroy(); - PowerMockito.verifyStatic(times(requests)); + PowerMockito.verifyStatic(OkHttpCallUtil.class, times(requests)); clientArguments = ArgumentCaptor.forClass(OkHttpClient.class); requestIdArguments = ArgumentCaptor.forClass(Integer.class); OkHttpCallUtil.cancelTag(clientArguments.capture(), requestIdArguments.capture()); diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/network/ReactCookieJarContainerTest.java b/ReactAndroid/src/test/java/com/facebook/react/modules/network/ReactCookieJarContainerTest.java index 97f3a48171c891..ef21b78fe94019 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/network/ReactCookieJarContainerTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/network/ReactCookieJarContainerTest.java @@ -32,7 +32,8 @@ public class ReactCookieJarContainerTest { @Test public void testMissingJar() throws Exception { ReactCookieJarContainer jarContainer = mock(ReactCookieJarContainer.class); - assertThat(jarContainer.loadForRequest(any(HttpUrl.class)).size()).isEqualTo(0); + assertThat(jarContainer.loadForRequest(HttpUrl.parse("http://example.com")).size()) + .isEqualTo(0); } @Test @@ -40,7 +41,8 @@ public void testEmptyCookies() throws Exception { ReactCookieJarContainer jarContainer = mock(ReactCookieJarContainer.class); List cookies = new ArrayList<>(); when(jarContainer.loadForRequest(any(HttpUrl.class))).thenReturn(cookies); - assertThat(jarContainer.loadForRequest(any(HttpUrl.class)).size()).isEqualTo(0); + assertThat(jarContainer.loadForRequest(HttpUrl.parse("http://example.com")).size()) + .isEqualTo(0); } @Test @@ -51,7 +53,8 @@ public void testValidCookies() throws Exception { List cookies = new ArrayList<>(); cookies.add(new Cookie.Builder().name("valid").value("valid value").domain("domain").build()); when(cookieJar.loadForRequest(any(HttpUrl.class))).thenReturn(cookies); - assertThat(jarContainer.loadForRequest(any(HttpUrl.class)).size()).isEqualTo(1); + assertThat(jarContainer.loadForRequest(HttpUrl.parse("http://example.com")).size()) + .isEqualTo(1); } @Test @@ -62,6 +65,7 @@ public void testInvalidCookies() throws Exception { List cookies = new ArrayList<>(); cookies.add(new Cookie.Builder().name("valid").value("înválíd välūė").domain("domain").build()); when(cookieJar.loadForRequest(any(HttpUrl.class))).thenReturn(cookies); - assertThat(jarContainer.loadForRequest(any(HttpUrl.class)).size()).isEqualTo(0); + assertThat(jarContainer.loadForRequest(HttpUrl.parse("http://example.com")).size()) + .isEqualTo(0); } } diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.java index 75a2135c223e31..2260bc47dde664 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.java @@ -9,6 +9,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.robolectric.Shadows.shadowOf; import android.app.Activity; import android.content.Intent; @@ -17,6 +18,7 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.JavaOnlyMap; import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactTestHelper; import com.facebook.react.bridge.WritableMap; import org.junit.After; @@ -31,14 +33,23 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.rule.PowerMockRule; +import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; -import org.robolectric.internal.ShadowExtractor; -import org.robolectric.shadows.ShadowApplication; @PrepareForTest({Arguments.class}) @RunWith(RobolectricTestRunner.class) -@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"}) +@PowerMockIgnore({ + "org.mockito.*", + "org.robolectric.*", + "androidx.*", + "android.*", + "javax.xml.*", + "org.xml.sax.*", + "org.w3c.dom.*", + "org.springframework.context.*", + "org.apache.log4j.*" +}) public class ShareModuleTest { private Activity mActivity; @@ -58,7 +69,11 @@ public Object answer(InvocationOnMock invocation) throws Throwable { } }); - mShareModule = new ShareModule(ReactTestHelper.createCatalystContextForTest()); + mActivity = Robolectric.setupActivity(Activity.class); + + ReactApplicationContext applicationContext = ReactTestHelper.createCatalystContextForTest(); + applicationContext.onNewIntent(mActivity, new Intent()); + mShareModule = new ShareModule(applicationContext); } @After @@ -81,9 +96,7 @@ public void testShareDialog() { mShareModule.share(content, dialogTitle, promise); - final Intent chooserIntent = - ((ShadowApplication) ShadowExtractor.extract(RuntimeEnvironment.application)) - .getNextStartedActivity(); + final Intent chooserIntent = shadowOf(RuntimeEnvironment.application).getNextStartedActivity(); assertNotNull("Dialog was not displayed", chooserIntent); assertEquals(Intent.ACTION_CHOOSER, chooserIntent.getAction()); assertEquals(dialogTitle, chooserIntent.getExtras().get(Intent.EXTRA_TITLE)); diff --git a/ReactAndroid/src/test/java/com/facebook/react/modules/storage/AsyncStorageModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/modules/storage/AsyncStorageModuleTest.java index 45b3f1b0f36d1b..bc5d9bc332649d 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/modules/storage/AsyncStorageModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/modules/storage/AsyncStorageModuleTest.java @@ -36,7 +36,7 @@ import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; -import org.robolectric.util.concurrent.RoboExecutorService; +import org.robolectric.android.util.concurrent.RoboExecutorService; /** Tests for {@link com.facebook.react.modules.storage.AsyncStorageModule}. */ @PrepareForTest({Arguments.class}) diff --git a/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK b/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK index 18dec467c72f2c..f34e2c12e0e360 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/packagerconnection/BUCK @@ -9,14 +9,11 @@ rn_robolectric_test( "PUBLIC", ], deps = [ - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), react_native_dep("third-party/java/okio:okio"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react/packagerconnection:packagerconnection"), ], ) diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK b/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK index ad592a0dddf576..bc96fa72a28aa6 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK @@ -17,7 +17,6 @@ rn_robolectric_test( ], deps = [ YOGA_TARGET, - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/android/androidx:annotation"), react_native_dep("third-party/android/androidx:core"), react_native_dep("third-party/android/androidx:fragment"), @@ -26,10 +25,8 @@ rn_robolectric_test( react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), react_native_dep("third-party/java/okio:okio"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/BUCK b/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/BUCK index 6c791141d5435f..3124e8db34698e 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/BUCK @@ -11,7 +11,6 @@ rn_robolectric_test( YOGA_TARGET, react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react/uimanager:uimanager"), ], ) diff --git a/ReactAndroid/src/test/java/com/facebook/react/util/BUCK b/ReactAndroid/src/test/java/com/facebook/react/util/BUCK index 12a2a521fc5be3..853b0a8a2f90bb 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/util/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/util/BUCK @@ -7,12 +7,9 @@ rn_robolectric_test( "PUBLIC", ], deps = [ - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react/util:util"), react_native_target("java/com/facebook/react/bridge:bridge"), ], diff --git a/ReactAndroid/src/test/java/com/facebook/react/views/BUCK b/ReactAndroid/src/test/java/com/facebook/react/views/BUCK index 5b616f6630bdc9..058829726fbfa4 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/views/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/views/BUCK @@ -9,7 +9,6 @@ rn_robolectric_test( contacts = ["oncall+fbandroid_sheriff@xmail.facebook.com"], deps = [ YOGA_TARGET, - react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock"), react_native_dep("libraries/fresco/fresco-react-native:fresco-drawee"), react_native_dep("libraries/fresco/fresco-react-native:fresco-react-native"), react_native_dep("libraries/fresco/fresco-react-native:imagepipeline"), @@ -22,10 +21,8 @@ rn_robolectric_test( react_native_dep("third-party/java/fest:fest"), react_native_dep("third-party/java/jsr-305:jsr-305"), react_native_dep("third-party/java/junit:junit"), - react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/okhttp:okhttp3"), react_native_dep("third-party/java/okio:okio"), - react_native_dep("third-party/java/robolectric3/robolectric:robolectric"), react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/test/java/org/mockito/configuration/BUCK b/ReactAndroid/src/test/java/org/mockito/configuration/BUCK index 99bce2a385eb49..a29174b85a037e 100644 --- a/ReactAndroid/src/test/java/org/mockito/configuration/BUCK +++ b/ReactAndroid/src/test/java/org/mockito/configuration/BUCK @@ -1,4 +1,4 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library") +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_android_toplevel_dep", "rn_android_library") rn_android_library( name = "configuration", @@ -7,6 +7,6 @@ rn_android_library( "PUBLIC", ], deps = [ - react_native_dep("third-party/java/mockito:mockito"), + react_native_android_toplevel_dep("third-party/java/mockito2:mockito2"), ], ) diff --git a/tools/build_defs/oss/rn_defs.bzl b/tools/build_defs/oss/rn_defs.bzl index 698ce671363feb..887e25d3651577 100644 --- a/tools/build_defs/oss/rn_defs.bzl +++ b/tools/build_defs/oss/rn_defs.bzl @@ -87,6 +87,9 @@ def react_native_integration_tests_target(path): def react_native_dep(path): return "//ReactAndroid/src/main/" + path +def react_native_android_toplevel_dep(path): + return react_native_dep(path) + # Example: react_native_xplat_dep('java/com/facebook/systrace:systrace') def react_native_xplat_dep(path): return "//ReactCommon/" + path @@ -183,12 +186,18 @@ def rn_robolectric_test(name, srcs, vm_args = None, *args, **kwargs): is_androidx = kwargs.pop("is_androidx", False) + kwargs["deps"] = kwargs.pop("deps", []) + [ + react_native_android_toplevel_dep("third-party/java/mockito2:mockito2"), + react_native_dep("libraries/fbcore/src/test/java/com/facebook/powermock:powermock2"), + react_native_dep("third-party/java/robolectric/4.3.1:robolectric"), + ] + extra_vm_args = [ "-XX:+UseConcMarkSweepGC", # required by -XX:+CMSClassUnloadingEnabled "-XX:+CMSClassUnloadingEnabled", "-XX:ReservedCodeCacheSize=150M", - "-Drobolectric.dependency.dir=buck-out/gen/ReactAndroid/src/main/third-party/java/robolectric3/robolectric", - "-Dlibraries=buck-out/gen/ReactAndroid/src/main/third-party/java/robolectric3/robolectric/*.jar", + "-Drobolectric.dependency.dir=buck-out/gen/ReactAndroid/src/main/third-party/java/robolectric/4.3.1", + "-Dlibraries=buck-out/gen/ReactAndroid/src/main/third-party/java/robolectric/4.3.1/*.jar", "-Drobolectric.logging.enabled=true", "-XX:MaxPermSize=620m", "-Drobolectric.offline=true",