@Test public void testConvertNull() throws Exception { SyntheticField field = mock(SyntheticField.class); when(field.getType()).thenReturn((Class) SimpleBaseDomain.class); String[] tags = new String[] {"a", "b", "c"}; assertThat(typeConverter.convert(null, field, null, tags)).isNull(); }
@Test public void testConvert() throws Exception { SimpleBaseTo source = new SimpleBaseTo(); SyntheticField field = mock(SyntheticField.class); when(field.getType()).thenReturn((Class) SimpleBaseDomain.class); String[] tags = new String[] {"a", "b", "c"}; typeConverter.convert(source, field, null, tags); verify(jTransfo).convertTo(source, SimpleBaseDomain.class, tags); }
@Test public void testReverse() throws Exception { SimpleBaseDomain source = new SimpleBaseDomain(); SimpleBaseTo target = new SimpleBaseTo(); when(reflectionHelper.newInstance(any(Class.class))).thenReturn(target); SyntheticField field = mock(SyntheticField.class); when(field.getType()).thenReturn((Class) SimpleBaseTo.class); String[] tags = new String[] {"a", "b", "c"}; typeConverter.reverse(source, field, null, tags); verify(jTransfo).convert(source, target, tags); }
@Test public void testReverseIllegalAccessException() throws Exception { SimpleBaseDomain source = new SimpleBaseDomain(); SimpleBaseTo target = new SimpleBaseTo(); when(reflectionHelper.newInstance(any(Class.class))).thenThrow(new IllegalAccessException()); SyntheticField field = mock(SyntheticField.class); when(field.getType()).thenReturn((Class) SimpleBaseTo.class); exception.expect(JTransfoException.class); exception.expectMessage( "Cannot create instance of transfer object class org.jtransfo.object.SimpleBaseTo."); typeConverter.reverse(source, field, null); }
@Test public void testReverseNullHandling() throws Exception { SyntheticField field = mock(SyntheticField.class); when(field.getType()).thenReturn((Class) SimpleBaseTo.class); assertThat(typeConverter.reverse(null, field, null)).isNull(); }