DynamicCommandSupport { public static List<Command> getRegisteredDynamicCommands() throws InstantiationException, IllegalAccessException, ClassNotFoundException { final List<Command> result = new LinkedList<Command>(); final ClassFinder finder = new ClassFinder(); finder.addClassPath(); final ClassFilter filter = new AndClassFilter( new NotClassFilter(new InterfaceOnlyClassFilter()), new SubclassClassFilter(DynamicCommand.class), new NotClassFilter(new AbstractClassFilter())); final Collection<ClassInfo> foundClasses = new ArrayList<ClassInfo>(); finder.findClasses(foundClasses, filter); for (final ClassInfo classInfo: foundClasses) { final Class<?> clasz = Class.forName(classInfo.getClassName()); final DynamicCommand generatedCommand = (DynamicCommand) clasz.newInstance(); result.add(generatedCommand); } final Command clear = new ClearSystemCommand(); result.add(clear); final ExitSystemCommand exit = new ExitSystemCommand(); result.add(exit); final VersionSystemCommand version = new VersionSystemCommand(); result.add(version); final Command help = new HelpSystemCommand(result); result.add(help); return result; }  static List<Command> getRegisteredDynamicCommands();  }
@Test public void testDynamicCommandLoader() throws InstantiationException, IllegalAccessException, ClassNotFoundException { List<Command> commands = null; assertThat(commands, is(nullValue())); commands = DynamicCommandSupport.getRegisteredDynamicCommands(); assertThat(commands, is(notNullValue())); assertThat(commands.size(), is(15)); }