From e2d9ff8538c2bb39db498a6f39bcedeb3f983ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Daipr=C3=A9?= Date: Mon, 29 Jul 2024 06:52:38 -0700 Subject: [PATCH] feat: migrate ShareModuleTest to AssertJ (#45789) Summary: Issue: https://github.com/facebook/react-native/issues/45596 ## Changelog: [ANDROID] [CHANGED] - Migrated `ShareModuleTest` from junit.Assert to assertj.core.api.Assertions. Pull Request resolved: https://github.com/facebook/react-native/pull/45789 Test Plan: Run `./gradlew test` Reviewed By: sammy-SC Differential Revision: D60379426 Pulled By: cortinico fbshipit-source-id: b49fca7aafd42a4207c76d51641caaa2e2511dc3 --- .../react/modules/share/ShareModuleTest.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt index eb21c9b43c0..5ca2e9c406e 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/share/ShareModuleTest.kt @@ -14,8 +14,7 @@ import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactTestHelper import com.facebook.react.bridge.WritableMap import com.facebook.testutils.shadows.ShadowArguments -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull +import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -57,17 +56,18 @@ class ShareModuleTest { shareModule.share(content, dialogTitle, promise) val chooserIntent = shadowOf(RuntimeEnvironment.getApplication()).nextStartedActivity - assertNotNull("Dialog was not displayed", chooserIntent) - assertEquals(Intent.ACTION_CHOOSER, chooserIntent.action) - assertEquals(dialogTitle, chooserIntent.extras?.getString(Intent.EXTRA_TITLE)) + assertThat(chooserIntent).isNotNull() + assertThat(chooserIntent.action).isEqualTo(Intent.ACTION_CHOOSER) + assertThat(chooserIntent.extras?.getString(Intent.EXTRA_TITLE)).isEqualTo(dialogTitle) val contentIntent = chooserIntent.extras?.getParcelable(Intent.EXTRA_INTENT, Intent::class.java) - assertNotNull("Intent was not built correctly", contentIntent) - assertEquals(Intent.ACTION_SEND, contentIntent?.action) - assertEquals(title, contentIntent?.extras?.getString(Intent.EXTRA_SUBJECT)) - assertEquals(message, contentIntent?.extras?.getString(Intent.EXTRA_TEXT)) + assertThat(contentIntent).isNotNull() + assertThat(contentIntent?.action).isEqualTo(Intent.ACTION_SEND) - assertEquals(1, promise.resolved) + assertThat(contentIntent?.extras?.getString(Intent.EXTRA_SUBJECT)).isEqualTo(title) + assertThat(contentIntent?.extras?.getString(Intent.EXTRA_TEXT)).isEqualTo(message) + + assertThat(promise.resolved).isEqualTo(1) } @Test @@ -78,8 +78,8 @@ class ShareModuleTest { shareModule.share(null, dialogTitle, promise) - assertEquals(1, promise.rejected) - assertEquals(ShareModule.ERROR_INVALID_CONTENT, promise.errorCode) + assertThat(promise.rejected).isEqualTo(1) + assertThat(promise.errorCode).isEqualTo(ShareModule.ERROR_INVALID_CONTENT) } internal class SimplePromise : Promise {