use of org.springframework.data.convert.ConverterBuilder.ConverterAware in project spring-data-commons by spring-projects.
the class ConverterBuilderUnitTests method setsUpBidirectionalConvertersFromReading.
// DATACMNS-1034
@Test
public void setsUpBidirectionalConvertersFromReading() {
ConverterAware builder = ConverterBuilder.reading(String.class, Long.class, it -> Long.valueOf(it)).andWriting(Object::toString);
assertConverter(builder.getReadingConverter(), "1", 1L);
assertConverter(builder.getWritingConverter(), 1L, "1");
}
use of org.springframework.data.convert.ConverterBuilder.ConverterAware in project spring-data-commons by spring-projects.
the class ConverterBuilderUnitTests method setsUpBidirectionalConvertersFromWriting.
// DATACMNS-1034
@Test
public void setsUpBidirectionalConvertersFromWriting() {
ConverterAware builder = ConverterBuilder.writing(Long.class, String.class, Object::toString).andReading(it -> Long.valueOf(it));
assertConverter(builder.getReadingConverter(), "1", 1L);
assertConverter(builder.getWritingConverter(), 1L, "1");
}
use of org.springframework.data.convert.ConverterBuilder.ConverterAware in project spring-data-commons by spring-projects.
the class CustomConversionsUnitTests method registersConverterFromConverterAware.
// DATACMNS-1034
@Test
public void registersConverterFromConverterAware() {
ConverterAware converters = ConverterBuilder.reading(Left.class, Right.class, left -> new Right()).andWriting(right -> new Left());
CustomConversions conversions = new CustomConversions(StoreConversions.NONE, Collections.singletonList(converters));
assertThat(conversions.hasCustomWriteTarget(Right.class)).isTrue();
assertThat(conversions.hasCustomReadTarget(Left.class, Right.class)).isTrue();
ConfigurableConversionService conversionService = new GenericConversionService();
conversions.registerConvertersIn(conversionService);
assertThat(conversionService.canConvert(Left.class, Right.class)).isTrue();
assertThat(conversionService.canConvert(Right.class, Left.class)).isTrue();
}
Aggregations