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

The following examples show how to use com.facebook.react.bridge.JavaOnlyArray#pushArray() . These examples are extracted from open source projects. 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 Project: react-native-navigation   File: JSONParserTest.java    License: 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
@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 3
@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 4
@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 5
@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);
  verify(clearCallback2, Mockito.times(1)).invoke();

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