### Question:
CompositeReactPackage implements ViewManagerOnDemandReactPackage, ReactPackage { @Override public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { final Map<String, NativeModule> moduleMap = new HashMap<>(); for (ReactPackage reactPackage : mChildReactPackages) { for (NativeModule nativeModule : reactPackage.createNativeModules(reactContext)) { moduleMap.put(nativeModule.getName(), nativeModule); } } return new ArrayList<>(moduleMap.values()); } CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage... args); @Override List<NativeModule> createNativeModules(ReactApplicationContext reactContext); @Override List<ViewManager> createViewManagers(ReactApplicationContext reactContext); @Override List<String> getViewManagerNames(ReactApplicationContext reactContext); @Override @Nullable ViewManager createViewManager(
      ReactApplicationContext reactContext, String viewManagerName);  }### Answer:
@Test public void testThatCreateNativeModulesIsCalledOnAllPackages() { CompositeReactPackage composite = new CompositeReactPackage(packageNo1, packageNo2, packageNo3); composite.createNativeModules(reactContext); verify(packageNo1).createNativeModules(reactContext); verify(packageNo2).createNativeModules(reactContext); verify(packageNo3).createNativeModules(reactContext); }
@Test public void testThatCompositeReturnsASumOfNativeModules() { CompositeReactPackage composite = new CompositeReactPackage(packageNo1, packageNo2); NativeModule moduleNo1 = mock(NativeModule.class); when(moduleNo1.getName()).thenReturn("ModuleNo1"); final String sameModuleName = "SameModuleName"; NativeModule moduleNo2 = mock(NativeModule.class); when(moduleNo2.getName()).thenReturn(sameModuleName); NativeModule moduleNo3 = mock(NativeModule.class); when(moduleNo3.getName()).thenReturn(sameModuleName); NativeModule moduleNo4 = mock(NativeModule.class); when(moduleNo4.getName()).thenReturn("ModuleNo4"); when(packageNo1.createNativeModules(reactContext)).thenReturn( Arrays.asList(new NativeModule[]{moduleNo1, moduleNo2})); when(packageNo2.createNativeModules(reactContext)).thenReturn( Arrays.asList(new NativeModule[]{moduleNo3, moduleNo4})); List<NativeModule> compositeModules = composite.createNativeModules(reactContext); Set<NativeModule> expected = new HashSet<>( Arrays.asList(new NativeModule[]{moduleNo1, moduleNo3, moduleNo4})); Set<NativeModule> actual = new HashSet<>(compositeModules); assertEquals(expected, actual); }