ReadOnlyDomainAutomaticTypeConverter extends AbstractToDomainTypeConverter implements Named, NeedsJTransfo { @Override public Object convert(Object toObject, SyntheticField domainField, Object domainObject, String... tags) throws JTransfoException { if (List.class.isAssignableFrom(domainField.getType())) { return rodListTypeConverter.convert((List<?>) toObject, domainField, domainObject, tags); } if (Set.class.isAssignableFrom(domainField.getType())) { return rodSetTypeConverter.convert((Set<?>) toObject, domainField, domainObject, tags); } return super.convert(toObject, domainField, domainObject, tags); }  @Override void setJTransfo(JTransfo jTransfo); @Override boolean canConvert(Type realToType, Type realDomainType); @Override Object convert(Object toObject, SyntheticField domainField, Object domainObject, String... tags); @Override Object reverse(Object domainObject, SyntheticField toField, Object toObject, String... tags); @Override Object doConvert(JTransfo jTransfo, Object toObject, SyntheticField domainField, String... tags); @Override String getName(); void setName(String name); void setKeepNullList(boolean keepNullList); void setKeepNullSet(boolean keepNullSet); void setAlwaysNewList(boolean alwaysNewList); void setAlwaysNewSet(boolean alwaysNewSet); void setSortList(boolean sortList);  }
@Test public void testConvertNull() throws Exception { assertThat(typeConverter.convert(null, domainField, null)).isNull(); }
@Test public void testConvertList() throws Exception { AddressTo to1 = new AddressTo(); to1.setId(1L); AddressTo to2 = new AddressTo(); to2.setId(2L); List<AddressTo> addresses = new ArrayList<>(); addresses.add(to1); addresses.add(to2); List<AddressDomain> res = (List) typeConverter.convert(addresses, listField, null); assertThat(res).isNotNull(); assertThat(res).hasSize(2); verify(jTransfo).findTarget(to1, AddressDomain.class, JTransfo.TAG_WHEN_READ_ONLY_DOMAIN); verify(jTransfo).findTarget(to2, AddressDomain.class, JTransfo.TAG_WHEN_READ_ONLY_DOMAIN); }
@Test public void testConvertSet() throws Exception { AddressTo to1 = new AddressTo(); to1.setId(1L); AddressTo to2 = new AddressTo(); to2.setId(2L); Set<AddressTo> addresses = new HashSet<>(); addresses.add(to1); addresses.add(to2); Set<AddressDomain> res = (Set) typeConverter.convert(addresses, setField, null); assertThat(res).isNotNull(); assertThat(res).hasSize(1); verify(jTransfo).findTarget(to1, AddressDomain.class, JTransfo.TAG_WHEN_READ_ONLY_DOMAIN); verify(jTransfo).findTarget(to2, AddressDomain.class, JTransfo.TAG_WHEN_READ_ONLY_DOMAIN); }
@Test public void testConvertSimple() throws Exception { SimpleBaseTo source = new SimpleBaseTo(); typeConverter.convert(source, domainField, null); verify(jTransfo).findTarget(source, SimpleBaseDomain.class, JTransfo.TAG_WHEN_READ_ONLY_DOMAIN); verify(jTransfo).getDomainClass(SimpleBaseTo.class); assertThat(typeConverter.convert(source, domainField, null)).isNull(); }