@Test public void testUnmarshall() 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"); 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)); IORegistry theRegistry = new IORegistry(); GameScene theScene2 = mock(GameScene.class); GameRuntime theRuntime2 = mock(GameRuntime.class); GameEventManager theManager2 = mock(GameEventManager.class); when(theScene2.getRuntime()).thenReturn(theRuntime2); when(theRuntime2.getEventManager()).thenReturn(theManager2); EventSheet theDeserialized = EventSheet.unmarshall(theRegistry, theScene2, theData); assertEquals("name", theDeserialized.nameProperty().get()); assertEquals(1, theDeserialized.getRules().length); assertTrue(theDeserialized.getRules()[0] instanceof GameRule); }
public static EventSheet unmarshall(IORegistry aIORegistry, GameScene aGameScene, Map<String, Object> aSerializedData) { EventSheet theResult = new EventSheet(aGameScene); String theName = (String) aSerializedData.get(NAME_PROPERTY); theResult.nameProperty.setQuietly(theName); List<Map<String, Object>> theRules = (List<Map<String, Object>>) aSerializedData.get("rules"); List<GameRule> theRuleList = new ArrayList<>(); if (theRules != null) { for (Map<String, Object> theRuleData : theRules) { theRuleList.add(GameRule.deserialize(aIORegistry, theResult, theRuleData)); } } theResult.rules = theRuleList.toArray(new GameRule[theRuleList.size()]); return theResult; }
EventSheet { public static EventSheet unmarshall(IORegistry aIORegistry, GameScene aGameScene, Map<String, Object> aSerializedData) { EventSheet theResult = new EventSheet(aGameScene); String theName = (String) aSerializedData.get(NAME_PROPERTY); theResult.nameProperty.setQuietly(theName); List<Map<String, Object>> theRules = (List<Map<String, Object>>) aSerializedData.get("rules"); List<GameRule> theRuleList = new ArrayList<>(); if (theRules != null) { for (Map<String, Object> theRuleData : theRules) { theRuleList.add(GameRule.deserialize(aIORegistry, theResult, theRuleData)); } } theResult.rules = theRuleList.toArray(new GameRule[theRuleList.size()]); return theResult; } }
EventSheet { public static EventSheet unmarshall(IORegistry aIORegistry, GameScene aGameScene, Map<String, Object> aSerializedData) { EventSheet theResult = new EventSheet(aGameScene); String theName = (String) aSerializedData.get(NAME_PROPERTY); theResult.nameProperty.setQuietly(theName); List<Map<String, Object>> theRules = (List<Map<String, Object>>) aSerializedData.get("rules"); List<GameRule> theRuleList = new ArrayList<>(); if (theRules != null) { for (Map<String, Object> theRuleData : theRules) { theRuleList.add(GameRule.deserialize(aIORegistry, theResult, theRuleData)); } } theResult.rules = theRuleList.toArray(new GameRule[theRuleList.size()]); return theResult; } EventSheet(GameScene aGameScene); }
EventSheet { public static EventSheet unmarshall(IORegistry aIORegistry, GameScene aGameScene, Map<String, Object> aSerializedData) { EventSheet theResult = new EventSheet(aGameScene); String theName = (String) aSerializedData.get(NAME_PROPERTY); theResult.nameProperty.setQuietly(theName); List<Map<String, Object>> theRules = (List<Map<String, Object>>) aSerializedData.get("rules"); List<GameRule> theRuleList = new ArrayList<>(); if (theRules != null) { for (Map<String, Object> theRuleData : theRules) { theRuleList.add(GameRule.deserialize(aIORegistry, theResult, theRuleData)); } } theResult.rules = theRuleList.toArray(new GameRule[theRuleList.size()]); 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); }
EventSheet { public static EventSheet unmarshall(IORegistry aIORegistry, GameScene aGameScene, Map<String, Object> aSerializedData) { EventSheet theResult = new EventSheet(aGameScene); String theName = (String) aSerializedData.get(NAME_PROPERTY); theResult.nameProperty.setQuietly(theName); List<Map<String, Object>> theRules = (List<Map<String, Object>>) aSerializedData.get("rules"); List<GameRule> theRuleList = new ArrayList<>(); if (theRules != null) { for (Map<String, Object> theRuleData : theRules) { theRuleList.add(GameRule.deserialize(aIORegistry, theResult, theRuleData)); } } theResult.rules = theRuleList.toArray(new GameRule[theRuleList.size()]); 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; }