package org.sfm.jdbc;

import org.junit.Test;
import org.sfm.beans.DbFinalObject;
import org.sfm.beans.DbObject;
import org.sfm.reflect.ReflectionService;
import org.sfm.tuples.Tuple2;
import org.sfm.utils.ListHandler;
import org.sfm.utils.RowHandler;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.Iterator;
import java.util.List;

import static org.junit.Assert.*;

public class JdbcMapperTupleTest {
	
	@Test
	public void testTuple2OnString() throws Exception {
		JdbcMapperBuilder<Tuple2<String, String>> builder = new JdbcMapperBuilder<Tuple2<String, String>>(Tuple2.typeDef(String.class, String.class));
		
		addColumn(builder);
		
		final JdbcMapper<Tuple2<String, String>> mapper = builder.mapper();

		DbHelper.testQuery(
				new RowHandler<PreparedStatement>() {
					@Override
					public void handle(PreparedStatement preparedStatement) throws Exception {
						try (ResultSet rs = preparedStatement.executeQuery()) {
							List<Tuple2<String, String>> list = mapper.forEach(rs, new ListHandler<Tuple2<String, String>>()).getList();

							assertEquals(1, list.size());

							Tuple2<String, String> tuple2 = list.get(0);
							assertEquals("1", tuple2.getElement1());
							assertEquals("2", tuple2.getElement2());
						}
					}
				},
				"select '1', '2' from  TEST_DB_OBJECT where id = 1"

		);
	}

	public static <T> JdbcMapperBuilder<T> addColumn(JdbcMapperBuilder<T> builder) {
		builder.addMapping("element1");
		builder.addMapping("element2");
		return builder;
	}

}
@@ -1000,13 +1000,8 @@
 %09%09%09%09
-try (
 Resu
@@ -1043,17 +1043,29 @@
 eQuery()
-)
+;%0D%0A%09%09%09%09%09%09try 
  %7B%0D%0A%09%09%09%09
@@ -1366,24 +1366,94 @@
 ement2());%0D%0A
+%09%09%09%09%09%09%7D finally %7B%0D%0A%09%09%09%09%09%09%09try %7B rs.close(); %7D catch (Exception e) %7B%7D%0D%0A
 %09%09%09%09%09%09%7D%0D%0A%09%09%09

fix jdk16