/* * Copyright (c) 2007 Tom Parker <thpr@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package plugin.lsttokens.equipment; import org.junit.Test; import pcgen.cdom.enumeration.EqModControl; import pcgen.cdom.enumeration.ObjectKey; import pcgen.core.Equipment; import pcgen.persistence.PersistenceLayerException; import pcgen.rules.persistence.CDOMLoader; import pcgen.rules.persistence.token.CDOMPrimaryToken; import plugin.lsttokens.testsupport.AbstractCDOMTokenTestCase; import plugin.lsttokens.testsupport.CDOMTokenLoader; import plugin.lsttokens.testsupport.ConsolidationRule; public class ModsTokenTest extends AbstractCDOMTokenTestCase<Equipment> { static ModsToken token = new ModsToken(); static CDOMTokenLoader<Equipment> loader = new CDOMTokenLoader<Equipment>(); @Override public Class<Equipment> getCDOMClass() { return Equipment.class; } @Override public CDOMLoader<Equipment> getLoader() { return loader; } @Override public CDOMPrimaryToken<Equipment> getToken() { return token; } @Test public void testBadInputNegative() throws PersistenceLayerException { try { boolean parse = parse("INVALID"); assertFalse(parse); } catch (IllegalArgumentException e) { // OK } } @Test public void testBadInputEmpty() throws PersistenceLayerException { assertFalse(parse("")); assertNoSideEffects(); } @Test public void testRoundRobinYes() throws PersistenceLayerException { runRoundRobin("YES"); } @Test public void testRoundRobinNo() throws PersistenceLayerException { runRoundRobin("NO"); } @Test public void testRoundRobinRequired() throws PersistenceLayerException { runRoundRobin("REQUIRED"); } @Override protected String getAlternateLegalValue() { return "REQUIRED"; } @Override protected String getLegalValue() { return "YES"; } @Override protected ConsolidationRule getConsolidationRule() { return ConsolidationRule.OVERWRITE; } @Test public void testUnparseNull() throws PersistenceLayerException { primaryProf.put(getObjectKey(), null); assertNull(getToken().unparse(primaryContext, primaryProf)); } private ObjectKey<EqModControl> getObjectKey() { return ObjectKey.MOD_CONTROL; } @Test public void testUnparseLegal() throws PersistenceLayerException { primaryProf.put(getObjectKey(), EqModControl.REQUIRED); expectSingle(getToken().unparse(primaryContext, primaryProf), EqModControl.REQUIRED.toString()); } @SuppressWarnings("unchecked") @Test public void testUnparseGenericsFail() throws PersistenceLayerException { ObjectKey objectKey = getObjectKey(); primaryProf.put(objectKey, new Object()); try { getToken().unparse(primaryContext, primaryProf); fail(); } catch (ClassCastException e) { // Yep! } } }