use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class MimeTypeTests method withConversionService.
@Test
void withConversionService() {
ConversionService conversionService = new DefaultConversionService();
assertThat(conversionService.canConvert(String.class, MimeType.class)).isTrue();
MimeType mimeType = MimeType.valueOf("application/xml");
assertThat(conversionService.convert("application/xml", MimeType.class)).isEqualTo(mimeType);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class SingleColumnRowMapperTests method useCustomConversionService.
// SPR-16483
@Test
public void useCustomConversionService() throws SQLException {
Timestamp timestamp = new Timestamp(0);
DefaultConversionService myConversionService = new DefaultConversionService();
myConversionService.addConverter(Timestamp.class, MyLocalDateTime.class, source -> new MyLocalDateTime(source.toLocalDateTime()));
SingleColumnRowMapper<MyLocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
ResultSet resultSet = mock(ResultSet.class);
ResultSetMetaData metaData = mock(ResultSetMetaData.class);
given(metaData.getColumnCount()).willReturn(1);
given(resultSet.getMetaData()).willReturn(metaData);
given(resultSet.getObject(1, MyLocalDateTime.class)).willThrow(new SQLFeatureNotSupportedException());
given(resultSet.getObject(1)).willReturn(timestamp);
MyLocalDateTime actualMyLocalDateTime = rowMapper.mapRow(resultSet, 1);
assertThat(actualMyLocalDateTime).isNotNull();
assertThat(actualMyLocalDateTime.value).isEqualTo(timestamp.toLocalDateTime());
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class ObjectToStringHttpMessageConverterTests method setup.
@BeforeEach
public void setup() {
ConversionService conversionService = new DefaultConversionService();
this.converter = new ObjectToStringHttpMessageConverter(conversionService);
this.servletResponse = new MockHttpServletResponse();
this.response = new ServletServerHttpResponse(this.servletResponse);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class ObjectToStringHttpMessageConverterTests method defaultCharsetModified.
@Test
public void defaultCharsetModified() throws IOException {
ConversionService cs = new DefaultConversionService();
ObjectToStringHttpMessageConverter converter = new ObjectToStringHttpMessageConverter(cs, StandardCharsets.UTF_16);
converter.write((byte) 31, null, this.response);
assertThat(this.servletResponse.getCharacterEncoding()).isEqualTo("UTF-16");
}
Aggregations