use of com.mockrunner.mock.jdbc.MockPreparedStatement in project cayenne by apache.
the class LocalDateTypeTest method testSetJdbcObject.
public void testSetJdbcObject() throws Exception {
PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
LocalDate savedObject = new LocalDate(0);
type.setJdbcObject(statement, savedObject, 1, Types.DATE, 0);
Object object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Date.class, object.getClass());
assertEquals(savedObject.toDate().getTime(), ((Date) object).getTime());
type.setJdbcObject(statement, savedObject, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Timestamp.class, object.getClass());
assertEquals(savedObject.toDate().getTime(), ((Timestamp) object).getTime());
type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertNull(object);
}
use of com.mockrunner.mock.jdbc.MockPreparedStatement in project cayenne by apache.
the class LocalTimeTypeTest method testSetJdbcObject.
public void testSetJdbcObject() throws Exception {
PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
LocalTime date = new LocalTime(0);
type.setJdbcObject(statement, date, 1, Types.TIME, 0);
Object object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Time.class, object.getClass());
assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Time) object).getTime());
type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Timestamp.class, object.getClass());
assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Timestamp) object).getTime());
type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertNull(object);
}
use of com.mockrunner.mock.jdbc.MockPreparedStatement in project cayenne by apache.
the class DateTimeTypeTest method testSetJdbcObject.
public void testSetJdbcObject() throws Exception {
PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
DateTime date = new DateTime(0);
type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
Object object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Timestamp.class, object.getClass());
assertEquals(date.getMillis(), ((Timestamp) object).getTime());
type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertNull(object);
}
use of com.mockrunner.mock.jdbc.MockPreparedStatement in project cayenne by apache.
the class LocalDateTimeTypeTest method testSetJdbcObject.
public void testSetJdbcObject() throws Exception {
PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
LocalDateTime date = new LocalDateTime(0);
type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
Object object = ((MockPreparedStatement) statement).getParameter(1);
assertEquals(Timestamp.class, object.getClass());
assertEquals(date.toDate().getTime(), ((Timestamp) object).getTime());
type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
object = ((MockPreparedStatement) statement).getParameter(1);
assertNull(object);
}
Aggregations