@Test public void testMapSqlDate() throws Exception { final java.sql.Date date = new java.sql.Date(new Date().getTime()); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.sql.Date>(date), java.sql.Date.class); newFieldMapperAndMapToPS(NullGetter.<Object, java.sql.Date>getter(), java.sql.Date.class); verify(ps).setDate(1, date); verify(ps).setNull(2, Types.DATE); }
@Test public void testJavaZonedDateTime() throws Exception { java.time.ZonedDateTime value = java.time.ZonedDateTime.now(); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.ZonedDateTime>(value), java.time.ZonedDateTime.class); newFieldMapperAndMapToPS(NullGetter.<Object, java.time.ZonedDateTime>getter(), java.time.ZonedDateTime.class); verify(ps).setTimestamp(1, new Timestamp(value.toInstant().toEpochMilli())); verify(ps).setNull(2, Types.TIMESTAMP); }
@Test public void testMapDateNoSqlType() throws Exception { final Date date = new Date(); newFieldMapperAndMapToPS(new ConstantGetter<Object, Date>(date), Date.class); newFieldMapperAndMapToPS(NullGetter.<Object, Date>getter(), Date.class); verify(ps).setTimestamp(1, new Timestamp(date.getTime())); verify(ps).setNull(2, Types.TIMESTAMP); }
@Test public void testJodaDateTime() throws Exception { org.joda.time.DateTime value = new org.joda.time.DateTime(); newFieldMapperAndMapToPS(new ConstantGetter<Object, org.joda.time.DateTime>(value), org.joda.time.DateTime.class); newFieldMapperAndMapToPS(NullGetter.<Object, org.joda.time.DateTime>getter(), org.joda.time.DateTime.class); verify(ps).setTimestamp(1, new Timestamp(value.getMillis())); verify(ps).setNull(2, Types.TIMESTAMP); }
@Test public void testMapTimestamp() throws Exception { final Timestamp date = new Timestamp(new Date().getTime()); newFieldMapperAndMapToPS(new ConstantGetter<Object, Timestamp>(date), Timestamp.class); newFieldMapperAndMapToPS(NullGetter.<Object, Timestamp>getter(), Timestamp.class); verify(ps).setTimestamp(1, date); verify(ps).setNull(2, Types.TIMESTAMP); }
@Test public void testJavaInstant() throws Exception { java.time.Instant value = java.time.Instant.now(); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.Instant>(value), java.time.Instant.class); newFieldMapperAndMapToPS(NullGetter.<Object, java.time.Instant>getter(), java.time.Instant.class); verify(ps).setTimestamp(1, new Timestamp(value.toEpochMilli())); verify(ps).setNull(2, Types.TIMESTAMP); }
@Test public void testJavaLocalDate() throws Exception { java.time.LocalDate value = java.time.LocalDate.now(); java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles"); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalDate>(value), java.time.LocalDate.class, new JavaZoneIdProperty(zoneId)); newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalDate>getter(), java.time.LocalDate.class); verify(ps).setDate(1, new java.sql.Date(value.atStartOfDay(zoneId).toInstant().toEpochMilli())); verify(ps).setNull(2, Types.DATE); }
@Test public void testReader() throws Exception { Reader value = mock(Reader.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Reader>(value), Reader.class); newFieldMapperAndMapToPS(NullGetter.<Object, Reader>getter(), Reader.class); verify(ps).setCharacterStream(1, value); verify(ps).setNull(2, Types.VARCHAR); }
@Test public void testClob() throws Exception { Clob value = mock(Clob.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Clob>(value), Clob.class); newFieldMapperAndMapToPS(NullGetter.<Object, Clob>getter(), Clob.class); verify(ps).setClob(1, value); verify(ps).setNull(2, Types.CLOB); }
@Test public void testBlob() throws Exception { Blob value = mock(Blob.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Blob>(value), Blob.class); newFieldMapperAndMapToPS(NullGetter.<Object, Blob>getter(), Blob.class); verify(ps).setBlob(1, value); verify(ps).setNull(2, Types.BINARY); }
@Test public void test() throws Exception { UUID uuid = UUID.randomUUID(); StringUUIDGetter<Object> getter = new StringUUIDGetter<Object>(new ConstantGetter<Object, String>(uuid.toString())); assertEquals(uuid, getter.get(null)); getter.toString(); } }
@Test public void testMapBoolean() throws Exception { newFieldMapperAndMapToPS(new ConstantBooleanGetter<Object>(true), boolean.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Boolean>(false), Boolean.class); newFieldMapperAndMapToPS(NullGetter.<Object, Boolean>getter(), Boolean.class); verify(ps).setBoolean(1, true); verify(ps).setBoolean(2, false); verify(ps).setNull(3, Types.BOOLEAN); }
@Test public void testMapChar() throws Exception { newFieldMapperAndMapToPS(new ConstantCharacterGetter<Object>((char)2), char.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Character>((char) 3), Character.class); newFieldMapperAndMapToPS(NullGetter.<Object, Character>getter(), Character.class); verify(ps).setInt(1, 2); verify(ps).setInt(2, 3); verify(ps).setNull(3, Types.INTEGER); }
@Test public void testMapInt() throws Exception { newFieldMapperAndMapToPS(new ConstantIntGetter<Object>(2), int.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Integer>(3), Integer.class); newFieldMapperAndMapToPS(NullGetter.<Object, Integer>getter(), Integer.class); verify(ps).setInt(1, 2); verify(ps).setInt(2, 3); verify(ps).setNull(3, Types.INTEGER); }
@Test public void testMapLong() throws Exception { newFieldMapperAndMapToPS(new ConstantLongGetter<Object>((long)2), long.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Long>((long) 3), Long.class); newFieldMapperAndMapToPS(NullGetter.<Object, Long>getter(), Long.class); verify(ps).setLong(1, (long) 2); verify(ps).setLong(2, (long) 3); verify(ps).setNull(3, Types.BIGINT); }
@Test public void testJodaLocalTime() throws Exception { org.joda.time.LocalTime value = new org.joda.time.LocalTime(); DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); newFieldMapperAndMapToPS(new ConstantGetter<Object, org.joda.time.LocalTime>(value), org.joda.time.LocalTime.class, dateTimeZone); newFieldMapperAndMapToPS(NullGetter.<Object, org.joda.time.LocalTime>getter(), org.joda.time.LocalTime.class); verify(ps).setTime(1, new Time(value.toDateTimeToday(dateTimeZone).getMillis())); verify(ps).setNull(2, Types.TIME); }
@Test public void testJavaOffsetTime() throws Exception { java.time.OffsetTime value = java.time.OffsetTime.now(); newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.OffsetTime>(value), java.time.OffsetTime.class); newFieldMapperAndMapToPS(NullGetter.<Object, java.time.OffsetTime>getter(), java.time.OffsetTime.class); verify(ps).setTime(1, new Time(value.atDate(LocalDate.now()).toInstant().toEpochMilli())); verify(ps).setNull(2, Types.TIME); }
@Test public void testRef() throws Exception { Ref value = mock(Ref.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, Ref>(value), Ref.class); newFieldMapperAndMapToPS(NullGetter.<Object, Ref>getter(), Ref.class); verify(ps).setRef(1, value); verify(ps).setNull(2, Types.REF); }
@Test public void testJodaLocalDateTime() throws Exception { org.joda.time.LocalDateTime value = new org.joda.time.LocalDateTime(); DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); newFieldMapperAndMapToPS(new ConstantGetter<Object, org.joda.time.LocalDateTime>(value), org.joda.time.LocalDateTime.class, dateTimeZone); newFieldMapperAndMapToPS(NullGetter.<Object, org.joda.time.LocalDateTime>getter(), org.joda.time.LocalDateTime.class); verify(ps).setTimestamp(1, new Timestamp(value.toDateTime(dateTimeZone).getMillis())); verify(ps).setNull(2, Types.TIMESTAMP); }
@Test public void testSQLXML() throws Exception { SQLXML value = mock(SQLXML.class); newFieldMapperAndMapToPS(new ConstantGetter<Object, SQLXML>(value), SQLXML.class); newFieldMapperAndMapToPS(NullGetter.<Object, SQLXML>getter(), SQLXML.class); verify(ps).setSQLXML(1, value); verify(ps).setNull(2, Types.SQLXML); }