package io.vertx.ext.jdbc.impl.actions;

import io.vertx.core.json.JsonObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import java.sql.SQLException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static java.time.format.DateTimeFormatter.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

@RunWith(Parameterized.class)
public class SQLConvertTest {

  private JsonObject config = new JsonObject().put("castUUID", true);

  private JDBCStatementHelper helper = new JDBCStatementHelper(config);

  @Parameters(name = "{0}")
  public static Collection<Object[]> generateData() {
    List<Object[]> params = new ArrayList<>();

    ZonedDateTime dateTime = ZonedDateTime.of(2016, 3, 16, 16, 0, 0, 0, ZoneId.of("Europe/Paris"));
    for (int i = 0; i < 4; i++) {
      int nanos = 123 * (i == 0 ? 0 : 1) * (int) Math.pow(1000, i > 1 ? i - 1 : 0);
      params.add(new Object[]{ISO_INSTANT.format(dateTime.withNano(nanos))});
    }
    params.add(new Object[]{ISO_LOCAL_TIME.format(dateTime.withSecond(1))});
    params.add(new Object[]{dateTime.toLocalDate().toString()});

    params.add(new Object[]{"f47ac10b-58cc-4372-a567-0e02b2c3d479"});

    return params;
  }

  // Fields
  private String value;

  public SQLConvertTest(String value) {
    this.value = value;
  }

  @Test
  public void testSQLConvert() throws SQLException {
    Object cast = helper.optimisticCast(value);
    assertThat(cast, not(instanceOf(String.class)));

    Object convert = JDBCStatementHelper.convertSqlValue(cast);
    assertEquals(value, convert);
  }
}

@@ -386,16 +386,39 @@
 il.List;
+%0Aimport java.util.UUID;
 %0A%0Aimport
@@ -1168,16 +1168,42 @@
 (nanos))
+, java.sql.Timestamp.class
 %7D);%0A    
@@ -1277,16 +1277,37 @@
 cond(1))
+, java.sql.Time.class
 %7D);%0A    
@@ -1363,16 +1363,37 @@
 String()
+, java.sql.Date.class
 %7D);%0A%0A   
@@ -1455,16 +1455,28 @@
 2c3d479%22
+, UUID.class
 %7D);%0A%0A   
@@ -1500,20 +1500,8 @@
  %7D%0A%0A
-  // Fields%0A
   pr
@@ -1519,16 +1519,52 @@
 g value;
+%0A  private Class%3C?%3E expectedSqlType;
 %0A%0A  publ
@@ -1597,33 +1597,103 @@
 alue
-) %7B%0A    this.value = valu
+, Class%3C?%3E expectedSqlType) %7B%0A    this.value = value;%0A    this.expectedSqlType = expectedSqlTyp
 e;%0A 
@@ -1830,12 +1830,8 @@
 st, 
-not(
 inst
@@ -1841,21 +1841,23 @@
 eOf(
-String.class)
+expectedSqlType
 ));%0A

Check JDBC type