CustomConverterContainer { public Class getCustomConverter(Class<?> srcClass, Class<?> destClass, Cache converterTypeCache) { if (converters.isEmpty()) { return null; } final Object cacheKey = CacheKeyFactory.createKey(destClass, srcClass); if (converterTypeCache.containsKey(cacheKey)) { return (Class)converterTypeCache.get(cacheKey); } final Class src = ClassUtils.primitiveToWrapper(srcClass); final Class dest = ClassUtils.primitiveToWrapper(destClass); Class appropriateConverter = findConverter(src, dest); converterTypeCache.put(cacheKey, appropriateConverter); return appropriateConverter; }  List<CustomConverterDescription> getConverters(); void setConverters(List<CustomConverterDescription> converters); void addConverter(CustomConverterDescription converter); Class getCustomConverter(Class<?> srcClass, Class<?> destClass, Cache converterTypeCache); Class findConverter(Class src, Class dest); @Override String toString();  }
@Test public void testGetCustomConverter_Cached() { CustomConverterDescription description = new CustomConverterDescription(); converters.add(description); cache.put(CacheKeyFactory.createKey(String.class, Integer.class), Object.class); Class result; result = ccc.getCustomConverter(Integer.class, String.class, cache); assertEquals(Object.class, result); }
@Test public void testGetCustomConverter_NotCached() { CustomConverterDescription description = new CustomConverterDescription(); description.setClassA(String.class); description.setClassB(Integer.class); description.setType(Void.class); converters.add(description); Class result; result = ccc.getCustomConverter(String.class, Integer.TYPE, cache); assertEquals(Void.class, result); result = ccc.getCustomConverter(String.class, Integer.class, cache); assertEquals(Void.class, result); }
@Test public void testGetCustomConverter_Miss() { cache.put(CacheKeyFactory.createKey(String.class, Integer.class), Object.class); Class result; result = ccc.getCustomConverter(Integer.class, Double.class, cache); assertEquals(null, result); result = ccc.getCustomConverter(Double.class, String.class, cache); assertEquals(null, result); }
@Test public void testGetCustomConverter_IsEmpty() { converters.clear(); Class result = ccc.getCustomConverter(Integer.class, Double.class, cache); assertEquals(null, result); }