CompositeReactPackage implements ReactPackage { @Override public List<Class<? extends JavaScriptModule>> createJSModules() { final Set<Class<? extends JavaScriptModule>> moduleSet = new HashSet<>(); for (ReactPackage reactPackage: mChildReactPackages) { for (Class<? extends JavaScriptModule> jsModule: reactPackage.createJSModules()) { moduleSet.add(jsModule); } } return new ArrayList(moduleSet); } CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage... args); @Override List<NativeModule> createNativeModules(ReactApplicationContext reactContext); @Override List<Class<? extends JavaScriptModule>> createJSModules(); @Override List<ViewManager> createViewManagers(ReactApplicationContext reactContext);  }
@Test public void testThatCreateJSModulesIsCalledOnAllPackages() { CompositeReactPackage composite = new CompositeReactPackage(packageNo1, packageNo2, packageNo3); composite.createJSModules(); verify(packageNo1).createJSModules(); verify(packageNo2).createJSModules(); verify(packageNo3).createJSModules(); }
@Test public void testThatCompositeReturnsASumOfJSModules() { CompositeReactPackage composite = new CompositeReactPackage(packageNo1, packageNo2); Class<? extends JavaScriptModule> moduleNo1 = mock(JavaScriptModuleNo1.class).getClass(); Class<? extends JavaScriptModule> moduleNo2 = mock(JavaScriptModuleNo2.class).getClass(); Class<? extends JavaScriptModule> moduleNo3 = mock(JavaScriptModuleNo3.class).getClass(); List<Class<? extends JavaScriptModule>> l1 = new ArrayList<>(); l1.add(moduleNo1); when(packageNo1.createJSModules()).thenReturn(l1); List<Class<? extends JavaScriptModule>> l2 = new ArrayList<>(); l2.add(moduleNo2); l2.add(moduleNo3); when(packageNo2.createJSModules()).thenReturn(l2); List<Class<? extends JavaScriptModule>> compositeModules = composite.createJSModules(); List<Class<? extends JavaScriptModule>> l3 = new ArrayList<>(); l3.add(moduleNo1); l3.add(moduleNo2); l3.add(moduleNo3); Set<Class<? extends JavaScriptModule>> expected = new HashSet<>(l3); Set<Class<? extends JavaScriptModule>> actual = new HashSet<>(compositeModules); assertEquals(expected, actual); }