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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user