diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/MountingManagerTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/MountingManagerTest.java deleted file mode 100644 index a66dca3ff86ca5..00000000000000 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/MountingManagerTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.fabric; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.facebook.react.ReactRootView; -import com.facebook.react.bridge.BridgeReactContext; -import com.facebook.react.bridge.ReactTestHelper; -import com.facebook.react.fabric.mounting.MountingManager; -import com.facebook.react.fabric.mounting.mountitems.MountItem; -import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests; -import com.facebook.react.uimanager.IllegalViewOperationException; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.ViewManager; -import com.facebook.react.uimanager.ViewManagerRegistry; -import com.facebook.react.views.view.ReactViewManager; -import java.util.Arrays; -import java.util.List; -import java.util.Queue; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -/** Tests {@link FabricUIManager} */ -@RunWith(RobolectricTestRunner.class) -public class MountingManagerTest { - - private MountingManager mMountingManager; - private MountingManager.MountItemExecutor mMountItemExecutor; - private ThemedReactContext mThemedReactContext; - private int mNextRootTag = 1; - - @Before - public void setUp() { - ReactNativeFeatureFlagsForTests.INSTANCE.setUp(); - - BridgeReactContext reactContext = new BridgeReactContext(RuntimeEnvironment.application); - reactContext.initializeWithInstance(ReactTestHelper.createMockCatalystInstance()); - mThemedReactContext = new ThemedReactContext(reactContext, reactContext); - List viewManagers = Arrays.asList(new ReactViewManager()); - mMountItemExecutor = - new MountingManager.MountItemExecutor() { - @Override - public void executeItems(Queue items) { - // no-op - } - }; - mMountingManager = - new MountingManager(new ViewManagerRegistry(viewManagers), mMountItemExecutor); - } - - @Test - public void addRootView() { - ReactRootView reactRootView = new ReactRootView(mThemedReactContext); - int rootReactTag = mNextRootTag++; - mMountingManager.startSurface(rootReactTag, mThemedReactContext, reactRootView); - assertThat(reactRootView.getId()).isEqualTo(rootReactTag); - } - - @Test - public void unableToAddRootViewTwice() { - ReactRootView reactRootView = new ReactRootView(mThemedReactContext); - int rootReactTag = mNextRootTag++; - mMountingManager.startSurface(rootReactTag, mThemedReactContext, reactRootView); - assertThat(reactRootView.getId()).isEqualTo(rootReactTag); - - // This is now a SoftException because it indicates a race condition in starting - // a single surface with a single View, and is concerning but not necessarily fatal. - // To be clear: in this case we're still guaranteed a single SurfaceMountingManager - // and therefore a single View involved. - mMountingManager.startSurface(rootReactTag, mThemedReactContext, reactRootView); - } - - @Test(expected = IllegalViewOperationException.class) - public void unableToAddHandledRootView() { - ReactRootView reactRootView = new ReactRootView(mThemedReactContext); - reactRootView.setId(1234567); - int rootReactTag = mNextRootTag++; - mMountingManager.startSurface(rootReactTag, mThemedReactContext, reactRootView); - } -} diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/MountingManagerTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/MountingManagerTest.kt new file mode 100644 index 00000000000000..bc67c9f96dd0db --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/MountingManagerTest.kt @@ -0,0 +1,78 @@ +/* + * 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.fabric + +import com.facebook.react.ReactRootView +import com.facebook.react.bridge.BridgeReactContext +import com.facebook.react.bridge.ReactTestHelper.createMockCatalystInstance +import com.facebook.react.fabric.mounting.MountingManager +import com.facebook.react.fabric.mounting.MountingManager.MountItemExecutor +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests +import com.facebook.react.uimanager.IllegalViewOperationException +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.react.uimanager.ViewManager +import com.facebook.react.uimanager.ViewManagerRegistry +import com.facebook.react.views.view.ReactViewManager +import org.assertj.core.api.Assertions +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment + +/** Tests [FabricUIManager] */ +@RunWith(RobolectricTestRunner::class) +class MountingManagerTest { + private lateinit var mountingManager: MountingManager + private lateinit var mountItemExecutor: MountItemExecutor + private lateinit var themedReactContext: ThemedReactContext + private var nextRootTag = 1 + + @Before + fun setUp() { + ReactNativeFeatureFlagsForTests.setUp() + val reactContext = BridgeReactContext(RuntimeEnvironment.getApplication()) + reactContext.initializeWithInstance(createMockCatalystInstance()) + themedReactContext = ThemedReactContext(reactContext, reactContext, null, -1) + val viewManagers = listOf>(ReactViewManager()) + mountItemExecutor = MountItemExecutor { + // no-op + } + mountingManager = MountingManager(ViewManagerRegistry(viewManagers), mountItemExecutor) + } + + @Test + fun addRootView() { + val reactRootView = ReactRootView(themedReactContext) + val rootReactTag = nextRootTag++ + mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView) + Assertions.assertThat(reactRootView.id).isEqualTo(rootReactTag) + } + + @Test + fun unableToAddRootViewTwice() { + val reactRootView = ReactRootView(themedReactContext) + val rootReactTag = nextRootTag++ + mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView) + Assertions.assertThat(reactRootView.id).isEqualTo(rootReactTag) + + // This is now a SoftException because it indicates a race condition in starting + // a single surface with a single View, and is concerning but not necessarily fatal. + // To be clear: in this case we're still guaranteed a single SurfaceMountingManager + // and therefore a single View involved. + mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView) + } + + @Test(expected = IllegalViewOperationException::class) + fun unableToAddHandledRootView() { + val reactRootView = ReactRootView(themedReactContext) + reactRootView.id = 1234567 + val rootReactTag = nextRootTag++ + mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView) + } +}