mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 09:21:44 +08:00
Get rid of jackson (mostly)
Reviewed By: astreet Differential Revision: D3041362 fb-gh-sync-id: a7027a08a63730b98dc766b86921820fa3624953 shipit-source-id: a7027a08a63730b98dc766b86921820fa3624953
This commit is contained in:
committed by
Facebook Github Bot 8
parent
14555063bb
commit
d329570ac8
@@ -8,12 +8,12 @@ android_library(
|
||||
name = 'testhelpers',
|
||||
srcs = glob(['*.java'], excludes = STANDARD_TEST_SRCS),
|
||||
deps = [
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
react_native_target('java/com/facebook/react/uimanager:uimanager'),
|
||||
react_native_dep('third-party/java/mockito:mockito'),
|
||||
react_native_dep('third-party/java/robolectric3/robolectric:robolectric'),
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
react_native_target('java/com/facebook/react/uimanager:uimanager'),
|
||||
react_native_tests_target('java/org/mockito/configuration:configuration'),
|
||||
],
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC'
|
||||
],
|
||||
@@ -26,19 +26,18 @@ robolectric3_test(
|
||||
srcs = glob(STANDARD_TEST_SRCS),
|
||||
deps = [
|
||||
':testhelpers',
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
react_native_target('java/com/facebook/react/common:common'),
|
||||
react_native_target('java/com/facebook/react/uimanager:uimanager'),
|
||||
|
||||
react_native_dep('third-party/java/robolectric3/robolectric:robolectric'),
|
||||
react_native_dep('libraries/fbcore/src/test/java/com/facebook/powermock:powermock'),
|
||||
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
|
||||
react_native_dep('third-party/java/fest:fest'),
|
||||
react_native_dep('third-party/java/junit:junit'),
|
||||
react_native_dep('third-party/java/mockito:mockito'),
|
||||
react_native_dep('third-party/java/jackson:core'),
|
||||
react_native_dep('third-party/java/jackson:jackson'),
|
||||
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
||||
react_native_dep('libraries/fbcore/src/test/java/com/facebook/powermock:powermock'),
|
||||
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
|
||||
react_native_dep('third-party/java/junit:junit'),
|
||||
react_native_dep('third-party/java/mockito:mockito'),
|
||||
react_native_dep('third-party/java/robolectric3/robolectric:robolectric'),
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
react_native_target('java/com/facebook/react/common:common'),
|
||||
react_native_target('java/com/facebook/react/uimanager:uimanager'),
|
||||
],
|
||||
visibility = [
|
||||
'PUBLIC'
|
||||
|
||||
@@ -12,8 +12,6 @@ package com.facebook.react.bridge;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
@@ -82,12 +80,11 @@ public class JavaScriptModuleConfigTest {
|
||||
|
||||
private static String getModuleDescriptions(JavaScriptModulesConfig jsModulesConfig)
|
||||
throws IOException {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
StringWriter writer = new StringWriter();
|
||||
JsonGenerator jg = jsonFactory.createGenerator(writer);
|
||||
jsModulesConfig.writeModuleDescriptions(jg);
|
||||
jg.close();
|
||||
return writer.getBuffer().toString();
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter writer = new JsonWriter(stringWriter);
|
||||
jsModulesConfig.writeModuleDescriptions(writer);
|
||||
writer.close();
|
||||
return stringWriter.getBuffer().toString();
|
||||
}
|
||||
|
||||
private JsonNode parse(String json) throws Exception {
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class JsonWriterTest {
|
||||
private final StringWriter mStringWriter;
|
||||
private final JsonWriter mWriter;
|
||||
|
||||
public JsonWriterTest() {
|
||||
mStringWriter = new StringWriter();
|
||||
mWriter = new JsonWriter(mStringWriter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyObject() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.endObject();
|
||||
verify("{}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyNestedObject() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.beginObject();
|
||||
mWriter.endObject();
|
||||
mWriter.endObject();
|
||||
verify("{{}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyArray() throws IOException {
|
||||
mWriter.beginArray();
|
||||
mWriter.endArray();
|
||||
verify("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyNestedArray() throws IOException {
|
||||
mWriter.beginArray();
|
||||
mWriter.beginArray();
|
||||
mWriter.endArray();
|
||||
mWriter.endArray();
|
||||
verify("[[]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallObject() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.name("hello").value(true);
|
||||
mWriter.name("hello_again").value("hi!");
|
||||
mWriter.endObject();
|
||||
verify("{\"hello\":true,\"hello_again\":\"hi!\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallArray() throws IOException {
|
||||
mWriter.beginArray();
|
||||
mWriter.value(true);
|
||||
mWriter.value(1);
|
||||
mWriter.value(1.0);
|
||||
mWriter.value("hi!");
|
||||
mWriter.endArray();
|
||||
verify("[true,1,1.0,\"hi!\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void string() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.name("string").value("hello!");
|
||||
mWriter.endObject();
|
||||
verify("{\"string\":\"hello!\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complexString() throws IOException {
|
||||
mWriter.beginObject();
|
||||
mWriter.name("string").value("\t\uD83D\uDCA9");
|
||||
mWriter.endObject();
|
||||
verify("{\"string\":\"\\t\uD83D\uDCA9\"}");
|
||||
}
|
||||
|
||||
private void verify(String expected) throws IOException {
|
||||
mWriter.close();
|
||||
assertThat(mStringWriter.getBuffer().toString()).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,6 @@ import java.util.Map;
|
||||
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
@@ -189,12 +187,11 @@ public class NativeModuleRegistryTest {
|
||||
|
||||
private static String getModuleDescriptions(NativeModuleRegistry registry)
|
||||
throws IOException {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
StringWriter writer = new StringWriter();
|
||||
JsonGenerator jg = jsonFactory.createGenerator(writer);
|
||||
registry.writeModuleDescriptions(jg);
|
||||
jg.close();
|
||||
return writer.getBuffer().toString();
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JsonWriter writer = new JsonWriter(stringWriter);
|
||||
registry.writeModuleDescriptions(writer);
|
||||
writer.close();
|
||||
return stringWriter.getBuffer().toString();
|
||||
}
|
||||
|
||||
private static class MethodsModule extends BaseJavaModule {
|
||||
|
||||
Reference in New Issue
Block a user