Java Code Examples for com.facebook.react.bridge.JavaOnlyArray#pushString()

The following examples show how to use com.facebook.react.bridge.JavaOnlyArray#pushString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONParserTest.java    From react-native-navigation with MIT License 6 votes vote down vote up
@Test
public void parsesArrays() throws Exception {
    JavaOnlyArray input = new JavaOnlyArray();
    input.pushString("Hello");
    input.pushInt(123);
    input.pushDouble(123.456);
    input.pushBoolean(true);
    input.pushArray(new JavaOnlyArray());
    input.pushMap(new JavaOnlyMap());
    input.pushNull();

    JSONArray result = new JSONParser().parse(input);
    assertThat(result.length()).isEqualTo(6);
    assertThat(result.get(0)).isEqualTo("Hello");
    assertThat(result.get(1)).isEqualTo(123);
    assertThat(result.get(2)).isEqualTo(123.456);
    assertThat(result.get(3)).isEqualTo(true);
    assertThat(result.getJSONArray(4).length()).isZero();
    assertThat(result.getJSONObject(5).keys()).isEmpty();
}
 
Example 2
Source File: RNInstabugBugReportingModuleTest.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
@Test
public void givenInvocationEvent$setInvocationEvents_whenQuery_thenShouldCallNativeApiWithArgs() {
    // given
    PowerMockito.mockStatic(BugReporting.class);
    final Map<String, Object> args = new HashMap<>();
    ArgsRegistry.registerInstabugInvocationEventsArgs(args);
    final String[] keysArray = args.keySet().toArray(new String[0]);
    JavaOnlyArray actualArray = new JavaOnlyArray();
    for (String key : keysArray) {
        actualArray.pushString(key);
    }
    // when
    bugReportingModule.setInvocationEvents(actualArray);
    // then
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    BugReporting.setInvocationEvents(args.values().toArray(new InstabugInvocationEvent[0]));
}
 
Example 3
Source File: RNInstabugBugReportingModuleTest.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
@Test
public void givenOptions$setOptions_whenQuery_thenShouldCallNativeApiWithArgs() {
    // given
    PowerMockito.mockStatic(BugReporting.class);
    final Map<String, Object> args = new HashMap<>();
    ArgsRegistry.registerInvocationOptionsArgs(args);
    final String[] keysArray = args.keySet().toArray(new String[0]);
    JavaOnlyArray actualArray = new JavaOnlyArray();
    actualArray.pushString(keysArray[0]);
    actualArray.pushString(keysArray[1]);
    // when
    bugReportingModule.setOptions(actualArray);
    // then
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    int option1 = (int) args.get(keysArray[0]);
    int option2 = (int) args.get(keysArray[1]);
    BugReporting.setOptions(option1);
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    BugReporting.setOptions(option2);
}
 
Example 4
Source File: RNInstabugBugReportingModuleTest.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
@Test
public void givenArray$setReportTypes_whenQuery_thenShouldCallNativeApiWithEnumArgs() {
    // given
    PowerMockito.mockStatic(BugReporting.class);
    final Map<String, Object> args = new HashMap<>();
    ArgsRegistry.registerInstabugReportTypesArgs(args);
    final String[] keysArray = args.keySet().toArray(new String[0]);
    JavaOnlyArray actualArray = new JavaOnlyArray();
    actualArray.pushString(keysArray[0]);
    actualArray.pushString(keysArray[1]);
    // when
    bugReportingModule.setReportTypes(actualArray);
    // then
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    int type1 = (int) args.get(keysArray[0]);
    int type2 = (int) args.get(keysArray[1]);
    BugReporting.setReportTypes(type1, type2);
}
 
Example 5
Source File: RNInstabugBugReportingModuleTest.java    From Instabug-React-Native with MIT License 6 votes vote down vote up
@Test
public void givenArgs$showBugReportingWithReportTypeAndOptions_whenQuery_thenShouldCallNativeApiWithEnums() {
    // given
    PowerMockito.mockStatic(BugReporting.class);
    final Map<String, Object> optionsArgs = new HashMap<>();
    final Map<String, Object> reportTypeArgs = new HashMap<>();
    ArgsRegistry.registerInvocationOptionsArgs(optionsArgs);
    ArgsRegistry.registerInstabugReportTypesArgs(reportTypeArgs);
    final String[] keysArray = optionsArgs.keySet().toArray(new String[0]);
    final String[] reportTypeKeys = reportTypeArgs.keySet().toArray(new String[0]);
    JavaOnlyArray actualArray = new JavaOnlyArray();
    actualArray.pushString(keysArray[0]);
    actualArray.pushString(keysArray[1]);
    // when
    bugReportingModule.show(reportTypeKeys[0], actualArray);
    // then
    int option1 = (int) optionsArgs.get(keysArray[0]);
    int option2 = (int) optionsArgs.get(keysArray[1]);
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    BugReporting.setOptions(option1);
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    BugReporting.setOptions(option2);
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    BugReporting.show((int) reportTypeArgs.get(reportTypeKeys[0]));
}
 
Example 6
Source File: AsyncStorageModuleTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@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);
  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);
  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);
  verify(getCallback2, Mockito.times(1)).invoke(null, keyValues);
}
 
Example 7
Source File: AsyncStorageModuleTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@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);
  verify(getCallback, Mockito.times(1)).invoke();

  Callback getAllCallback = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback);
  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);
  verify(getCallback2, Mockito.times(1)).invoke();

  Callback getAllCallback2 = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback2);
  verify(getAllCallback2, Mockito.times(1)).invoke(null, mEmptyArray);
}
 
Example 8
Source File: AsyncStorageModuleTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@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);
  verify(getAllCallback, Mockito.times(1)).invoke(null, storedKeys);

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

  mStorage.getAllKeys(getAllCallback2);
  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);
  verify(getAllCallback3, Mockito.times(1)).invoke(null, mEmptyArray);
}
 
Example 9
Source File: AsyncStorageModuleTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
private JavaOnlyArray getArray(String... values) {
  JavaOnlyArray array = new JavaOnlyArray();
  for (String value : values) {
    array.pushString(value);
  }
  return array;
}
 
Example 10
Source File: RNInstabugReactnativeModuleTest.java    From Instabug-React-Native with MIT License 5 votes vote down vote up
@Test
public void givenArg$appendTags_whenQuery_thenShouldCallNativeApiWithArg() {
    // given
    PowerMockito.mockStatic(Instabug.class);
    JavaOnlyArray array = new JavaOnlyArray();
    array.pushString("tag1");
    array.pushString("tag2");
    // when
    rnModule.appendTags(array);
    // then
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    String [] expectedArray = {"tag1", "tag2"};
    Instabug.addTags(expectedArray);
}