### Question:
ModuleStateManagerImpl implements ModuleStateManager { @Override public Collection<String> detectModules(Node node) { Collection<String> moduleNames = New.set(); synchronized (myControllerMap) { for (Entry<String, List<Reference<ModuleStateController>>> entry : myControllerMap.entrySet()) { for (Reference<ModuleStateController> ref : entry.getValue()) { ModuleStateController moduleStateController = ref.get(); if (moduleStateController != null && moduleStateController.canActivateState(node) && !moduleStateController.isAlwaysActivateState()) { moduleNames.add(entry.getKey()); } } } } return moduleNames; } ModuleStateManagerImpl(PreferencesRegistry preferencesRegistry); @Override void deactivateAllStates(); @Override Collection<String> detectModules(Node node); @Override Collection<String> detectModules(StateType state); @Override Collection<? extends String> getActiveStateIds(); @Override Collection<? extends String> getModuleNames(); @Override Collection<? extends String> getModulesThatCanSaveState(); @Override Collection<? extends String> getModulesThatSaveStateByDefault(); @Override Collection<String> getRegisteredStateIds(); @Override StateType getState(String state); @Override Map<String, Collection<? extends String>> getStateDependenciesForModules(Collection<? extends String> modules); @Override String getStateDescription(String state); @Override Collection<? extends String> getStateTags(String state); @Override boolean isStateActive(String state); @Override void registerModuleStateController(String moduleName, ModuleStateController controller); @Override void registerState(String id, String description, Collection<? extends String> tags,
            Collection<? extends String> modules, Element element); @Override void registerState(String id, String description, Collection<? extends String> tags,
            Collection<? extends String> modules, StateType state); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
            Node parentNode); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
            StateType state); @Override void toggleState(String id); @Override void unregisterModuleStateController(String moduleName, ModuleStateController controller); @Override void unregisterState(String id);  }### Answer:
@Test public void testDetectModules() { Node node = EasyMock.createMock(Node.class); ModuleStateController controller1 = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller1.canActivateState(node))).andReturn(Boolean.TRUE).atLeastOnce(); ModuleStateController controller2 = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller2.canActivateState(node))).andReturn(Boolean.FALSE).atLeastOnce(); ModuleStateController controller3a = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller3a.canActivateState(node))).andReturn(Boolean.TRUE).atLeastOnce(); ModuleStateController controller3b = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller3b.canActivateState(node))).andReturn(Boolean.FALSE).atLeastOnce(); EasyMock.replay(node, controller1, controller2, controller3a, controller3b); ModuleStateManager manager = new ModuleStateManagerImpl((PreferencesRegistry)null); Collection<? extends String> moduleNames; moduleNames = manager.detectModules(node); Assert.assertTrue(moduleNames.isEmpty()); manager.registerModuleStateController(TWO, controller2); moduleNames = manager.detectModules(node); Assert.assertTrue(moduleNames.isEmpty()); manager.registerModuleStateController(ONE, controller1); moduleNames = manager.detectModules(node); Assert.assertEquals(1, moduleNames.size()); Assert.assertTrue(moduleNames.contains(ONE)); manager.registerModuleStateController(THREE, controller3a); manager.registerModuleStateController(THREE, controller3b); moduleNames = manager.detectModules(node); Assert.assertEquals(2, moduleNames.size()); Assert.assertTrue(moduleNames.contains(ONE)); Assert.assertTrue(moduleNames.contains(THREE)); EasyMock.verify(node, controller1, controller2, controller3a, controller3b); }