DATACMNS-623 - Added converter for JSR-310 Instant instances.

Made the converter types public to be able to reuse them from other projects.

Related tickets: DATAJPA-650.
This commit is contained in:
Oliver Gierke
2014-12-30 13:45:34 +01:00
parent d7ecaa8db0
commit c5d920fa69
2 changed files with 50 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -105,6 +106,26 @@ public class Jsr310ConvertersUnitTests {
assertThat(format(CONVERSION_SERVICE.convert(now, Date.class), "HH:mm:ss.SSS"), is(now.toString()));
}
/**
* @see DATACMNS-623
*/
@Test
public void convertsDateToInstant() {
Date now = new Date();
assertThat(CONVERSION_SERVICE.convert(now, Instant.class), is(now.toInstant()));
}
/**
* @see DATACMNS-623
*/
@Test
public void convertsInstantToDate() {
Date now = new Date();
assertThat(CONVERSION_SERVICE.convert(now.toInstant(), Date.class), is(now));
}
private static String format(Date date, String format) {
return new SimpleDateFormat(format).format(date);
}