use of org.springframework.core.convert.support.ConfigurableConversionService in project spring-boot by spring-projects.
the class EnvironmentConverterTests method convertedEnvironmentHasSameConversionService.
@Test
void convertedEnvironmentHasSameConversionService() {
AbstractEnvironment originalEnvironment = new MockEnvironment();
ConfigurableConversionService conversionService = mock(ConfigurableConversionService.class);
originalEnvironment.setConversionService(conversionService);
StandardEnvironment convertedEnvironment = this.environmentConverter.convertEnvironmentIfNecessary(originalEnvironment, StandardEnvironment.class);
assertThat(convertedEnvironment.getConversionService()).isEqualTo(conversionService);
}
use of org.springframework.core.convert.support.ConfigurableConversionService in project spring-boot by spring-projects.
the class ConfigTreePropertySourceTests method getPropertyViaEnvironmentSupportsConversion.
@Test
void getPropertyViaEnvironmentSupportsConversion() throws Exception {
StandardEnvironment environment = new StandardEnvironment();
ConversionService conversionService = ApplicationConversionService.getSharedInstance();
environment.setConversionService((ConfigurableConversionService) conversionService);
environment.getPropertySources().addFirst(getFlatPropertySource());
assertThat(environment.getProperty("a")).isEqualTo("A");
assertThat(environment.getProperty("b")).isEqualTo("B");
assertThat(environment.getProperty("c", InputStreamSource.class).getInputStream()).hasContent("C");
assertThat(environment.getProperty("c", byte[].class)).contains('C');
assertThat(environment.getProperty("one", Integer.class)).isEqualTo(1);
}
use of org.springframework.core.convert.support.ConfigurableConversionService in project spring-boot by spring-projects.
the class LogbackLoggingSystemTests method setup.
@BeforeEach
void setup() {
System.getProperties().remove(LoggingSystemProperties.CONSOLE_LOG_CHARSET);
System.getProperties().remove(LoggingSystemProperties.FILE_LOG_CHARSET);
this.systemPropertyNames = new HashSet<>(System.getProperties().keySet());
this.loggingSystem.cleanUp();
this.logger = ((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).getLogger(getClass());
this.environment = new MockEnvironment();
ConversionService conversionService = ApplicationConversionService.getSharedInstance();
this.environment.setConversionService((ConfigurableConversionService) conversionService);
this.initializationContext = new LoggingInitializationContext(this.environment);
}
use of org.springframework.core.convert.support.ConfigurableConversionService 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();
}
use of org.springframework.core.convert.support.ConfigurableConversionService in project spring-framework by spring-projects.
the class AbstractPropertyResolver method getConversionService.
@Override
public ConfigurableConversionService getConversionService() {
// Need to provide an independent DefaultConversionService, not the
// shared DefaultConversionService used by PropertySourcesPropertyResolver.
ConfigurableConversionService cs = this.conversionService;
if (cs == null) {
synchronized (this) {
cs = this.conversionService;
if (cs == null) {
cs = new DefaultConversionService();
this.conversionService = cs;
}
}
}
return cs;
}
Aggregations