Search in sources :

Example 1 with JavaOnlyArray

use of com.facebook.react.bridge.JavaOnlyArray in project react-native-navigation by wix.

the class ColorParseTest method shouldParsePlatformColors.

@Test
public void shouldParsePlatformColors() throws JSONException {
    JSONObject color = new JSONObject();
    final JSONArray jsonArray = new JSONArray();
    jsonArray.put("@color/colorPrimary");
    color.put("resource_paths", jsonArray);
    try (MockedStatic<Arguments> theMock = Mockito.mockStatic(Arguments.class)) {
        theMock.when(Arguments::createMap).thenReturn(new JavaOnlyMap());
        theMock.when(Arguments::createArray).thenReturn(new JavaOnlyArray());
        assertThat(ColorParser.parse(activity, color, "color")).isInstanceOf(ReactPlatformColor.class);
    }
}
Also used : JSONObject(org.json.JSONObject) JavaOnlyMap(com.facebook.react.bridge.JavaOnlyMap) JSONArray(org.json.JSONArray) Arguments(com.facebook.react.bridge.Arguments) JavaOnlyArray(com.facebook.react.bridge.JavaOnlyArray) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 2 with JavaOnlyArray

use of com.facebook.react.bridge.JavaOnlyArray in project react-native-navigation by wix.

the class JSONParserTest method parsesMap.

@Test
public void parsesMap() throws Exception {
    JavaOnlyMap input = new JavaOnlyMap();
    input.putString("keyString", "stringValue");
    input.putInt("keyInt", 123);
    input.putDouble("keyDouble", 123.456);
    input.putBoolean("keyBoolean", true);
    input.putArray("keyArray", new JavaOnlyArray());
    input.putMap("keyMap", new JavaOnlyMap());
    input.putNull("bla");
    JSONObject result = new JSONParser().parse(input);
    assertThat(result.keys()).containsOnly("keyString", "keyInt", "keyDouble", "keyBoolean", "keyMap", "keyArray");
    assertThat(result.get("keyString")).isEqualTo("stringValue");
    assertThat(result.get("keyInt")).isEqualTo(123);
    assertThat(result.get("keyDouble")).isEqualTo(123.456);
    assertThat(result.get("keyBoolean")).isEqualTo(true);
    assertThat(result.getJSONObject("keyMap").keys()).isEmpty();
    assertThat(result.getJSONArray("keyArray").length()).isZero();
}
Also used : JSONObject(org.json.JSONObject) JavaOnlyMap(com.facebook.react.bridge.JavaOnlyMap) JavaOnlyArray(com.facebook.react.bridge.JavaOnlyArray) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 3 with JavaOnlyArray

use of com.facebook.react.bridge.JavaOnlyArray in project react-native-navigation by wix.

the class JSONParserTest method parsesArrays.

@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();
}
Also used : JavaOnlyMap(com.facebook.react.bridge.JavaOnlyMap) JSONArray(org.json.JSONArray) JavaOnlyArray(com.facebook.react.bridge.JavaOnlyArray) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 4 with JavaOnlyArray

use of com.facebook.react.bridge.JavaOnlyArray in project react-native-image-picker by marcshilling.

the class ImagePickerModuleTest method nativeMock.

private void nativeMock() {
    PowerMockito.mockStatic(Arguments.class);
    when(Arguments.createArray()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return new JavaOnlyArray();
        }
    });
    when(Arguments.createMap()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return new JavaOnlyMap();
        }
    });
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) JavaOnlyMap(com.facebook.react.bridge.JavaOnlyMap) JavaOnlyArray(com.facebook.react.bridge.JavaOnlyArray)

Example 5 with JavaOnlyArray

use of com.facebook.react.bridge.JavaOnlyArray in project react-native-svg by react-native-svg.

the class RenderableView method setFill.

@ReactProp(name = "fill")
public void setFill(@Nullable Dynamic fill) {
    if (fill == null || fill.isNull()) {
        this.fill = null;
        invalidate();
        return;
    }
    ReadableType type = fill.getType();
    if (type.equals(ReadableType.Number)) {
        this.fill = JavaOnlyArray.of(0, fill.asInt());
    } else if (type.equals(ReadableType.Array)) {
        this.fill = fill.asArray();
    } else {
        JavaOnlyArray arr = new JavaOnlyArray();
        arr.pushInt(0);
        Matcher m = regex.matcher(fill.asString());
        int i = 0;
        while (m.find()) {
            double parsed = Double.parseDouble(m.group());
            arr.pushDouble(i++ < 3 ? parsed / 255 : parsed);
        }
        this.fill = arr;
    }
    invalidate();
}
Also used : ReadableType(com.facebook.react.bridge.ReadableType) Matcher(java.util.regex.Matcher) JavaOnlyArray(com.facebook.react.bridge.JavaOnlyArray) ReactProp(com.facebook.react.uimanager.annotations.ReactProp)

Aggregations

JavaOnlyArray (com.facebook.react.bridge.JavaOnlyArray)6 JavaOnlyMap (com.facebook.react.bridge.JavaOnlyMap)4 BaseTest (com.reactnativenavigation.BaseTest)3 Test (org.junit.Test)3 ReadableType (com.facebook.react.bridge.ReadableType)2 ReactProp (com.facebook.react.uimanager.annotations.ReactProp)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Arguments (com.facebook.react.bridge.Arguments)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1