@Test
  public void testGetDeclaredTypeConverterDefaults() throws Exception {
    MappedBy mappedBy = mock(MappedBy.class);
    when(mappedBy.typeConverterClass()).thenReturn(MappedBy.DefaultTypeConverter.class);
    when(mappedBy.typeConverter()).thenReturn(MappedBy.DEFAULT_TYPE_CONVERTER);
    when(mappedBy.field()).thenReturn(MappedBy.DEFAULT_FIELD);

    assertThat(converterHelper.getDeclaredTypeConverter(mappedBy)).isNull();
  }
  @Test
  public void testGetDeclaredTypeConverterAsName() throws Exception {
    MappedBy mappedBy = mock(MappedBy.class);
    when(mappedBy.typeConverterClass()).thenReturn(MappedBy.DefaultTypeConverter.class);
    when(mappedBy.typeConverter()).thenReturn(NoConversionTypeConverter.class.getName());
    when(mappedBy.field()).thenReturn(MappedBy.DEFAULT_FIELD);
    when(reflectionHelper.newInstance(NoConversionTypeConverter.class.getName()))
        .thenReturn(new NoConversionTypeConverter());

    TypeConverter res = converterHelper.getDeclaredTypeConverter(mappedBy);

    assertThat(res).isInstanceOf(NoConversionTypeConverter.class);
  }
  @Test
  public void testGetDeclaredTypeConverterIae() throws Exception {
    MappedBy mappedBy = mock(MappedBy.class);
    when(mappedBy.typeConverterClass()).thenReturn(MappedBy.DefaultTypeConverter.class);
    when(mappedBy.typeConverter()).thenReturn(NoConversionTypeConverter.class.getName());
    when(mappedBy.field()).thenReturn(MappedBy.DEFAULT_FIELD);
    when(reflectionHelper.newInstance(NoConversionTypeConverter.class.getName()))
        .thenThrow(new IllegalAccessException());

    exception.expect(JTransfoException.class);
    exception.expectMessage(
        "Declared TypeConverter class org.jtransfo.NoConversionTypeConverter cannot be accessed.");
    converterHelper.getDeclaredTypeConverter(mappedBy);
  }
  @Test
  public void testGetDeclaredTypeConverterAsClass() throws Exception {
    MappedBy mappedBy = mock(MappedBy.class);
    when(mappedBy.typeConverterClass()).thenReturn(NoConversionTypeConverter.class);
    when(mappedBy.typeConverter()).thenReturn(MappedBy.DEFAULT_TYPE_CONVERTER);
    when(mappedBy.field()).thenReturn(MappedBy.DEFAULT_FIELD);
    when(reflectionHelper.newInstance(NoConversionTypeConverter.class.getName()))
        .thenReturn(new NoConversionTypeConverter());

    TypeConverter res = converterHelper.getDeclaredTypeConverter(mappedBy);

    assertThat(res).isInstanceOf(NoConversionTypeConverter.class);

    TypeConverter res2 = converterHelper.getDeclaredTypeConverter(mappedBy);

    assertThat(res2 == res).isTrue(); // instance needs to be cached and reused
  }