Java Code Examples for com.facebook.react.bridge.ReadableNativeMap#keySetIterator()

The following examples show how to use com.facebook.react.bridge.ReadableNativeMap#keySetIterator() . 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: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMapIterateOverMapWithBasicTypes() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  Set<String> keys = new HashSet<String>();
  while (mapIterator.hasNextKey()) {
    keys.add(mapIterator.nextKey());
  }

  Set<String> expectedKeys = new HashSet<String>(
      Arrays.asList("stringKey", "doubleKey", "intKey", "booleanKey", "nullKey"));
  assertEquals(keys, expectedKeys);
}
 
Example 2
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void testMapIterateOverNestedMaps() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnNestedMap();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator firstLevelIterator = map.keySetIterator();
  String firstLevelKey = firstLevelIterator.nextKey();
  assertEquals(firstLevelKey, "weHaveToGoDeeper");

  ReadableNativeMap secondMap = map.getMap("weHaveToGoDeeper");
  ReadableMapKeySetIterator secondLevelIterator = secondMap.keySetIterator();
  String secondLevelKey = secondLevelIterator.nextKey();
  assertEquals(secondLevelKey, "inception");
  assertTrue(secondMap.getBoolean(secondLevelKey));
}
 
Example 3
Source File: CatalystNativeJSToJavaParametersTestCase.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void testInvalidIteratorExceptionThrown() {
  mCatalystInstance.getJSModule(TestJSToJavaParametersModule.class).returnMapWithBasicTypes();
  waitForBridgeAndUIIdle();

  List<ReadableMap> calls = mRecordingTestModule.getMapCalls();
  assertEquals(1, calls.size());
  ReadableNativeMap map = (ReadableNativeMap) calls.get(0);
  assertNotNull(map);

  ReadableMapKeySetIterator mapIterator = map.keySetIterator();
  while (mapIterator.hasNextKey()) {
    mapIterator.nextKey();
  }
  assertInvalidIteratorExceptionThrown(mapIterator);
}