Skip to content

Commit

Permalink
Fix Android build warning
Browse files Browse the repository at this point in the history
Summary:
Fix Android build warning reporting usage of depreacted APIs: Robolectric.setupActivity() is deprecated in Android unit test

Following Google Android recommendations: https://developer.android.com/reference/androidx/test/core/app/ActivityScenario

changelog: [internal] internal

Reviewed By: cortinico

Differential Revision: D48168983

fbshipit-source-id: ac37235715578af6e28da2e219c6a942bfafca2a
  • Loading branch information
mdvacca authored and facebook-github-bot committed Aug 9, 2023
1 parent da6a7a0 commit 2013c2c
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

package com.facebook.react.modules.share

import android.app.Activity
import android.content.Intent
import androidx.fragment.app.FragmentActivity
import com.facebook.react.bridge.JavaOnlyMap
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactTestHelper
Expand All @@ -23,19 +23,20 @@ import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.android.controller.ActivityController
import org.robolectric.annotation.Config

@Config(shadows = [ShadowArguments::class])
@RunWith(RobolectricTestRunner::class)
class ShareModuleTest {

private lateinit var activity: Activity
private lateinit var shareModule: ShareModule
private lateinit var activityController: ActivityController<FragmentActivity>

@Before
fun prepareModules() {
activity = Robolectric.setupActivity(Activity::class.java)

activityController = Robolectric.buildActivity(FragmentActivity::class.java)
val activity = activityController.create().start().resume().get()
val applicationContext = ReactTestHelper.createCatalystContextForTest()
applicationContext.onNewIntent(activity, Intent())
shareModule = ShareModule(applicationContext)
Expand Down

0 comments on commit 2013c2c

Please sign in to comment.