Refactor start of ReactHost in ReactHostTest (#37986)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37986

Refactor start of ReactHost in ReactHostTest from previous diffs comments

changelog: [internal] internal

Reviewed By: cortinico

Differential Revision: D46815048

fbshipit-source-id: ff68890413e91804b5b4997d637d81be29b8bff4
This commit is contained in:
David Vacca
2023-06-26 16:58:14 -07:00
committed by Facebook GitHub Bot
parent add10419b6
commit 1334594704
@@ -105,6 +105,10 @@ public class ReactHostTest {
false,
null,
false);
TaskCompletionSource<Boolean> taskCompletionSource = new TaskCompletionSource<>();
taskCompletionSource.setResult(true);
whenNew(TaskCompletionSource.class).withAnyArguments().thenReturn(taskCompletionSource);
}
@Test
@@ -126,13 +130,6 @@ public class ReactHostTest {
@Test
public void testStart() throws Exception {
statAndTestReactHost();
}
private void statAndTestReactHost() throws Exception {
TaskCompletionSource<Boolean> taskCompletionSource = new TaskCompletionSource<>();
taskCompletionSource.setResult(true);
whenNew(TaskCompletionSource.class).withAnyArguments().thenReturn(taskCompletionSource);
doNothing().when(mDevSupportManager).isPackagerRunning(any(PackagerStatusCallback.class));
assertThat(mReactHost.isInstanceInitialized()).isFalse();
@@ -143,9 +140,13 @@ public class ReactHostTest {
verify(mMemoryPressureRouter).addMemoryPressureListener((MemoryPressureListener) any());
}
private void startReactHost() throws Exception {
waitForTaskUIThread(mReactHost.start());
}
@Test
public void testDestroy() throws Exception {
statAndTestReactHost();
startReactHost();
waitForTaskUIThread(mReactHost.destroy("Destroying from testing infra", null));
assertThat(mReactHost.isInstanceInitialized()).isFalse();
@@ -154,7 +155,7 @@ public class ReactHostTest {
@Test
public void testReload() throws Exception {
statAndTestReactHost();
startReactHost();
ReactContext oldReactContext = mReactHost.getCurrentReactContext();
BridgelessReactContext newReactContext = mock(BridgelessReactContext.class);
@@ -171,9 +172,8 @@ public class ReactHostTest {
@Test
public void testLifecycleStateChanges() throws Exception {
statAndTestReactHost();
startReactHost();
assertThat(mReactHost.isInstanceInitialized()).isTrue();
assertThat(mReactHost.getLifecycleState()).isEqualTo(LifecycleState.BEFORE_CREATE);
mReactHost.onHostResume(mActivityController.get());
assertThat(mReactHost.getLifecycleState()).isEqualTo(LifecycleState.RESUMED);