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

Method testAddAbility

code/src/test/pcgen/core/PObjectTest.java:318–379  ·  view source on GitHub ↗

Test the definition and application of abilities. @throws PersistenceLayerException

()

Source from the content-addressed store, hash-verified

316 * @throws PersistenceLayerException
317 */
318 @Test
319 public void testAddAbility() throws PersistenceLayerException
320 {
321 // Create some abilities to be added
322 LoadContext context = Globals.getContext();
323 AbilityCategory cat = context.getReferenceContext().constructCDOMObject(
324 AbilityCategory.class, "TestCat");
325 new AbilityCategoryLoader().parseLine(context, "TestCat\tCATEGORY:TestCat", null);
326 Ability ab1 = new Ability();
327 ab1.setName("Ability1");
328 ab1.setCDOMCategory(SettingsHandler.getGameAsProperty().get().getAbilityCategory("TestCat"));
329 Ability ab2 = new Ability();
330 ab2.setName("Ability2");
331 ab2.setCDOMCategory(SettingsHandler.getGameAsProperty().get().getAbilityCategory("TestCat"));
332 context.getReferenceContext().importObject(ab1);
333 context.getReferenceContext().importObject(ab2);
334
335 // Link them to a template
336 Race race = new Race();
337 CampaignSourceEntry source;
338 try
339 {
340 source = new CampaignSourceEntry(new Campaign(),
341 new URI("file:/" + getClass().getName() + ".java"));
342 }
343 catch (URISyntaxException e)
344 {
345 throw new UnreachableError(e);
346 }
347 GenericLoader<Race> loader = new GenericLoader<>(Race.class);
348 loader
349 .parseLine(
350 context,
351 race,
352 "Race1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
353 context.getReferenceContext().importObject(ab1);
354 context.getReferenceContext().importObject(ab2);
355 CDOMSingleRef<AbilityCategory> acRef =
356 context.getReferenceContext().getCDOMReference(
357 AbilityCategory.class, "TestCat");
358 assertTrue(context.getReferenceContext().resolveReferences(null));
359 CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
360 Collection<CDOMReference<Ability>> listMods = race.getListMods(autoList);
361 assertEquals(2, listMods.size());
362 Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
363 CDOMReference<Ability> ref1 = iterator.next();
364 CDOMReference<Ability> ref2 = iterator.next();
365 Collection<Ability> contained1 = ref1.getContainedObjects();
366 Collection<Ability> contained2 = ref2.getContainedObjects();
367 assertEquals(1, contained1.size());
368 assertEquals(1, contained2.size());
369 assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
370 assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
371
372 // Add the template to the character
373 PlayerCharacter pc = getCharacter();
374 pc.setRace(race);
375 assertTrue("Character should have ability1.", hasAbility(pc, cat,

Callers

nothing calls this directly

Calls 15

getContextMethod · 0.95
getReferenceContextMethod · 0.95
setCDOMCategoryMethod · 0.95
getGameAsPropertyMethod · 0.95
parseLineMethod · 0.95
setRaceMethod · 0.95
constructCDOMObjectMethod · 0.80
importObjectMethod · 0.80
getCDOMReferenceMethod · 0.80
getListModsMethod · 0.80
parseLineMethod · 0.65

Tested by

no test coverage detected