### Question:
EventSheet { public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(NAME_PROPERTY, nameProperty.get()); List<Map<String, Object>> theRuleList = new ArrayList<>(); for (GameRule theRule : rules) { theRuleList.add(theRule.serialize()); } theResult.put("rules", theRuleList); return theResult; } EventSheet(GameScene aGameScene); GameScene getGameScene(); Property<String> nameProperty(); GameRule[] getRules(); Map<String, Object> serialize(); static EventSheet unmarshall(IORegistry aIORegistry, GameScene aGameScene, Map<String, Object> aSerializedData); void addRule(GameRule aNewRule); void removeRule(GameRule aGameRule); static final String NAME_PROPERTY; }### Answer:
@Test public void testSerialize() throws Exception { GameScene theScene = mock(GameScene.class); GameRuntime theRuntime = mock(GameRuntime.class); GameEventManager theManager = mock(GameEventManager.class); when(theScene.getRuntime()).thenReturn(theRuntime); when(theRuntime.getEventManager()).thenReturn(theManager); EventSheet theSheet = new EventSheet(theScene); theSheet.nameProperty().set("name"); verify(theManager).handleGameEvent(any(PropertyChanged.class)); GameRule theRule = new GameRule(); theSheet.addRule(theRule); assertEquals(1, theSheet.getRules().length); assertSame(theRule, theSheet.getRules()[0]); Map<String, Object> theData = theSheet.serialize(); assertEquals(2, theData.size()); assertEquals("name", theData.get(EventSheet.NAME_PROPERTY)); List<Map<String, Object>> theRules = (List<Map<String, Object>>) theData.get("rules"); assertEquals(1, theRules.size()); Map<String, Object> theFirstRule = theRules.get(0); assertEquals(1, theFirstRule.size()); }