### Question:
StateControllerImpl implements StateController { @Override public void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules, boolean saveToApplication, OutputStream outputStream) { StateType state = new StateType(); myModuleStateManager.saveState(id, description, tags, modules, state); if (outputStream != null) { try { new StateV4ReaderWriter().write(state, outputStream); } catch (JAXBException e) { LOGGER.error(e, e); } } if (saveToApplication) { myModuleStateManager.registerState(id, description, tags, modules, state); hookState(id, state); } } StateControllerImpl(Toolbox toolbox); @Override void deactivateAllStates(); @Override Collection<? extends String> getAvailableModules(); @Override Collection<? extends String> getAvailableStates(); @Override Collection<? extends String> getModulesThatCanSaveState(); @Override Collection<? extends String> getModulesThatSaveStateByDefault(); @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 removeStates(Collection<? extends String> stateIds); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
            boolean saveToApplication, OutputStream outputStream); @Override void toggleState(String id); @Override void hookState(String id, StateType state);  }### Answer:
@Test public void testSaveState() throws SAXException, IOException, ParserConfigurationException { ModuleStateManager moduleStateManager = EasyMock.createMock(ModuleStateManager.class); String id = "stateid"; String description = "State description"; Collection<? extends String> tags = Arrays.asList("tag1", "tag2", "tag3"); @SuppressWarnings("unchecked") Collection<? extends String> modules = EasyMock.createMock(Collection.class); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final Capture<StateType> stateCapture = EasyMock.newCapture(); moduleStateManager.saveState(EasyMock.eq(id), EasyMock.eq(description), EasyMock.same(tags), EasyMock.same(modules), EasyMock.isA(StateType.class)); EasyMock.expectLastCall().andAnswer(new IAnswer<Void>() { @Override public Void answer() { StateType state = (StateType)EasyMock.getCurrentArguments()[4]; stateCapture.setValue(state); return null; } }); moduleStateManager.registerState(EasyMock.eq(id), EasyMock.eq(description), EasyMock.same(tags), EasyMock.same(modules), EasyMockHelper.eq(stateCapture)); EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = createToolbox(support, moduleStateManager); Collection<String> idCollection = New.collection(); EasyMock.expect(moduleStateManager.getRegisteredStateIds()).andReturn(idCollection); EasyMock.replay(moduleStateManager, modules); support.replayAll(); StateControllerImpl controller = new StateControllerImpl(toolbox); controller.saveState(id, description, tags, modules, true, outputStream); support.verifyAll(); EasyMock.verify(moduleStateManager, modules); XMLUtilities.newDocumentBuilderNS().parse(new ByteArrayInputStream(outputStream.toByteArray())); }