Using reflection in Java, I've written some code to iterate through an arraylist of the names of classes I want enabled, instantiate them and in turn invoke a method with the common name 'parse(String)' within each.
for (String parser : enabledParses)
{
Class<?> parserClass = Class.forname(String.format"%s.%s", parserDirectoryPath, parser));
Method parseMethod = parserClass.getMethod("parse", String.class);
Object parserObj = null;
switch (parser)
{
case "parser1" :
parserObj = parserClass.getConstructor(ConfigWrapper.class, Alerter.class).newInstance(config, alerter);
break;
...
...
...
}
parseMethod.invoke(pluginObj, stringToParse);
When testing, how can I check to see that the parse() method has been called for each of the enabled parsers?
Thanks!
Aucun commentaire:
Enregistrer un commentaire