@Test public void testGetDeclaredTypeConverter() throws Exception { MapOnly mapOnly = mock(MapOnly.class); when(mapOnly.typeConverterClass()).thenReturn(MappedBy.DefaultTypeConverter.class); when(mapOnly.typeConverter()).thenReturn(MappedBy.DEFAULT_TYPE_CONVERTER); TypeConverter tc = mock(TypeConverter.class); TypeConverter res = converterHelper.getDeclaredTypeConverter(mapOnly, tc); assertThat(res).isEqualTo(tc); }
TypeConverter getDeclaredTypeConverter(String typeConverterClassName1, String typeConverterClassName2) { String typeConverterClass = typeConverterClassName1; if (MappedBy.DefaultTypeConverter.class.getName().equals(typeConverterClass)) { typeConverterClass = typeConverterClassName2; } if (!MappedBy.DEFAULT_TYPE_CONVERTER.equals(typeConverterClass)) { TypeConverter typeConverter = typeConverterInstances.get(typeConverterClass); if (null == typeConverter) { try { typeConverter = reflectionHelper.newInstance(typeConverterClass); typeConverterInstances.put(typeConverterClass, typeConverter); } catch (ClassNotFoundException cnfe) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be found.", cnfe); } catch (InstantiationException ie) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be instantiated.", ie); } catch (IllegalAccessException iae) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be accessed.", iae); } catch (ClassCastException cce) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be cast to a TypeConverter.", cce); } } return typeConverter; } return null; }
ConverterHelper { TypeConverter getDeclaredTypeConverter(String typeConverterClassName1, String typeConverterClassName2) { String typeConverterClass = typeConverterClassName1; if (MappedBy.DefaultTypeConverter.class.getName().equals(typeConverterClass)) { typeConverterClass = typeConverterClassName2; } if (!MappedBy.DEFAULT_TYPE_CONVERTER.equals(typeConverterClass)) { TypeConverter typeConverter = typeConverterInstances.get(typeConverterClass); if (null == typeConverter) { try { typeConverter = reflectionHelper.newInstance(typeConverterClass); typeConverterInstances.put(typeConverterClass, typeConverter); } catch (ClassNotFoundException cnfe) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be found.", cnfe); } catch (InstantiationException ie) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be instantiated.", ie); } catch (IllegalAccessException iae) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be accessed.", iae); } catch (ClassCastException cce) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be cast to a TypeConverter.", cce); } } return typeConverter; } return null; } }
ConverterHelper { TypeConverter getDeclaredTypeConverter(String typeConverterClassName1, String typeConverterClassName2) { String typeConverterClass = typeConverterClassName1; if (MappedBy.DefaultTypeConverter.class.getName().equals(typeConverterClass)) { typeConverterClass = typeConverterClassName2; } if (!MappedBy.DEFAULT_TYPE_CONVERTER.equals(typeConverterClass)) { TypeConverter typeConverter = typeConverterInstances.get(typeConverterClass); if (null == typeConverter) { try { typeConverter = reflectionHelper.newInstance(typeConverterClass); typeConverterInstances.put(typeConverterClass, typeConverter); } catch (ClassNotFoundException cnfe) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be found.", cnfe); } catch (InstantiationException ie) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be instantiated.", ie); } catch (IllegalAccessException iae) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be accessed.", iae); } catch (ClassCastException cce) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be cast to a TypeConverter.", cce); } } return typeConverter; } return null; }  }
ConverterHelper { TypeConverter getDeclaredTypeConverter(String typeConverterClassName1, String typeConverterClassName2) { String typeConverterClass = typeConverterClassName1; if (MappedBy.DefaultTypeConverter.class.getName().equals(typeConverterClass)) { typeConverterClass = typeConverterClassName2; } if (!MappedBy.DEFAULT_TYPE_CONVERTER.equals(typeConverterClass)) { TypeConverter typeConverter = typeConverterInstances.get(typeConverterClass); if (null == typeConverter) { try { typeConverter = reflectionHelper.newInstance(typeConverterClass); typeConverterInstances.put(typeConverterClass, typeConverter); } catch (ClassNotFoundException cnfe) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be found.", cnfe); } catch (InstantiationException ie) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be instantiated.", ie); } catch (IllegalAccessException iae) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be accessed.", iae); } catch (ClassCastException cce) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be cast to a TypeConverter.", cce); } } return typeConverter; } return null; }  ToConverter getToConverter(Class toClass, Class domainClass); }
ConverterHelper { TypeConverter getDeclaredTypeConverter(String typeConverterClassName1, String typeConverterClassName2) { String typeConverterClass = typeConverterClassName1; if (MappedBy.DefaultTypeConverter.class.getName().equals(typeConverterClass)) { typeConverterClass = typeConverterClassName2; } if (!MappedBy.DEFAULT_TYPE_CONVERTER.equals(typeConverterClass)) { TypeConverter typeConverter = typeConverterInstances.get(typeConverterClass); if (null == typeConverter) { try { typeConverter = reflectionHelper.newInstance(typeConverterClass); typeConverterInstances.put(typeConverterClass, typeConverter); } catch (ClassNotFoundException cnfe) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be found.", cnfe); } catch (InstantiationException ie) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be instantiated.", ie); } catch (IllegalAccessException iae) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be accessed.", iae); } catch (ClassCastException cce) { throw new JTransfoException(DECLARED_TYPE_CONVERTER_CLASS + typeConverterClass + " cannot be cast to a TypeConverter.", cce); } } return typeConverter; } return null; }  ToConverter getToConverter(Class toClass, Class domainClass);  }