mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-13 09:21:46 +08:00
Remove JS config completely
Reviewed By: astreet Differential Revision: D3276230 fbshipit-source-id: b3ab7e7dc149696b7db1049613fbb6a2a19bc8fb
This commit is contained in:
committed by
Facebook Github Bot 2
parent
4a7f2192f9
commit
0934470676
@@ -1,95 +0,0 @@
|
||||
/**
|
||||
* 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 com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class JavaScriptModuleConfigTest {
|
||||
|
||||
private static interface SomeModule extends JavaScriptModule {
|
||||
public void stringMethod(String arg);
|
||||
public void intMethod(int arg);
|
||||
}
|
||||
|
||||
private static interface OtherModule extends JavaScriptModule {
|
||||
public void method(String arg1, int arg2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModuleWithMethods() throws Exception {
|
||||
JavaScriptModulesConfig jsModulesConfig = new JavaScriptModulesConfig.Builder()
|
||||
.add(SomeModule.class)
|
||||
.build();
|
||||
|
||||
String json = getModuleDescriptions(jsModulesConfig);
|
||||
JsonNode node = parse(json);
|
||||
assertThat(node).hasSize(1);
|
||||
|
||||
JsonNode module = node.fields().next().getValue();
|
||||
assertThat(module).isNotNull();
|
||||
|
||||
JsonNode methods = module.get("methods");
|
||||
assertThat(methods)
|
||||
.isNotNull()
|
||||
.hasSize(2);
|
||||
|
||||
JsonNode intMethodNode = methods.get("intMethod");
|
||||
assertThat(intMethodNode).isNotNull();
|
||||
assertThat(intMethodNode.get("methodID").asText()).isEqualTo("intMethod");
|
||||
|
||||
JsonNode stringMethod = methods.get("stringMethod");
|
||||
assertThat(stringMethod).isNotNull();
|
||||
assertThat(stringMethod.get("methodID").asText()).isEqualTo("stringMethod");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleModules() throws Exception {
|
||||
JavaScriptModulesConfig jsModulesConfig = new JavaScriptModulesConfig.Builder()
|
||||
.add(OtherModule.class)
|
||||
.add(SomeModule.class)
|
||||
.build();
|
||||
|
||||
String json = getModuleDescriptions(jsModulesConfig);
|
||||
JsonNode node = parse(json);
|
||||
assertThat(node).hasSize(2);
|
||||
|
||||
JsonNode someModuleNode = node.get("SomeModule");
|
||||
assertThat(someModuleNode).isNotNull();
|
||||
String someModuleID = someModuleNode.get("moduleID").asText();
|
||||
|
||||
JsonNode otherModuleNode = node.get("OtherModule");
|
||||
assertThat(otherModuleNode).isNotNull();
|
||||
String otherModuleID = otherModuleNode.get("moduleID").asText();
|
||||
assertThat(otherModuleID)
|
||||
.isNotEqualTo(someModuleID);
|
||||
}
|
||||
|
||||
private static String getModuleDescriptions(JavaScriptModulesConfig jsModulesConfig)
|
||||
throws IOException {
|
||||
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 {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readTree(json);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user