Skip to content

Commit

Permalink
Convert the last Unit Tests to Kotlin (#42078)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42078

Resubmit of D51891716 and D52033328

I'm doing a pass and converting the last Java Unit Tests we had to Kotlin
I've also re-enabled multiple tests that were disabled in the past.

Changelog:
[Internal] [Changed] - Convert the last Unit Tests to Kotlin

Reviewed By: rshest

Differential Revision: D52430728

fbshipit-source-id: e6b4a6ed88d852024d959cf5148e992e97a84434
  • Loading branch information
cortinico authored and facebook-github-bot committed Dec 27, 2023
1 parent ac9b87c commit c75abef
Show file tree
Hide file tree
Showing 8 changed files with 505 additions and 535 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.runtime

import android.app.Activity
import android.content.Context
import com.facebook.react.bridge.JSIModuleType
import com.facebook.react.fabric.FabricUIManager
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.testutils.shadows.ShadowSoLoader
import org.assertj.core.api.Assertions
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import org.mockito.Mockito.doReturn
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

/** Tests [BridgelessReactContext] */
@RunWith(RobolectricTestRunner::class)
@Config(shadows = [ShadowSoLoader::class])
class BridgelessReactContextTest {
private lateinit var context: Context
private lateinit var reactHost: ReactHostImpl
private lateinit var bridgelessReactContext: BridgelessReactContext

@Before
fun setUp() {
context = Robolectric.buildActivity(Activity::class.java).create().get()
reactHost = Mockito.mock(ReactHostImpl::class.java)
bridgelessReactContext = BridgelessReactContext(context, reactHost)
}

@Test
fun getNativeModuleTest() {
val mUiManagerModule = Mockito.mock(UIManagerModule::class.java)
doReturn(mUiManagerModule)
.`when`(reactHost)
.getNativeModule(ArgumentMatchers.any<Class<UIManagerModule>>())
val uiManagerModule = bridgelessReactContext.getNativeModule(UIManagerModule::class.java)
Assertions.assertThat(uiManagerModule).isEqualTo(mUiManagerModule)
}

@Test(expected = UnsupportedOperationException::class)
fun getJSIModule_throwsException() {
bridgelessReactContext.getJSIModule(JSIModuleType.TurboModuleManager)
}

@Test
fun getJSIModuleTest() {
val fabricUiManager = Mockito.mock(FabricUIManager::class.java)
doReturn(fabricUiManager).`when`(reactHost).uiManager
Assertions.assertThat(bridgelessReactContext.getJSIModule(JSIModuleType.UIManager))
.isEqualTo(fabricUiManager)
}

@Test(expected = UnsupportedOperationException::class)
fun getCatalystInstance_throwsException() {
// Disable this test for now due to mocking FabricUIManager fails
bridgelessReactContext.catalystInstance
}
}

This file was deleted.

Loading

0 comments on commit c75abef

Please sign in to comment.