Java 类com.facebook.react.bridge.JavaOnlyArray 实例源码

项目:RNLearn_Project1    文件:TransformAnimatedNode.java   
public void collectViewUpdates(JavaOnlyMap propsMap) {
  List<JavaOnlyMap> transforms = new ArrayList<>(mTransformConfigs.size());

  for (TransformConfig transformConfig : mTransformConfigs) {
    double value;
    if (transformConfig instanceof AnimatedTransformConfig) {
      int nodeTag = ((AnimatedTransformConfig) transformConfig).mNodeTag;
      AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(nodeTag);
      if (node == null) {
        throw new IllegalArgumentException("Mapped style node does not exists");
      } else if (node instanceof ValueAnimatedNode) {
        value = ((ValueAnimatedNode) node).getValue();
      } else {
        throw new IllegalArgumentException("Unsupported type of node used as a transform child " +
          "node " + node.getClass());
      }
    } else {
      value = ((StaticTransformConfig) transformConfig).mValue;
    }

    transforms.add(JavaOnlyMap.of(transformConfig.mProperty, value));
  }

  propsMap.putArray("transform", JavaOnlyArray.from(transforms));
}
项目:RNLearn_Project1    文件:NativeAnimatedNodeTraversalTest.java   
@Test
public void testNativeAnimatedEventDoUpdate() {
  int viewTag = 1000;

  createSimpleAnimatedViewWithOpacity(viewTag, 0d);

  mNativeAnimatedNodesManager.addAnimatedEventToView(viewTag, "topScroll", JavaOnlyMap.of(
    "animatedValueTag", 1,
    "nativeEventPath", JavaOnlyArray.of("contentOffset", "y")));

  mNativeAnimatedNodesManager.onEventDispatch(createScrollEvent(viewTag, 10));

  ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
    ArgumentCaptor.forClass(ReactStylesDiffMap.class);

  reset(mUIImplementationMock);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture());
  assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(10);
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testPausingAndResuming() {
  mTiming.onHostResume();
  mTiming.createTimer(mExecutorTokenMock, 41, 1, 0, true);

  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHostPause();
  stepChoreographerFrame();
  verifyNoMoreInteractions(mJSTimersMock);

  reset(mJSTimersMock);
  mTiming.onHostResume();
  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testHeadlessJsTaskIntertwine() {
  mTiming.onHostResume();
  mTiming.onHeadlessJsTaskStart(42);
  mTiming.createTimer(mExecutorTokenMock, 41, 1, 0, true);
  mTiming.onHostPause();

  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHostResume();
  mTiming.onHeadlessJsTaskFinish(42);
  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHostPause();
  stepChoreographerFrame();
  verifyNoMoreInteractions(mJSTimersMock);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testDeleteViews() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(1);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2);

  uiManager.manageChildren(
      hierarchy.rootView,
      null,
      null,
      null,
      null,
      JavaOnlyArray.of(0, 3));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertChildrenAreExactly(
      hierarchy.nativeRootView,
      expectedViewAt0,
      expectedViewAt1);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testMoveAndDeleteViews() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(3);
  View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(2);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(3),
      JavaOnlyArray.of(1),
      null,
      null,
      JavaOnlyArray.of(1));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertChildrenAreExactly(
      hierarchy.nativeRootView,
      expectedViewAt0,
      expectedViewAt1,
      expectedViewAt2);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test(expected = IllegalViewOperationException.class)
public void testMoveAndDeleteRemoveViewsDuplicateRemove() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(3),
      JavaOnlyArray.of(1),
      null,
      null,
      JavaOnlyArray.of(3));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test(expected = IllegalViewOperationException.class)
public void testDuplicateRemove() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  uiManager.manageChildren(
      hierarchy.rootView,
      null,
      null,
      null,
      null,
      JavaOnlyArray.of(3, 3));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();
}
项目:RNLearn_Project1    文件:NativeAnimatedNodeTraversalTest.java   
@Test
public void testNodeValueListenerIfNotListening() {
  int nodeId = 1;

  createSimpleAnimatedViewWithOpacity(1000, 0d);
  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);

  Callback animationCallback = mock(Callback.class);
  AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class);

  mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener);
  mNativeAnimatedNodesManager.startAnimatingNode(
    1,
    nodeId,
    JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
    animationCallback);

  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(valueListener).onValueUpdate(eq(0d));

  mNativeAnimatedNodesManager.stopListeningToAnimatedNodeValue(nodeId);

  reset(valueListener);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(valueListener);
}
项目:RNLearn_Project1    文件:NativeAnimatedNodeTraversalTest.java   
@Test
public void testNodeValueListenerIfNotListening() {
  int nodeId = 1;

  createSimpleAnimatedViewWithOpacity(1000, 0d);
  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);

  Callback animationCallback = mock(Callback.class);
  AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class);

  mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener);
  mNativeAnimatedNodesManager.startAnimatingNode(
    1,
    nodeId,
    JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
    animationCallback);

  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(valueListener).onValueUpdate(eq(0d));

  mNativeAnimatedNodesManager.stopListeningToAnimatedNodeValue(nodeId);

  reset(valueListener);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(valueListener);
}
项目:RNLearn_Project1    文件:NativeAnimatedNodeTraversalTest.java   
@Test
public void testNativeAnimatedEventDoNotUpdate() {
  int viewTag = 1000;

  createSimpleAnimatedViewWithOpacity(viewTag, 0d);

  mNativeAnimatedNodesManager.addAnimatedEventToView(viewTag, "otherEvent", JavaOnlyMap.of(
    "animatedValueTag", 1,
    "nativeEventPath", JavaOnlyArray.of("contentOffset", "y")));

  mNativeAnimatedNodesManager.addAnimatedEventToView(999, "topScroll", JavaOnlyMap.of(
    "animatedValueTag", 1,
    "nativeEventPath", JavaOnlyArray.of("contentOffset", "y")));

  mNativeAnimatedNodesManager.onEventDispatch(createScrollEvent(viewTag, 10));

  ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
    ArgumentCaptor.forClass(ReactStylesDiffMap.class);

  reset(mUIImplementationMock);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(viewTag), stylesCaptor.capture());
  assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(0);
}
项目:RNLearn_Project1    文件:TransformAnimatedNode.java   
public void collectViewUpdates(JavaOnlyMap propsMap) {
  List<JavaOnlyMap> transforms = new ArrayList<>(mTransformConfigs.size());

  for (TransformConfig transformConfig : mTransformConfigs) {
    double value;
    if (transformConfig instanceof AnimatedTransformConfig) {
      int nodeTag = ((AnimatedTransformConfig) transformConfig).mNodeTag;
      AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(nodeTag);
      if (node == null) {
        throw new IllegalArgumentException("Mapped style node does not exists");
      } else if (node instanceof ValueAnimatedNode) {
        value = ((ValueAnimatedNode) node).getValue();
      } else {
        throw new IllegalArgumentException("Unsupported type of node used as a transform child " +
          "node " + node.getClass());
      }
    } else {
      value = ((StaticTransformConfig) transformConfig).mValue;
    }

    transforms.add(JavaOnlyMap.of(transformConfig.mProperty, value));
  }

  propsMap.putArray("transform", JavaOnlyArray.from(transforms));
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testHeadlessJsTaskInForeground() {
  mTiming.onHostResume();
  mTiming.onHeadlessJsTaskStart(42);
  mTiming.createTimer(mExecutorTokenMock, 41, 1, 0, true);

  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHeadlessJsTaskFinish(42);
  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHostPause();
  verifyNoMoreInteractions(mJSTimersMock);
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testHeadlessJsTaskIntertwine() {
  mTiming.onHostResume();
  mTiming.onHeadlessJsTaskStart(42);
  mTiming.createTimer(mExecutorTokenMock, 41, 1, 0, true);
  mTiming.onHostPause();

  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHostResume();
  mTiming.onHeadlessJsTaskFinish(42);
  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHostPause();
  stepChoreographerFrame();
  verifyNoMoreInteractions(mJSTimersMock);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testMoveAndDeleteViews() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(3);
  View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(2);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(3),
      JavaOnlyArray.of(1),
      null,
      null,
      JavaOnlyArray.of(1));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertChildrenAreExactly(
      hierarchy.nativeRootView,
      expectedViewAt0,
      expectedViewAt1,
      expectedViewAt2);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test(expected = IllegalViewOperationException.class)
public void testMoveAndDeleteRemoveViewsDuplicateRemove() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(3),
      JavaOnlyArray.of(1),
      null,
      null,
      JavaOnlyArray.of(3));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test(expected = IllegalViewOperationException.class)
public void testDuplicateRemove() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  uiManager.manageChildren(
      hierarchy.rootView,
      null,
      null,
      null,
      null,
      JavaOnlyArray.of(3, 3));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testDeleteViewsWithChildren() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2);
  View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(3);

  uiManager.manageChildren(
      hierarchy.rootView,
      null,
      null,
      null,
      null,
      JavaOnlyArray.of(1));

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertChildrenAreExactly(
      hierarchy.nativeRootView,
      expectedViewAt0,
      expectedViewAt1,
      expectedViewAt2);
}
项目:rnrecord    文件:FindCommandTest.java   
@Test
public void shouldFindDbEntry() throws Exception {
    String tableName  = "testTable";
    ReadableMap readableMap = JavaOnlyMap.of("id", 1D);
    AwaitablePromise<JavaOnlyArray> awaitablePromise = new AwaitablePromise<>();
    Cursor cursor = mockCursor();
    when(sqLiteDatabase.rawQuery("SELECT * from " + tableName + " WHERE id = ? ;", new String[] { "1.0" })).thenReturn(cursor);

    FindCommand findCommand = new FindCommand(reactContext, rnRecordSQLiteHelper);
    findCommand.find(tableName, readableMap, awaitablePromise.promise());
    JavaOnlyArray result = awaitablePromise.awaitResolve();
    assertThat(result.size(), is(1));
    assertThat(result.getMap(0).getString("name"), is("rob"));
}
项目:rnrecord    文件:FindAllCommandTest.java   
@Test
public void shouldFindAllDbEntries() throws Exception {
    String tableName  = "testTable";
    AwaitablePromise<JavaOnlyArray> awaitablePromise = new AwaitablePromise<>();
    Cursor cursor = mockCursor();
    when(sqLiteDatabase.rawQuery("select * from " + tableName, null)).thenReturn(cursor);

    FindAllCommand findAllCommand = new FindAllCommand(reactContext, rnRecordSQLiteHelper);
    findAllCommand.findAll(tableName, awaitablePromise.promise());
    JavaOnlyArray result = awaitablePromise.awaitResolve();
    assertThat(result.size(), is(1));
    assertThat(result.getMap(0).getString("name"), is("rob"));
}
项目:RNLearn_Project1    文件:TextInputTest.java   
@Test
public void testPropsApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  rootView.setLayoutParams(new ReactRootView.LayoutParams(100, 100));
  int rootTag = uiManager.addMeasuredRootView(rootView);
  int textInputTag = rootTag + 1;
  final String hintStr = "placeholder text";

  uiManager.createView(
      textInputTag,
      ReactTextInputManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of(
          ViewProps.FONT_SIZE, 13.37, ViewProps.HEIGHT, 20.0, "placeholder", hintStr));

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textInputTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingChoreographerCallbacks();

  EditText editText = (EditText) rootView.getChildAt(0);
  assertThat(editText.getHint()).isEqualTo(hintStr);
  assertThat(editText.getTextSize()).isEqualTo((float) Math.ceil(13.37));
  assertThat(editText.getHeight()).isEqualTo(20);
}
项目:RNLearn_Project1    文件:ReactTextTest.java   
private ReactRootView createText(
    UIManagerModule uiManager,
    JavaOnlyMap textProps,
    JavaOnlyMap rawTextProps) {
  ReactRootView rootView = new ReactRootView(RuntimeEnvironment.application);
  int rootTag = uiManager.addMeasuredRootView(rootView);
  int textTag = rootTag + 1;
  int rawTextTag = textTag + 1;

  uiManager.createView(
      textTag,
      ReactTextViewManager.REACT_CLASS,
      rootTag,
      textProps);
  uiManager.createView(
      rawTextTag,
      ReactRawTextManager.REACT_CLASS,
      rootTag,
      rawTextProps);

  uiManager.manageChildren(
      textTag,
      null,
      null,
      JavaOnlyArray.of(rawTextTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.manageChildren(
      rootTag,
      null,
      null,
      JavaOnlyArray.of(textTag),
      JavaOnlyArray.of(0),
      null);

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();
  return rootView;
}
项目:RNLearn_Project1    文件:ReactImagePropertyTest.java   
@Test
public void testRoundedCorners() {
  ReactImageManager viewManager = new ReactImageManager();
  ReactImageView view = viewManager.createViewInstance(mThemeContext);
  viewManager.updateProperties(
    view,
    buildStyles("src", JavaOnlyArray.of(JavaOnlyMap.of("uri", "http://mysite.com/mypic.jpg"))));

  // We can't easily verify if rounded corner was honored or not, this tests simply verifies
  // we're not crashing..
  viewManager.updateProperties(view, buildStyles("borderRadius", (double) 10));
  viewManager.updateProperties(view, buildStyles("borderRadius", (double) 0));
  viewManager.updateProperties(view, buildStyles("borderRadius", null));
}
项目:RNLearn_Project1    文件:NetworkingModuleTest.java   
@Test
public void testGetWithoutHeaders() throws Exception {
  OkHttpClient httpClient = mock(OkHttpClient.class);
  when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      Call callMock = mock(Call.class);
      return callMock;
    }
  });
  OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
  when(clientBuilder.build()).thenReturn(httpClient);
  when(httpClient.newBuilder()).thenReturn(clientBuilder);
  NetworkingModule networkingModule =
    new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);

  networkingModule.sendRequest(
    mock(ExecutorToken.class),
    "GET",
    "http://somedomain/foo",
    /* requestId */ 0,
    /* headers */ JavaOnlyArray.of(),
    /* body */ null,
    /* responseType */ "text",
    /* useIncrementalUpdates*/ true,
    /* timeout */ 0,
    /* withCredentials */ false);

  ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
  verify(httpClient).newCall(argumentCaptor.capture());
  assertThat(argumentCaptor.getValue().url().toString()).isEqualTo("http://somedomain/foo");
  // We set the User-Agent header by default
  assertThat(argumentCaptor.getValue().headers().size()).isEqualTo(1);
  assertThat(argumentCaptor.getValue().method()).isEqualTo("GET");
}
项目:RNLearn_Project1    文件:NetworkingModuleTest.java   
@Test
public void testFailPostWithoutContentType() throws Exception {
  RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
  ReactApplicationContext context = mock(ReactApplicationContext.class);
  when(context.getJSModule(any(ExecutorToken.class), any(Class.class))).thenReturn(emitter);

  OkHttpClient httpClient = mock(OkHttpClient.class);
  OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
  when(clientBuilder.build()).thenReturn(httpClient);
  when(httpClient.newBuilder()).thenReturn(clientBuilder);
  NetworkingModule networkingModule = new NetworkingModule(context, "", httpClient);

  JavaOnlyMap body = new JavaOnlyMap();
  body.putString("string", "This is request body");

  mockEvents();

  networkingModule.sendRequest(
    mock(ExecutorToken.class),
    "POST",
    "http://somedomain/bar",
    0,
    JavaOnlyArray.of(),
    body,
    /* responseType */ "text",
    /* useIncrementalUpdates*/ true,
    /* timeout */ 0,
    /* withCredentials */ false);

  verifyErrorEmit(emitter, 0);
}
项目:RNLearn_Project1    文件:NetworkingModuleTest.java   
@Test
public void testHeaders() throws Exception {
  OkHttpClient httpClient = mock(OkHttpClient.class);
  when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
      Call callMock = mock(Call.class);
      return callMock;
    }
  });
  OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
  when(clientBuilder.build()).thenReturn(httpClient);
  when(httpClient.newBuilder()).thenReturn(clientBuilder);
  NetworkingModule networkingModule =
    new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);

  List<JavaOnlyArray> headers = Arrays.asList(
      JavaOnlyArray.of("Accept", "text/plain"),
      JavaOnlyArray.of("User-Agent", "React test agent/1.0"));

  networkingModule.sendRequest(
    mock(ExecutorToken.class),
    "GET",
    "http://someurl/baz",
    0,
    JavaOnlyArray.from(headers),
    null,
    /* responseType */ "text",
    /* useIncrementalUpdates*/ true,
    /* timeout */ 0,
    /* withCredentials */ false);
  ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
  verify(httpClient).newCall(argumentCaptor.capture());
  Headers requestHeaders = argumentCaptor.getValue().headers();
  assertThat(requestHeaders.size()).isEqualTo(2);
  assertThat(requestHeaders.get("Accept")).isEqualTo("text/plain");
  assertThat(requestHeaders.get("User-Agent")).isEqualTo("React test agent/1.0");
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testSimpleRecurringTimer() {
  mTiming.createTimer(mExecutorTokenMock, 100, 1, 0, true);
  mTiming.onHostResume();
  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(100));

  reset(mJSTimersMock);
  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(100));
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testCancelRecurringTimer() {
  mTiming.onHostResume();
  mTiming.createTimer(mExecutorTokenMock, 105, 1, 0, true);

  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(105));

  reset(mJSTimersMock);
  mTiming.deleteTimer(mExecutorTokenMock, 105);
  stepChoreographerFrame();
  verifyNoMoreInteractions(mJSTimersMock);
}
项目:RNLearn_Project1    文件:TimingModuleTest.java   
@Test
public void testHeadlessJsTaskInBackground() {
  mTiming.onHostPause();
  mTiming.onHeadlessJsTaskStart(42);
  mTiming.createTimer(mExecutorTokenMock, 41, 1, 0, true);

  stepChoreographerFrame();
  verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));

  reset(mJSTimersMock);
  mTiming.onHeadlessJsTaskFinish(42);
  stepChoreographerFrame();
  verifyNoMoreInteractions(mJSTimersMock);
}
项目:RNLearn_Project1    文件:AsyncStorageModuleTest.java   
@Test
public void testMultiSetMultiGet() {
  final String key1 = "foo1";
  final String key2 = "foo2";
  final String fakeKey = "fakeKey";
  final String value1 = "bar1";
  final String value2 = "bar2";
  JavaOnlyArray keyValues = new JavaOnlyArray();
  keyValues.pushArray(getArray(key1, value1));
  keyValues.pushArray(getArray(key2, value2));

  Callback setCallback = mock(Callback.class);
  mStorage.multiSet(keyValues, setCallback);
  Mockito.verify(setCallback, Mockito.times(1)).invoke();

  JavaOnlyArray keys = new JavaOnlyArray();
  keys.pushString(key1);
  keys.pushString(key2);

  Callback getCallback = mock(Callback.class);
  mStorage.multiGet(keys, getCallback);
  Mockito.verify(getCallback, Mockito.times(1)).invoke(null, keyValues);

  keys.pushString(fakeKey);
  JavaOnlyArray row3 = new JavaOnlyArray();
  row3.pushString(fakeKey);
  row3.pushString(null);
  keyValues.pushArray(row3);

  Callback getCallback2 = mock(Callback.class);
  mStorage.multiGet(keys, getCallback2);
  Mockito.verify(getCallback2, Mockito.times(1)).invoke(null, keyValues);
}
项目:RNLearn_Project1    文件:AsyncStorageModuleTest.java   
@Test
public void testMultiRemove() {
  final String key1 = "foo1";
  final String key2 = "foo2";
  final String value1 = "bar1";
  final String value2 = "bar2";

  JavaOnlyArray keyValues = new JavaOnlyArray();
  keyValues.pushArray(getArray(key1, value1));
  keyValues.pushArray(getArray(key2, value2));
  mStorage.multiSet(keyValues, mock(Callback.class));

  JavaOnlyArray keys = new JavaOnlyArray();
  keys.pushString(key1);
  keys.pushString(key2);

  Callback getCallback = mock(Callback.class);
  mStorage.multiRemove(keys, getCallback);
  Mockito.verify(getCallback, Mockito.times(1)).invoke();

  Callback getAllCallback = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback);
  Mockito.verify(getAllCallback, Mockito.times(1)).invoke(null, mEmptyArray);

  mStorage.multiSet(keyValues, mock(Callback.class));

  keys.pushString("fakeKey");
  Callback getCallback2 = mock(Callback.class);
  mStorage.multiRemove(keys, getCallback2);
  Mockito.verify(getCallback2, Mockito.times(1)).invoke();

  Callback getAllCallback2 = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback2);
  Mockito.verify(getAllCallback2, Mockito.times(1)).invoke(null, mEmptyArray);
}
项目:RNLearn_Project1    文件:AsyncStorageModuleTest.java   
@Test
public void testGetAllKeys() {
  final String[] keys = {"foo", "foo2"};
  final String[] values = {"bar", "bar2"};
  JavaOnlyArray keyValues = new JavaOnlyArray();
  keyValues.pushArray(getArray(keys[0], values[0]));
  keyValues.pushArray(getArray(keys[1], values[1]));
  mStorage.multiSet(keyValues, mock(Callback.class));

  JavaOnlyArray storedKeys = new JavaOnlyArray();
  storedKeys.pushString(keys[0]);
  storedKeys.pushString(keys[1]);

  Callback getAllCallback = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback);
  Mockito.verify(getAllCallback, Mockito.times(1)).invoke(null, storedKeys);

  Callback getAllCallback2 = mock(Callback.class);
  mStorage.multiRemove(getArray(keys[0]), mock(Callback.class));

  mStorage.getAllKeys(getAllCallback2);
  Mockito.verify(getAllCallback2, Mockito.times(1)).invoke(null, getArray(keys[1]));

  mStorage.multiRemove(getArray(keys[1]), mock(Callback.class));
  Callback getAllCallback3 = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback3);
  Mockito.verify(getAllCallback3, Mockito.times(1)).invoke(null, mEmptyArray);
}
项目:RNLearn_Project1    文件:AsyncStorageModuleTest.java   
@Test
public void testClear() {
  JavaOnlyArray keyValues = new JavaOnlyArray();
  keyValues.pushArray(getArray("foo", "foo2"));
  keyValues.pushArray(getArray("bar", "bar2"));
  mStorage.multiSet(keyValues, mock(Callback.class));

  Callback clearCallback2 = mock(Callback.class);
  mStorage.clear(clearCallback2);
  Mockito.verify(clearCallback2, Mockito.times(1)).invoke();

  Callback getAllCallback2 = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback2);
  Mockito.verify(getAllCallback2, Mockito.times(1)).invoke(null, mEmptyArray);
}
项目:RNLearn_Project1    文件:AsyncStorageModuleTest.java   
private JavaOnlyArray getArray(String... values) {
  JavaOnlyArray array = new JavaOnlyArray();
  for (String value : values) {
    array.pushString(value);
  }
  return array;
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testMoveViews() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(1);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2);
  View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(0);
  View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(3);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(1, 0, 2),
      JavaOnlyArray.of(0, 2, 1),
      null,
      null,
      null);

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertChildrenAreExactly(
      hierarchy.nativeRootView,
      expectedViewAt0,
      expectedViewAt1,
      expectedViewAt2,
      expectedViewAt3);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testMoveAndAddViews() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  int textViewTag = 1000;
  uiManager.createView(
      textViewTag,
      ReactTextViewManager.REACT_CLASS,
      hierarchy.rootView,
      JavaOnlyMap.of("collapsable", false));

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(3);
  View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(1);
  View expectedViewAt4 = hierarchy.nativeRootView.getChildAt(2);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(1, 2, 3),
      JavaOnlyArray.of(3, 4, 1),
      JavaOnlyArray.of(textViewTag),
      JavaOnlyArray.of(2),
      null);

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertThat(hierarchy.nativeRootView.getChildCount()).isEqualTo(5);
  assertThat(hierarchy.nativeRootView.getChildAt(0)).isEqualTo(expectedViewAt0);
  assertThat(hierarchy.nativeRootView.getChildAt(1)).isEqualTo(expectedViewAt1);
  assertThat(hierarchy.nativeRootView.getChildAt(3)).isEqualTo(expectedViewAt3);
  assertThat(hierarchy.nativeRootView.getChildAt(4)).isEqualTo(expectedViewAt4);
}
项目:RNLearn_Project1    文件:UIManagerModuleTest.java   
@Test
public void testMoveViewsWithChildren() {
  UIManagerModule uiManager = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager);

  View expectedViewAt0 = hierarchy.nativeRootView.getChildAt(0);
  View expectedViewAt1 = hierarchy.nativeRootView.getChildAt(2);
  View expectedViewAt2 = hierarchy.nativeRootView.getChildAt(1);
  View expectedViewAt3 = hierarchy.nativeRootView.getChildAt(3);

  uiManager.manageChildren(
      hierarchy.rootView,
      JavaOnlyArray.of(1, 2),
      JavaOnlyArray.of(2, 1),
      null,
      null,
      null);

  uiManager.onBatchComplete();
  executePendingFrameCallbacks();

  assertChildrenAreExactly(
      hierarchy.nativeRootView,
      expectedViewAt0,
      expectedViewAt1,
      expectedViewAt2,
      expectedViewAt3);
  assertThat(((ViewGroup) hierarchy.nativeRootView.getChildAt(2)).getChildCount()).isEqualTo(2);
}
项目:RNLearn_Project1    文件:NativeAnimatedNodeTraversalTest.java   
@Test
public void testNodeValueListenerIfListening() {
  int nodeId = 1;

  createSimpleAnimatedViewWithOpacity(1000, 0d);
  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);

  Callback animationCallback = mock(Callback.class);
  AnimatedNodeValueListener valueListener = mock(AnimatedNodeValueListener.class);

  mNativeAnimatedNodesManager.startListeningToAnimatedNodeValue(nodeId, valueListener);
  mNativeAnimatedNodesManager.startAnimatingNode(
    1,
    nodeId,
    JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
    animationCallback);

  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(valueListener).onValueUpdate(eq(0d));

  for (int i = 0; i < frames.size(); i++) {
    reset(valueListener);
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
    verify(valueListener).onValueUpdate(eq(frames.getDouble(i)));
  }

  reset(valueListener);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(valueListener);
}
项目:RNLearn_Project1    文件:NativeAnimatedNodeTraversalTest.java   
@Test
public void testFramesAnimation() {
  createSimpleAnimatedViewWithOpacity(1000, 0d);

  JavaOnlyArray frames = JavaOnlyArray.of(0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d);
  Callback animationCallback = mock(Callback.class);
  mNativeAnimatedNodesManager.startAnimatingNode(
    1,
    1,
    JavaOnlyMap.of("type", "frames", "frames", frames, "toValue", 1d),
    animationCallback);

  ArgumentCaptor<ReactStylesDiffMap> stylesCaptor =
      ArgumentCaptor.forClass(ReactStylesDiffMap.class);

  reset(mUIImplementationMock);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verify(mUIImplementationMock).synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
  assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN)).isEqualTo(0);

  for (int i = 0; i < frames.size(); i++) {
    reset(mUIImplementationMock);
    mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
    verify(mUIImplementationMock)
        .synchronouslyUpdateViewOnUIThread(eq(1000), stylesCaptor.capture());
    assertThat(stylesCaptor.getValue().getDouble("opacity", Double.NaN))
        .isEqualTo(frames.getDouble(i));
  }

  reset(mUIImplementationMock);
  mNativeAnimatedNodesManager.runUpdates(nextFrameTime());
  verifyNoMoreInteractions(mUIImplementationMock);
}
项目:RNLearn_Project1    文件:ReactPropAnnotationSetterTest.java   
@Test
public void testArraySetter() {
  ReadableArray array = new JavaOnlyArray();
  mViewManager.updateProperties(null, buildStyles("arrayProp", array));
  verify(mUpdatesReceiverMock).onArraySetterCalled(array);
  verifyNoMoreInteractions(mUpdatesReceiverMock);
  reset(mUpdatesReceiverMock);

  mViewManager.updateProperties(null, buildStyles("arrayProp", null));
  verify(mUpdatesReceiverMock).onArraySetterCalled(null);
  verifyNoMoreInteractions(mUpdatesReceiverMock);
  reset(mUpdatesReceiverMock);
}