FormatterRegistry implements FormatterFactory { @Override public Formatter createFormatter(String name, List<String> args) throws UnknownFormatterException, FormatterInstantiationException { final Class<? extends Formatter> formatterClass = namedFormatters .get(name); if (formatterClass == null) { throw new UnknownFormatterException(name); } return createFormatter(formatterClass, args); } FormatterRegistry(); @SuppressWarnings("unchecked") @PostConstruct void initBuildInFormatter(); void registerClass(Class<? extends Formatter> someClass); boolean hasFormatter(String formatterName); @Override Formatter createFormatter(String name, List<String> args); @Override Formatter createDefaultFormatter(Class<?> type);  }
@Test public void twoArgFormatter() { TwoArgFormatter formatter = (TwoArgFormatter) FormatterRegistry .createFormatter(TwoArgFormatter.class, Arrays.asList("a", "b")); assertEquals("a", formatter.arg1); assertEquals("b", formatter.arg2); }
@Test public void enumArgFormatter() { EnumArgFormatter formatter = (EnumArgFormatter) FormatterRegistry .createFormatter(EnumArgFormatter.class, Arrays.asList("VALUE_1")); assertEquals(Simple.VALUE_1, formatter.value); }
@Test public void intArgFormatter() { IntArgFormatter formatter = (IntArgFormatter) FormatterRegistry .createFormatter(IntArgFormatter.class, Arrays.asList("23")); assertEquals(23, formatter.value); }