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

Method testAddFeatAbility

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

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

()

Source from the content-addressed store, hash-verified

126 * @throws MalformedURLException
127 */
128 @Test
129 public void testAddFeatAbility() throws PersistenceLayerException, MalformedURLException
130 {
131 LoadContext context = Globals.getContext();
132 // Create some abilities to be added
133 Ability ab1 = new Ability();
134 ab1.setName("Ability1");
135 ab1.setCDOMCategory(BuildUtilities.getFeatCat());
136 context.getReferenceContext().importObject(ab1);
137 Ability ab2 = new Ability();
138 ab2.setName("Ability2");
139 ab2.setCDOMCategory(BuildUtilities.getFeatCat());
140 context.getReferenceContext().importObject(ab2);
141
142 CampaignSourceEntry source;
143 try
144 {
145 source = new CampaignSourceEntry(new Campaign(),
146 new URI("file:/" + getClass().getName() + ".java"));
147 }
148 catch (URISyntaxException e)
149 {
150 throw new UnreachableError(e);
151 }
152 loader
153 .parseLine(
154 context,
155 null,
156 "Template1 ABILITY:FEAT|AUTOMATIC|Ability1 ABILITY:FEAT|AUTOMATIC|Ability2", source);
157 PCTemplate template =
158 context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
159 context.getReferenceContext().importObject(ab1);
160 context.getReferenceContext().importObject(ab2);
161 CDOMSingleRef<AbilityCategory> acRef =
162 context.getReferenceContext().getCDOMReference(
163 AbilityCategory.class, "Feat");
164 assertTrue(context.getReferenceContext().resolveReferences(null));
165 CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
166 Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
167 assertEquals(2, listMods.size());
168 Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
169 CDOMReference<Ability> ref1 = iterator.next();
170 CDOMReference<Ability> ref2 = iterator.next();
171 Collection<Ability> contained1 = ref1.getContainedObjects();
172 Collection<Ability> contained2 = ref2.getContainedObjects();
173 assertEquals(1, contained1.size());
174 assertEquals(1, contained2.size());
175 assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
176 assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
177
178 // Add the template to the character
179 PlayerCharacter pc = getCharacter();
180 pc.addTemplate(template);
181 // Need to do this to populate the ability list
182 //pc.getAutomaticAbilityList(BuildUtilities.getFeatCat());
183 assertTrue("Character should have ability1.", hasAbility(pc, BuildUtilities.getFeatCat(),
184 Nature.AUTOMATIC, ab1));
185 assertTrue("Character should have ability2.", hasAbility(pc, BuildUtilities.getFeatCat(),

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected