
package br.com.leonardoz.unit;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;

import org.junit.Test;

import br.com.leonardoz.dsl.ConnectionFactory;
import br.com.leonardoz.dsl.dml.DmlStatementWorker;
import br.com.leonardoz.dsl.query.QueryStatementWorker;
import br.com.leonardoz.dsl.query.ResultSetToEntity;
import br.com.leonardoz.dsl.statement.StatementBuilder;
import br.com.leonardoz.models.User;

/**
 * @author Leonardo H. Zapparoli
 *  2017-06-27
 */
public class StatementBuilderTest {

	@Test
	public void shouldBuildAsDml() {
		ConnectionFactory connectionFactory = any(ConnectionFactory.class);
		String sql = "INSERT INTO USERS VALUES (?, ?)";
		DmlStatementWorker asDml = new StatementBuilder(connectionFactory)
			.statement(sql)
			.withParameters(22, "Sponger Bob")
			.asDml();
		
		assertNotNull(asDml);
	}
	
	@Test
	public void shouldBuildAsQuery() {
		ConnectionFactory connectionFactory = any(ConnectionFactory.class);
		@SuppressWarnings("unchecked")
		ResultSetToEntity<User> parser = any(ResultSetToEntity.class);
		String sql = "SELECT * FROM USERS WHERE ID = ?";
		QueryStatementWorker<User> asQuery = new StatementBuilder(connectionFactory)
			.statement(sql)
			.withParameters(22)
			.asQuery(parser);
		
		assertNotNull(asQuery);
	}


}
