### Question:
SpriteBehaviorTemplate implements BehaviorTemplate<SpriteBehavior>, Sprite, Reflectable<SpriteClassInformation> { @Override public Map<String, Object> serialize() { Map<String, Object> theResult = new HashMap<>(); theResult.put(SpriteBehavior.TYPE_ATTRIBUTE, SpriteBehavior.TYPE); List<Map<String, Object>> theAnimations = new ArrayList<>(); for (Animation theAnimation : animations) { theAnimations.add(theAnimation.serialize()); } theResult.put("animations", theAnimations); if (!currentAnimation.isNull()) { theResult.put("currentAnimation", currentAnimation.get().getUuid()); } theResult.put("speed", Integer.toString(speed.get())); return theResult; } SpriteBehaviorTemplate(GameEventManager aEventManager, GameObject aOwner); @Override BehaviorType getType(); @Override SpriteClassInformation getClassInformation(); @Override GameObject getOwner(); @Override SpriteBehavior create(GameObjectInstance aInstance, GameRuntime aGameRuntime); @Override Property<Animation> currentAnimationProperty(); @Override Property<Integer> speedProperty(); void addAnimation(Animation aAnimation); @Override Map<String, Object> serialize(); @Override void delete(); @Override GameScene getGameScene(); @Override Animation[] getAnimations(); void replaceAnimation(Animation aOldAnimation, Animation aNewAnimation); static SpriteBehaviorTemplate deserialize(GameEventManager aEventManager, GameObject aOwner, Map<String, Object> aSerializedData); static final BehaviorType TYPE; }### Answer:
@Test public void testSerialize() throws Exception { GameEventManager theEventManager = mock(GameEventManager.class); GameObject theOwner = mock(GameObject.class); GameScene theScene = mock(GameScene.class); when(theOwner.getGameScene()).thenReturn(theScene); SpriteBehaviorTemplate theTemplate = new SpriteBehaviorTemplate(theEventManager, theOwner); Animation theOldAnimation = new Animation("Lala"); Animation theOldAnimation2 = new Animation("Lala2"); theTemplate.addAnimation(theOldAnimation); theTemplate.addAnimation(theOldAnimation2); theTemplate.currentAnimationProperty().set(theOldAnimation); Map<String, Object> theData = theTemplate.serialize(); assertEquals(4, theData.size()); assertEquals(SpriteBehavior.TYPE, theData.get(SpriteBehavior.TYPE_ATTRIBUTE)); assertEquals("5", theData.get("speed")); assertEquals(theOldAnimation.getUuid(), theData.get("currentAnimation")); List<Map<String, Object>> theAnimations = (List<Map<String, Object>>) theData.get("animations"); assertEquals(2, theAnimations.size()); assertEquals("Lala", Animation.deserialize(theAnimations.get(0)).getName()); assertEquals("Lala2", Animation.deserialize(theAnimations.get(1)).getName()); theTemplate.currentAnimationProperty().set(null); theData = theTemplate.serialize(); assertEquals(3, theData.size()); assertEquals(SpriteBehavior.TYPE, theData.get(SpriteBehavior.TYPE_ATTRIBUTE)); assertEquals("5", theData.get("speed")); theAnimations = (List<Map<String, Object>>) theData.get("animations"); assertEquals(2, theAnimations.size()); assertEquals("Lala", Animation.deserialize(theAnimations.get(0)).getName()); assertEquals("Lala2", Animation.deserialize(theAnimations.get(1)).getName()); }