private void setMagicTemplate(Element generalElement, GenericCharacterTemplate characterTemplate)
     throws PersistenceException {
   Element magicTemplateElement = generalElement.element(TAG_MAGIC_TEMPLATE);
   if (magicTemplateElement == null) {
     return;
   }
   GenericMagicTemplateParser parser =
       new GenericMagicTemplateParser(
           registryCollection.getMagicTemplateRegistry(), characterTemplate);
   GenericMagicTemplate template = parser.parseTemplate(magicTemplateElement);
   characterTemplate.setMagicTemplate(template);
 }
 @Test
 public void testDefaultFreePicksPredicate() throws Exception {
   Element templateElement = DocumentUtilities.read(xml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertTrue(
       template.canBuyFromFreePicks(
           DummyCharmUtilities.createCharm("TestCharm", "Group"))); // $NON-NLS-1$ //$NON-NLS-2$
 }
 @Test
 public void testMortalCharmTemplate() throws Exception {
   Element templateElement = DocumentUtilities.read(xml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   ICharmTemplate charmTemplate = template.getCharmTemplate();
   assertEquals(MartialArtsLevel.Mortal, charmTemplate.getMartialArtsRules().getStandardLevel());
   assertFalse(charmTemplate.canLearnCharms());
 }
 @Test
 public void testFavoringTraitTypeModified() throws Exception {
   String typeXml =
       "<magicTemplate>" //$NON-NLS-1$
           + "<freePicksPredicate type=\"Default\"/>" //$NON-NLS-1$
           + "<favoringTraitType type =\"AttributeType\"/>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(typeXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertEquals(FavoringTraitType.AttributeType, template.getFavoringTraitType());
 }
 @Test
 public void picksUpMartialArtsRules() throws Exception {
   String celestialXml =
       "<magicTemplate>"
           + //$NON-NLS-1$
           "<charmTemplate charmType=\"None\" ><martialArts rulesClass=\"net.sf.anathema.character.generic.dummy.magic.DummyMartialArtsRules\" level=\"Terrestrial\" /></charmTemplate>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(celestialXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   Assert.assertTrue(
       template.getCharmTemplate().getMartialArtsRules() instanceof DummyMartialArtsRules);
 }
 @Test
 public void testDefaultRulesSetting() throws Exception {
   String celestialXml =
       "<magicTemplate>"
           + //$NON-NLS-1$
           "<charmTemplate charmType=\"None\" ><martialArts level=\"Terrestrial\" /></charmTemplate>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(celestialXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   Assert.assertTrue(
       template.getCharmTemplate().getMartialArtsRules() instanceof DefaultMartialArtsRules);
 }
 @Test
 public void testFalseFreePicksPredicate() throws Exception {
   String customXml =
       "<magicTemplate>" //$NON-NLS-1$
           + "<freePicksPredicate defaultResponse=\"false\"/>" //$NON-NLS-1$
           + "<charmTemplate charmType=\"None\">" //$NON-NLS-1$
           + "<martialArts level=\"Mortal\"/></charmTemplate>" //$NON-NLS-1$
           + "<spellTemplate maximumSorceryCircle=\"None\" maximumNecromancyCircle=\"None\"/>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(customXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertFalse(
       template.canBuyFromFreePicks(
           DummyCharmUtilities.createCharm("TestCharm", "Group"))); // $NON-NLS-1$ //$NON-NLS-2$
 }
 @Test
 public void testAlienCharmsAllowed() throws Exception {
   String typeXml =
       "<magicTemplate>" //$NON-NLS-1$
           + "<charmTemplate charmType=\"None\">" //$NON-NLS-1$
           + " <alienCharms> <caste type=\"DummyCaste\"/></alienCharms>" //$NON-NLS-1$
           + "<martialArts level=\"Celestial\" highLevel=\"false\" />" //$NON-NLS-1$
           + "</charmTemplate>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(typeXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertTrue(
       template
           .getCharmTemplate()
           .isAllowedAlienCharms(new DummyCasteType("DummyCaste"))); // $NON-NLS-1$
 }
 @Test
 public void testParsesMaximumNecromancyCircle() throws Exception {
   String celestialXml =
       "<magicTemplate>"
           + //$NON-NLS-1$
           "<spellTemplate maximumSorceryCircle=\"Solar\" maximumNecromancyCircle=\"Labyrinth\"/>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(celestialXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertTrue(
       net.sf.anathema.lib.lang.ArrayUtilities.containsValue(
           template.getSpellMagic().getNecromancyCircles(), CircleType.Shadowlands));
   assertTrue(
       net.sf.anathema.lib.lang.ArrayUtilities.containsValue(
           template.getSpellMagic().getNecromancyCircles(), CircleType.Labyrinth));
   assertFalse(
       net.sf.anathema.lib.lang.ArrayUtilities.containsValue(
           template.getSpellMagic().getNecromancyCircles(), CircleType.Void));
 }
 @Test
 public void testHighLevelSettingModified() throws Exception {
   String celestialXml =
       "<magicTemplate>"
           + //$NON-NLS-1$
           "<charmTemplate charmType=\"None\" ><martialArts level=\"Terrestrial\" highLevel=\"true\"/></charmTemplate>" //$NON-NLS-1$
           + "</magicTemplate>"; //$NON-NLS-1$
   Element templateElement = DocumentUtilities.read(celestialXml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   DummyCharm dummyMartialArtsCharm = new DummyCharm("Dummy") { // $NON-NLS-1$
         @Override
         public boolean hasAttribute(Identified attribute) {
           return attribute.getId().equals("MartialArts")
               || attribute.getId().equals("Celestial"); // $NON-NLS-1$ //$NON-NLS-2$
         }
       };
   assertTrue(
       template
           .getCharmTemplate()
           .getMartialArtsRules()
           .isCharmAllowed(dummyMartialArtsCharm, null, false));
 }
 @Test
 public void testFavoringTraitTypeUnmodified() throws Exception {
   Element templateElement = DocumentUtilities.read(xml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertEquals(FavoringTraitType.AbilityType, template.getFavoringTraitType());
 }
 @Test
 public void testMortalSpellTemplate() throws Exception {
   Element templateElement = DocumentUtilities.read(xml).getRootElement();
   GenericMagicTemplate template = parser.parseTemplate(templateElement);
   assertFalse(template.getSpellMagic().canLearnSpellMagic());
 }