Wednesday, April 09, 2008

Unit Testing Loaders

To unit test a loader, you first need to extend it so that the load method is exposed.  I usually just create a private static final class within the test class that I am using to test the loader.

private static final class ExposedFoodEvidenceLoader extends FoodEvidenceLoader {
    public void load(final RulesParameters rp) throws AppException, InformationalException {
        super.load(rp);
    }
}

In the actual test method, I just create the RDO instances and execute the loader.

final FoodEvidenceGroup foodEvidenceGroup = new FoodEvidenceGroup();
final ItemGroupGlobals itemGroupGlobals = new ItemGroupGlobals();
itemGroupGlobals.dateOfCalculation.setValue(Date.getCurrentDate()); 

final RulesParameters rulesParameters = new RulesParameters();
rulesParameters.addRDO(itemGroupGlobals, false);
rulesParameters.addRDO(foodEvidenceGroup, false);

new ExposedFoodEvidenceLoader().load(rulesParameters);

assertEquals(FOODTYPE.FILIPINO, foodEvidenceGroup.getfoodType().getValueNoLoad());

0 comments: