mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add ScalarTypeLocalDate
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ScalarTypeLocalDateTest {
|
||||
|
||||
ScalarTypeLocalDate type = new ScalarTypeLocalDate();
|
||||
|
||||
@Test
|
||||
public void testConvertToMillis() throws Exception {
|
||||
|
||||
LocalDate date = LocalDate.of(2014, 5, 20);
|
||||
long millis = type.convertToMillis(date);
|
||||
|
||||
System.out.println(date);
|
||||
|
||||
LocalDate parseDate = type.parseDateTime(millis);
|
||||
|
||||
assertEquals(date, parseDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromDate() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToDate() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseDateTime() throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ScalarTypeLocalDateTimeTest {
|
||||
|
||||
ScalarTypeLocalDateTime type = new ScalarTypeLocalDateTime();
|
||||
|
||||
// warm up
|
||||
LocalDateTime warmUp = LocalDateTime.now();
|
||||
|
||||
@Test
|
||||
public void testConvertToMillis() throws Exception {
|
||||
|
||||
warmUp.hashCode();
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long toMillis = type.convertToMillis( LocalDateTime.now());
|
||||
|
||||
assertTrue(toMillis - now < 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromTimestamp() throws Exception {
|
||||
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
LocalDateTime localDateTime = type.convertFromTimestamp(now);
|
||||
Timestamp timestamp = type.convertToTimestamp(localDateTime);
|
||||
|
||||
assertEquals(now, timestamp);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
|
||||
Object jdbcType = type.toJdbcType(LocalDateTime.now());
|
||||
assertTrue(jdbcType instanceof Timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() throws Exception {
|
||||
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
LocalDateTime localDateTime = type.toBeanType(timestamp);
|
||||
|
||||
assertNotNull(localDateTime);
|
||||
|
||||
Timestamp timestamp1 = type.convertToTimestamp(localDateTime);
|
||||
assertEquals(timestamp, timestamp1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ScalarTypeOffsetDateTimeTest {
|
||||
|
||||
|
||||
ScalarTypeOffsetDateTime type = new ScalarTypeOffsetDateTime();
|
||||
|
||||
OffsetDateTime warmUp = OffsetDateTime.now();
|
||||
|
||||
@Test
|
||||
public void testConvertToMillis() throws Exception {
|
||||
|
||||
warmUp.hashCode();
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long toMillis = type.convertToMillis( OffsetDateTime.now());
|
||||
|
||||
assertTrue(toMillis - now < 10);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromTimestamp() throws Exception {
|
||||
|
||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
OffsetDateTime localDateTime = type.convertFromTimestamp(now);
|
||||
Timestamp timestamp = type.convertToTimestamp(localDateTime);
|
||||
|
||||
assertEquals(now, timestamp);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
|
||||
Object jdbcType = type.toJdbcType(OffsetDateTime.now());
|
||||
assertTrue(jdbcType instanceof Timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() throws Exception {
|
||||
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
OffsetDateTime localDateTime = type.toBeanType(timestamp);
|
||||
|
||||
assertNotNull(localDateTime);
|
||||
|
||||
Timestamp timestamp1 = type.convertToTimestamp(localDateTime);
|
||||
assertEquals(timestamp, timestamp1);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user