MCPcopy Create free account
hub / github.com/PCGen/pcgen / testAddAbility

Method testAddAbility

code/src/test/pcgen/core/PCTemplateTest.java:62–121  ·  view source on GitHub ↗

Test the definition and application of abilities. @throws PersistenceLayerException @throws MalformedURLException

()

Source from the content-addressed store, hash-verified

60 * @throws MalformedURLException
61 */
62 @Test
63 public void testAddAbility() throws PersistenceLayerException, MalformedURLException
64 {
65 LoadContext context = Globals.getContext();
66 // Create some abilities to be added
67 AbilityCategory cat = context.getReferenceContext().constructCDOMObject(
68 AbilityCategory.class, "TestCat");
69 Ability ab1 = new Ability();
70 ab1.setName("Ability1");
71 ab1.setCDOMCategory(cat);
72 context.getReferenceContext().importObject(ab1);
73 Ability ab2 = new Ability();
74 ab2.setName("Ability2");
75 ab2.setCDOMCategory(cat);
76 context.getReferenceContext().importObject(ab2);
77
78 CampaignSourceEntry source;
79 try
80 {
81 source = new CampaignSourceEntry(new Campaign(),
82 new URI("file:/" + getClass().getName() + ".java"));
83 }
84 catch (URISyntaxException e)
85 {
86 throw new UnreachableError(e);
87 }
88 loader
89 .parseLine(
90 context,
91 null,
92 "Template1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
93 PCTemplate template =
94 context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
95 context.getReferenceContext().importObject(ab1);
96 context.getReferenceContext().importObject(ab2);
97 CDOMSingleRef<AbilityCategory> acRef =
98 context.getReferenceContext().getCDOMReference(
99 AbilityCategory.class, "TestCat");
100 assertTrue(context.getReferenceContext().resolveReferences(null));
101 CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
102 Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
103 assertEquals(2, listMods.size());
104 Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
105 CDOMReference<Ability> ref1 = iterator.next();
106 CDOMReference<Ability> ref2 = iterator.next();
107 Collection<Ability> contained1 = ref1.getContainedObjects();
108 Collection<Ability> contained2 = ref2.getContainedObjects();
109 assertEquals(1, contained1.size());
110 assertEquals(1, contained2.size());
111 assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
112 assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
113
114 // Add the template to the character
115 PlayerCharacter pc = getCharacter();
116 pc.addTemplate(template);
117 assertTrue("Character should have ability1.", hasAbility(pc, cat,
118 Nature.AUTOMATIC, ab1));
119 assertTrue("Character should have ability2.", hasAbility(pc, cat,

Callers

nothing calls this directly

Calls 15

getContextMethod · 0.95
getReferenceContextMethod · 0.95
setCDOMCategoryMethod · 0.95
addTemplateMethod · 0.95
constructCDOMObjectMethod · 0.80
importObjectMethod · 0.80
getCDOMReferenceMethod · 0.80
getListModsMethod · 0.80
setNameMethod · 0.65
getNameMethod · 0.65

Tested by

no test coverage detected