@Test public void get_by_type_not_found() { Translator string = mockTranslator("string", String.class); Translator bool = mockTranslator("bool", Boolean.class); Map<Class, Translator> configuration = CollectionFactory.newMap(); configuration.put(String.class, string); configuration.put(Boolean.class, bool); replay(); TranslatorSource source = new TranslatorSourceImpl(configuration); try { source.getByType(Integer.class); unreachable(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "No translator is defined for type java.lang.Integer. Registered types: java.lang.Boolean, java.lang.String."); } verify(); }
public Translator getByType(Class valueType) { Translator result = registry.get(valueType); if (result == null) { List<String> names = CollectionFactory.newList(); for (Class type : registry.getTypes()) { names.add(type.getName()); } throw new IllegalArgumentException(String.format("No translator is defined for type %s. Registered types: %s.", PlasticUtils.toTypeName(valueType), InternalUtils .joinSorted(names))); } return result; }
TranslatorSourceImpl implements TranslatorSource, Runnable { public Translator getByType(Class valueType) { Translator result = registry.get(valueType); if (result == null) { List<String> names = CollectionFactory.newList(); for (Class type : registry.getTypes()) { names.add(type.getName()); } throw new IllegalArgumentException(String.format("No translator is defined for type %s. Registered types: %s.", PlasticUtils.toTypeName(valueType), InternalUtils .joinSorted(names))); } return result; } }
TranslatorSourceImpl implements TranslatorSource, Runnable { public Translator getByType(Class valueType) { Translator result = registry.get(valueType); if (result == null) { List<String> names = CollectionFactory.newList(); for (Class type : registry.getTypes()) { names.add(type.getName()); } throw new IllegalArgumentException(String.format("No translator is defined for type %s. Registered types: %s.", PlasticUtils.toTypeName(valueType), InternalUtils .joinSorted(names))); } return result; } TranslatorSourceImpl(Map<Class, Translator> configuration);  TranslatorSourceImpl(Map<Class, Translator> configuration, Map<String, Translator> alternates); }
TranslatorSourceImpl implements TranslatorSource, Runnable { public Translator getByType(Class valueType) { Translator result = registry.get(valueType); if (result == null) { List<String> names = CollectionFactory.newList(); for (Class type : registry.getTypes()) { names.add(type.getName()); } throw new IllegalArgumentException(String.format("No translator is defined for type %s. Registered types: %s.", PlasticUtils.toTypeName(valueType), InternalUtils .joinSorted(names))); } return result; } TranslatorSourceImpl(Map<Class, Translator> configuration);  TranslatorSourceImpl(Map<Class, Translator> configuration, Map<String, Translator> alternates); Translator get(String name); Translator getByType(Class valueType); Translator findByType(Class valueType); void run(); }
TranslatorSourceImpl implements TranslatorSource, Runnable { public Translator getByType(Class valueType) { Translator result = registry.get(valueType); if (result == null) { List<String> names = CollectionFactory.newList(); for (Class type : registry.getTypes()) { names.add(type.getName()); } throw new IllegalArgumentException(String.format("No translator is defined for type %s. Registered types: %s.", PlasticUtils.toTypeName(valueType), InternalUtils .joinSorted(names))); } return result; } TranslatorSourceImpl(Map<Class, Translator> configuration);  TranslatorSourceImpl(Map<Class, Translator> configuration, Map<String, Translator> alternates); Translator get(String name); Translator getByType(Class valueType); Translator findByType(Class valueType); void run();  }