Change class names to modules names in packages

Reviewed By: achen1

Differential Revision: D9508095

fbshipit-source-id: e3973ea417c803110eb8612c854a6374a849474b
This commit is contained in:
Ram N 2018-09-05 18:14:59 -07:00 committed by Facebook Github Bot
parent 5eaa2d29c0
commit 48169b28e2
12 changed files with 110 additions and 276 deletions

View File

@ -33,6 +33,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/modules/systeminfo:systeminfo"),
react_native_target("java/com/facebook/react/modules/toast:toast"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/views/imagehelper:imagehelper"),
],
exported_deps = [

View File

@ -84,7 +84,7 @@ public abstract class LazyReactPackage implements ReactPackage {
.flush();
ReactMarker.logMarker(
ReactMarkerConstants.CREATE_MODULE_START,
holder.getClassName());
holder.getName());
try {
nativeModule = holder.getProvider().get();
} finally {

View File

@ -5,23 +5,19 @@
package com.facebook.react;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.ModuleHolder;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.NativeModuleRegistry;
import com.facebook.react.bridge.OnBatchCompleteListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.model.ReactModuleInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Helper class to build NativeModuleRegistry.
@ -32,7 +28,6 @@ public class NativeModuleRegistryBuilder {
private final ReactInstanceManager mReactInstanceManager;
private final Map<String, ModuleHolder> mModules = new HashMap<>();
private final Map<String,String> namesToType = new HashMap<>();
public NativeModuleRegistryBuilder(
ReactApplicationContext reactApplicationContext,
@ -50,14 +45,14 @@ public class NativeModuleRegistryBuilder {
lazyReactPackage.getReactModuleInfoProvider().getReactModuleInfos();
for (ModuleSpec moduleSpec : moduleSpecs) {
String className = moduleSpec.getClassName();
ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(className);
String name = moduleSpec.getName();
ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(name);
ModuleHolder moduleHolder;
if (reactModuleInfo == null || eagerNativeModules.contains(className)) {
if (reactModuleInfo == null || eagerNativeModules.contains(name)) {
NativeModule module;
ReactMarker.logMarker(
ReactMarkerConstants.CREATE_MODULE_START,
moduleSpec.getClassName());
name);
try {
module = moduleSpec.getProvider().get();
} finally {
@ -68,8 +63,7 @@ public class NativeModuleRegistryBuilder {
moduleHolder = new ModuleHolder(reactModuleInfo, moduleSpec.getProvider());
}
String name = moduleHolder.getName();
putModuleTypeAndHolderToModuleMaps(className, name, moduleHolder);
putModuleTypeAndHolderToModuleMaps(name, moduleHolder);
}
} else {
FLog.d(
@ -93,23 +87,21 @@ public class NativeModuleRegistryBuilder {
public void addNativeModule(NativeModule nativeModule) {
String name = nativeModule.getName();
Class<? extends NativeModule> type = nativeModule.getClass();
putModuleTypeAndHolderToModuleMaps(type.getName(), name, new ModuleHolder(nativeModule));
putModuleTypeAndHolderToModuleMaps(name, new ModuleHolder(nativeModule));
}
private void putModuleTypeAndHolderToModuleMaps(
String className, String underName, ModuleHolder moduleHolder)
String name, ModuleHolder moduleHolder)
throws IllegalStateException {
if (namesToType.containsKey(underName)) {
String existingNativeModule = namesToType.get(underName);
if (mModules.containsKey(name)) {
ModuleHolder existingNativeModule = mModules.get(name);
if (!moduleHolder.getCanOverrideExistingModule()) {
throw new IllegalStateException(
"Native module "
+ className
+ name
+ " tried to override "
+ existingNativeModule
+ existingNativeModule.getClassName()
+ " for module name "
+ underName
+ ". Check the getPackages() method in MainApplication.java, it might be "
+ "that module is being created twice. "
+ "If this was your intention, set canOverrideExistingModule=true");
@ -118,8 +110,7 @@ public class NativeModuleRegistryBuilder {
mModules.remove(existingNativeModule);
}
namesToType.put(underName, className);
mModules.put(className, moduleHolder);
mModules.put(name, moduleHolder);
}
public NativeModuleRegistry build() {

View File

@ -41,6 +41,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/model:model"),
react_native_target("java/com/facebook/react/uimanager/common:common"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
] + ([react_native_target("jni/react/jni:jni")] if not IS_OSS_BUILD else []),
exported_deps = [
react_native_dep("java/com/facebook/jni:jni"),

View File

@ -49,14 +49,12 @@ public class JavaModuleWrapper {
private final JSInstance mJSInstance;
private final ModuleHolder mModuleHolder;
private final String mClassName;
private final ArrayList<NativeModule.NativeMethod> mMethods;
private final ArrayList<MethodDescriptor> mDescs;
public JavaModuleWrapper(JSInstance jsInstance, String className, ModuleHolder moduleHolder) {
public JavaModuleWrapper(JSInstance jsInstance, ModuleHolder moduleHolder) {
mJSInstance = jsInstance;
mModuleHolder = moduleHolder;
mClassName = className;
mMethods = new ArrayList<>();
mDescs = new ArrayList();
}

View File

@ -24,11 +24,12 @@ import javax.inject.Provider;
/**
* Holder to enable us to lazy create native modules.
*
* This works by taking a provider instead of an instance, when it is first required we'll create
* <p>This works by taking a provider instead of an instance, when it is first required we'll create
* and initialize it. Initialization currently always happens on the UI thread but this is due to
* change for performance reasons.
*
* Lifecycle events via a {@link LifecycleEventListener} will still always happen on the UI thread.
* <p>Lifecycle events via a {@link LifecycleEventListener} will still always happen on the UI
* thread.
*/
@DoNotStrip
public class ModuleHolder {
@ -38,9 +39,7 @@ public class ModuleHolder {
private final int mInstanceKey = sInstanceKeyCounter.getAndIncrement();
private final String mName;
private final boolean mCanOverrideExistingModule;
private final boolean mHasConstants;
private final boolean mIsCxxModule;
private final ReactModuleInfo mReactModuleInfo;
private @Nullable Provider<? extends NativeModule> mProvider;
// Outside of the constructur, these should only be checked or set when synchronized on this
@ -53,10 +52,8 @@ public class ModuleHolder {
public ModuleHolder(ReactModuleInfo moduleInfo, Provider<? extends NativeModule> provider) {
mName = moduleInfo.name();
mCanOverrideExistingModule = moduleInfo.canOverrideExistingModule();
mHasConstants = moduleInfo.hasConstants();
mProvider = provider;
mIsCxxModule = moduleInfo.isCxxModule();
mReactModuleInfo = moduleInfo;
if (moduleInfo.needsEagerInit()) {
mModule = create();
}
@ -64,19 +61,25 @@ public class ModuleHolder {
public ModuleHolder(NativeModule nativeModule) {
mName = nativeModule.getName();
mCanOverrideExistingModule = nativeModule.canOverrideExistingModule();
mHasConstants = true;
mIsCxxModule = CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass());
mReactModuleInfo =
new ReactModuleInfo(
nativeModule.getName(),
nativeModule.getClass().getSimpleName(),
nativeModule.canOverrideExistingModule(),
true,
true,
CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass()));
mModule = nativeModule;
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
}
/*
* Checks if mModule has been created, and if so tries to initialize the module unless another
* thread is already doing the initialization.
* If mModule has not been created, records that initialization is needed
*/
* Checks if mModule has been created, and if so tries to initialize the module unless another
* thread is already doing the initialization.
* If mModule has not been created, records that initialization is needed
*/
/* package */ void markInitializable() {
boolean shouldInitializeNow = false;
NativeModule module = null;
@ -109,14 +112,20 @@ public class ModuleHolder {
}
public boolean getCanOverrideExistingModule() {
return mCanOverrideExistingModule;
return mReactModuleInfo.canOverrideExistingModule();
}
public boolean getHasConstants() {
return mHasConstants;
return mReactModuleInfo.hasConstants();
}
public boolean isCxxModule() {return mIsCxxModule; }
public boolean isCxxModule() {
return mReactModuleInfo.isCxxModule();
}
public String getClassName() {
return mReactModuleInfo.className();
}
@DoNotStrip
public NativeModule getModule() {
@ -125,11 +134,12 @@ public class ModuleHolder {
synchronized (this) {
if (mModule != null) {
return mModule;
// if mModule has not been set, and no one is creating it. Then this thread should call create
// if mModule has not been set, and no one is creating it. Then this thread should call
// create
} else if (!mIsCreating) {
shouldCreate = true;
mIsCreating = true;
} else {
} else {
// Wait for mModule to be created by another thread
}
}
@ -163,8 +173,8 @@ public class ModuleHolder {
SoftAssertions.assertCondition(mModule == null, "Creating an already created module.");
ReactMarker.logMarker(CREATE_MODULE_START, mName, mInstanceKey);
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ModuleHolder.createModule")
.arg("name", mName)
.flush();
.arg("name", mName)
.flush();
PrinterHolder.getPrinter()
.logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
NativeModule module;
@ -172,7 +182,7 @@ public class ModuleHolder {
module = assertNotNull(mProvider).get();
mProvider = null;
boolean shouldInitializeNow = false;
synchronized(this) {
synchronized (this) {
mModule = module;
if (mInitializable && !mIsInitializing) {
shouldInitializeNow = true;
@ -190,8 +200,8 @@ public class ModuleHolder {
private void doInitialize(NativeModule module) {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ModuleHolder.initialize")
.arg("name", mName)
.flush();
.arg("name", mName)
.flush();
ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_START, mName, mInstanceKey);
try {
boolean shouldInitialize = false;
@ -204,7 +214,8 @@ public class ModuleHolder {
}
if (shouldInitialize) {
module.initialize();
// Once finished, set flags accordingly, but we don't expect anyone to wait for this to finish
// Once finished, set flags accordingly, but we don't expect anyone to wait for this to
// finish
// So no need to notify other threads
synchronized (this) {
mIsInitializing = false;

View File

@ -1,73 +1,45 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.facebook.react.bridge;
import com.facebook.react.common.build.ReactBuildConfig;
import java.lang.reflect.Constructor;
import com.facebook.common.logging.FLog;
import com.facebook.react.module.annotations.ReactModule;
import javax.annotation.Nullable;
import javax.inject.Provider;
/**
* A specification for a native module. This exists so that we don't have to pay the cost
* for creation until/if the module is used.
*
* If your module either has a default constructor or one taking ReactApplicationContext you can use
* {@link #simple(Class)} or {@link #simple(Class, ReactApplicationContext)}} methods.
* A specification for a native module. This exists so that we don't have to pay the cost for
* creation until/if the module is used.
*/
public class ModuleSpec {
private static final Class[] EMPTY_SIGNATURE = {};
private static final Class[] CONTEXT_SIGNATURE = { ReactApplicationContext.class };
private static final String TAG = "ModuleSpec";
private final @Nullable Class<? extends NativeModule> mType;
private final Provider<? extends NativeModule> mProvider;
private final String mClassName;
/**
* Simple spec for modules with a default constructor.
*/
public static ModuleSpec simple(final Class<? extends NativeModule> type) {
return new ModuleSpec(type, new ConstructorProvider(type, EMPTY_SIGNATURE) {
@Override
public NativeModule get() {
try {
return getConstructor(type, EMPTY_SIGNATURE).newInstance();
} catch (Exception e) {
throw new RuntimeException("ModuleSpec with class: " + type.getName(), e);
}
}
});
}
/**
* Simple spec for modules with a constructor taking ReactApplicationContext.
*/
public static ModuleSpec simple(
final Class<? extends NativeModule> type,
final ReactApplicationContext context) {
return new ModuleSpec(type, new ConstructorProvider(type, CONTEXT_SIGNATURE) {
@Override
public NativeModule get() {
try {
return getConstructor(type, CONTEXT_SIGNATURE).newInstance(context);
} catch (Exception e) {
throw new RuntimeException("ModuleSpec with class: " + type.getName(), e);
}
}
});
}
private final String mName;
public static ModuleSpec viewManagerSpec(Provider<? extends NativeModule> provider) {
return new ModuleSpec(null, provider);
return new ModuleSpec(provider);
}
public static ModuleSpec nativeModuleSpec(
Class<? extends NativeModule> type, Provider<? extends NativeModule> provider) {
return new ModuleSpec(provider, type.getName());
ReactModule annotation = type.getAnnotation(ReactModule.class);
if (annotation == null) {
FLog.w(
TAG,
"Could not find @ReactModule annotation on "
+ type.getName()
+ ". So creating the module eagerly to get the name. Consider adding an annotation to make this Lazy");
NativeModule nativeModule = provider.get();
return new ModuleSpec(provider, nativeModule.getName());
} else {
return new ModuleSpec(provider, annotation.name());
}
}
public static ModuleSpec nativeModuleSpec(
@ -75,50 +47,32 @@ public class ModuleSpec {
return new ModuleSpec(provider, className);
}
private ModuleSpec(
@Nullable Class<? extends NativeModule> type, Provider<? extends NativeModule> provider) {
mType = type;
mProvider = provider;
mClassName = type == null ? null : type.getName();
}
public ModuleSpec(Provider<? extends NativeModule> provider, String name) {
/**
* Called by View Managers
*
* @param provider
*/
private ModuleSpec(Provider<? extends NativeModule> provider) {
mType = null;
mProvider = provider;
mClassName = name;
mName = null;
}
private ModuleSpec(Provider<? extends NativeModule> provider, String name) {
mType = null;
mProvider = provider;
mName = name;
}
public @Nullable Class<? extends NativeModule> getType() {
return mType;
}
public String getClassName(){return mClassName;}
public String getName() {
return mName;
}
public Provider<? extends NativeModule> getProvider() {
return mProvider;
}
private static abstract class ConstructorProvider implements Provider<NativeModule> {
protected @Nullable Constructor<? extends NativeModule> mConstructor;
public ConstructorProvider(Class<? extends NativeModule> type, Class[] signature) {
if (ReactBuildConfig.DEBUG) {
try {
mConstructor = getConstructor(type, signature);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("No such constructor", e);
}
}
}
protected Constructor<? extends NativeModule> getConstructor(
Class<? extends NativeModule> mType,
Class[] signature) throws NoSuchMethodException {
if (mConstructor != null) {
return mConstructor;
} else {
return mType.getConstructor(signature);
}
}
}
}

View File

@ -8,6 +8,7 @@
package com.facebook.react.bridge;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.systrace.Systrace;
import java.util.ArrayList;
import java.util.Collection;
@ -44,10 +45,9 @@ public class NativeModuleRegistry {
JSInstance jsInstance) {
ArrayList<JavaModuleWrapper> javaModules = new ArrayList<>();
for (Map.Entry<String, ModuleHolder> entry : mModules.entrySet()) {
String type = entry.getKey();
if (!entry.getValue().isCxxModule()) {
//if (!CxxModuleWrapperBase.class.isAssignableFrom(entry.getValue().getModule().getClass())) {
javaModules.add(new JavaModuleWrapper(jsInstance, type, entry.getValue()));
javaModules.add(new JavaModuleWrapper(jsInstance, entry.getValue()));
}
}
return javaModules;
@ -120,19 +120,21 @@ public class NativeModuleRegistry {
// iterating over all the modules for find this one instance, and then calling it, we short-circuit
// the search, and simply call OnBatchComplete on the UI Manager.
// With Fabric, UIManager would no longer be a NativeModule, so this call would simply go away
ModuleHolder moduleHolder = mModules.get("com.facebook.react.uimanager.UIManagerModule");
ModuleHolder moduleHolder = mModules.get("UIManager");
if (moduleHolder != null && moduleHolder.hasInstance()) {
((OnBatchCompleteListener) moduleHolder.getModule()).onBatchComplete();
}
}
public <T extends NativeModule> boolean hasModule(Class<T> moduleInterface) {
return mModules.containsKey(moduleInterface.getName());
String name = moduleInterface.getAnnotation(ReactModule.class).name();
return mModules.containsKey(name);
}
public <T extends NativeModule> T getModule(Class<T> moduleInterface) {
String name = moduleInterface.getAnnotation(ReactModule.class).name();
return (T) Assertions.assertNotNull(
mModules.get(moduleInterface.getName()), moduleInterface.getSimpleName()).getModule();
mModules.get(name), moduleInterface.getSimpleName()).getModule();
}
public List<NativeModule> getAllModules() {

View File

@ -16,14 +16,17 @@ public class ReactModuleInfo {
private final boolean mNeedsEagerInit;
private final boolean mHasConstants;
private final boolean mIsCxxModule;
private String mClassName;
public ReactModuleInfo(
String name,
String className,
boolean canOverrideExistingModule,
boolean needsEagerInit,
boolean hasConstants,
boolean isCxxModule) {
mName = name;
mClassName = className;
mCanOverrideExistingModule = canOverrideExistingModule;
mNeedsEagerInit = needsEagerInit;
mHasConstants = hasConstants;
@ -34,6 +37,8 @@ public class ReactModuleInfo {
return mName;
}
public String className() {return mClassName;}
public boolean canOverrideExistingModule() {
return mCanOverrideExistingModule;
}

View File

@ -35,7 +35,6 @@ import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
@ -45,31 +44,6 @@ import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.facebook.infer.annotation.SuppressFieldNotInitialized;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.module.annotations.ReactModuleList;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.tools.Diagnostic.Kind.ERROR;
/**
* Generates a list of ReactModuleInfo for modules annotated with {@link ReactModule} in
@ -211,14 +185,15 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
String valueString = new StringBuilder()
.append("new ReactModuleInfo(")
.append("\"").append(reactModule.name()).append("\"").append(", ")
.append(reactModule.canOverrideExistingModule()).append(", ")
.append("\"").append(keyString).append("\"").append(", ")
.append(reactModule.canOverrideExistingModule()).append(", ")
.append(reactModule.needsEagerInit()).append(", ")
.append(hasConstants).append(", ")
.append(reactModule.isCxxModule())
.append(")")
.toString();
builder.addStatement("map.put(\"" + keyString + "\", " + valueString + ")");
builder.addStatement("map.put(\"" + reactModule.name() + "\", " + valueString + ")");
}
builder.addStatement("return map");
}

View File

@ -41,7 +41,7 @@ public class BaseJavaModuleTest {
@Before
public void setup() {
ModuleHolder moduleHolder = new ModuleHolder(new MethodsModule());
mWrapper = new JavaModuleWrapper(null, MethodsModule.class.getName(), moduleHolder);
mWrapper = new JavaModuleWrapper(null, moduleHolder);
mMethods = mWrapper.getMethodDescriptors();
PowerMockito.mockStatic(SoLoader.class);
mArguments = PowerMockito.mock(ReadableNativeArray.class);

View File

@ -1,104 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
import com.facebook.react.common.build.ReactBuildConfig;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.powermock.reflect.Whitebox;
import org.robolectric.RobolectricTestRunner;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
@SuppressStaticInitializationFor("com.facebook.react.common.build.ReactBuildConfig")
@PrepareForTest({ReactBuildConfig.class})
@RunWith(RobolectricTestRunner.class)
public class ModuleSpecTest {
@Rule
public PowerMockRule rule = new PowerMockRule();
@Test(expected = IllegalArgumentException.class)
public void testSimpleFailFast() {
Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
ModuleSpec.simple(ComplexModule.class, mock(ReactApplicationContext.class));
}
@Test(expected = IllegalArgumentException.class)
public void testSimpleFailFastDefault() {
Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
ModuleSpec.simple(ComplexModule.class);
}
@Test
public void testSimpleNoFailFastRelease() {
Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", false);
ModuleSpec.simple(ComplexModule.class, mock(ReactApplicationContext.class));
}
@Test(expected = RuntimeException.class)
public void testSimpleFailLateRelease() {
Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", false);
ModuleSpec spec = ModuleSpec.simple(ComplexModule.class, mock(ReactApplicationContext.class));
spec.getProvider().get();
}
@Test
public void testSimpleDefaultConstructor() {
Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
ModuleSpec spec = ModuleSpec.simple(SimpleModule.class);
assertThat(spec.getProvider().get()).isInstanceOf(SimpleModule.class);
}
@Test
public void testSimpleContextConstructor() {
Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
ReactApplicationContext context = mock(ReactApplicationContext.class);
ModuleSpec spec = ModuleSpec.simple(SimpleContextModule.class, context);
NativeModule module = spec.getProvider().get();
assertThat(module).isInstanceOf(SimpleContextModule.class);
SimpleContextModule contextModule = (SimpleContextModule) module;
assertThat(contextModule.getReactApplicationContext()).isSameAs(context);
}
public static class ComplexModule extends BaseJavaModule {
public ComplexModule(int a, int b) {
}
public String getName() {
return "ComplexModule";
}
}
public static class SimpleModule extends BaseJavaModule {
public String getName() {
return "SimpleModule";
}
}
public static class SimpleContextModule extends ReactContextBaseJavaModule {
public SimpleContextModule(ReactApplicationContext context) {
super(context);
}
public String getName() {
return "SimpleContextModule";
}
}
}