### Question:
SourceTargetTypeConverterFactoryLookup implements TypeConverterFactoryLookup<S, T> { @Override public TypeConverterFactory<S, T> apply(final Map<Object, Object> registryEntries) { final Set<TypeConverterFactory<?, ?>> typeConverterFactories = (Set<TypeConverterFactory<?, ?>>) registryEntries.get(TYPE_CONVERTER_FACTORY_REGISTRY_KEY); return lookup(typeConverterFactories); } SourceTargetTypeConverterFactoryLookup(final Class<S> sourceType, final Class<T> targetType); @Override TypeConverterFactory<S, T> apply(final Map<Object, Object> registryEntries); TypeConverterFactory<S, T> lookup(final Set<TypeConverterFactory<?, ?>> typeConverterFactories);  }### Answer:
@Test public void testApply() { Map<Object, Object> registryEntries = new HashMap<>(); registryEntries.put(TypeConverterFactoryLookup.TYPE_CONVERTER_FACTORY_REGISTRY_KEY, new HashSet() {{ this.add(new TypeConverterFactory<String, Integer>() { @Override public TypeConverter<String, Integer> createTypeConverter() { return Integer::valueOf; } @Override public TypeConverterDescriptor<Class<String>, Class<Integer>> getTypeConverterDescriptor() { return new TypeConverterDescriptor<>(String.class, Integer.class); } }); this.add(new TypeConverterFactory<String, String>() { @Override public TypeConverter<String, String> createTypeConverter() { return value -> value; } @Override public TypeConverterDescriptor<Class<String>, Class<String>> getTypeConverterDescriptor() { return new TypeConverterDescriptor<>(String.class, String.class); } }); }}); SourceTargetTypeConverterFactoryLookup<String, Integer> sourceTargetTypeConverterFactoryLookup = new SourceTargetTypeConverterFactoryLookup<>(String.class, Integer.class); TypeConverter<? super String, ? extends Integer> typeConverter = sourceTargetTypeConverterFactoryLookup.apply(registryEntries).createTypeConverter(); assertNotNull(typeConverter); assertNotNull(typeConverter.convert("1")); }
@Test public void testApplyGivenTypeConverterFactoriesWithMatchingSourceAndTargetTypesButDifferentPriorities() { Map<Object, Object> registryEntries = new HashMap<>(); registryEntries.put(TypeConverterFactoryLookup.TYPE_CONVERTER_FACTORY_REGISTRY_KEY, new HashSet<>()); TypeConverterFactory<String, Integer> lowPriorityTypeConverterFactory = new TypeConverterFactory<String, Integer>() { @Override public TypeConverter<String, Integer> createTypeConverter() { throw new AssertionError(); } @Override public TypeConverterDescriptor<Class<String>, Class<Integer>> getTypeConverterDescriptor() { return new TypeConverterDescriptor<>(String.class, Integer.class); } }; TypeConverterFactory<String, Integer> mediumPriorityTypeConverterFactory = new TypeConverterFactory<String, Integer>() { @Override public TypeConverter<String, Integer> createTypeConverter() { throw new AssertionError(); } @Override public TypeConverterDescriptor<Class<String>, Class<Integer>> getTypeConverterDescriptor() { return new TypeConverterDescriptor<>(String.class, Integer.class, new Integer(Short.MAX_VALUE / 2).shortValue()); } }; TypeConverterFactory<String, Integer> highPriorityTypeConverterFactory = new TypeConverterFactory<String, Integer>() { @Override public TypeConverter<String, Integer> createTypeConverter() { return Integer::valueOf; } @Override public TypeConverterDescriptor<Class<String>, Class<Integer>> getTypeConverterDescriptor() { return new TypeConverterDescriptor<>(String.class, Integer.class, Short.MAX_VALUE); } }; ((Set<TypeConverterFactory<?, ?>>) registryEntries.get(TypeConverterFactoryLookup.TYPE_CONVERTER_FACTORY_REGISTRY_KEY)).add(lowPriorityTypeConverterFactory); ((Set<TypeConverterFactory<?, ?>>) registryEntries.get(TypeConverterFactoryLookup.TYPE_CONVERTER_FACTORY_REGISTRY_KEY)).add(highPriorityTypeConverterFactory); ((Set<TypeConverterFactory<?, ?>>) registryEntries.get(TypeConverterFactoryLookup.TYPE_CONVERTER_FACTORY_REGISTRY_KEY)).add(mediumPriorityTypeConverterFactory); SourceTargetTypeConverterFactoryLookup<String, Integer> sourceTargetTypeConverterFactoryLookup = new SourceTargetTypeConverterFactoryLookup<>(String.class, Integer.class); TypeConverter<? super String, ? extends Integer> typeConverter = sourceTargetTypeConverterFactoryLookup.apply(registryEntries).createTypeConverter(); assertNotNull(typeConverter.convert("1")); }