package com.zaxxer.hikari;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintWriter;

import javax.sql.DataSource;

import org.junit.Assert;
import org.junit.Test;

import com.zaxxer.hikari.util.PropertyBeanSetter;

public class TestPropertySetter
{
    @Test
    public void testProperty1()
    {
        File file = new File("src/test/resources/propfile1.properties");
        HikariConfig config = new HikariConfig(file.getPath());
        config.validate();

        Assert.assertEquals(5, config.getMinimumIdle());
        Assert.assertEquals("SELECT 1", config.getConnectionTestQuery());
    }

    @Test
    public void testProperty2() throws Exception
    {
        File file = new File("src/test/resources/propfile2.properties");
        HikariConfig config = new HikariConfig(file.getPath());
        config.validate();

        Class<?> clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName());
        DataSource dataSource = (DataSource) clazz.newInstance();
        PropertyBeanSetter.setTargetFromProperties(dataSource, config.getDataSourceProperties());
    }

    @Test
    public void testObjectProperty() throws Exception
    {
        HikariConfig config = new HikariConfig();
        config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
        PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
        config.addDataSourceProperty("logWriter", writer);

        Class<?> clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName());
        DataSource dataSource = (DataSource) clazz.newInstance();
        PropertyBeanSetter.setTargetFromProperties(dataSource, config.getDataSourceProperties());

        Assert.assertSame(PrintWriter.class, dataSource.getLogWriter().getClass());
    }

    @Test
    public void testPropertyUpperCase() throws Exception
    {
        File file = new File("src/test/resources/propfile3.properties");
        HikariConfig config = new HikariConfig(file.getPath());
        config.validate();

        Class<?> clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName());
        DataSource dataSource = (DataSource) clazz.newInstance();
        PropertyBeanSetter.setTargetFromProperties(dataSource, config.getDataSourceProperties());
    }

}

@@ -107,16 +107,38 @@
 tWriter;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -2354,10 +2354,255 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testGetPropertyNames() throws Exception%0A    %7B%0A        Set%3CString%3E propertyNames = PropertyBeanSetter.getPropertyNames(HikariConfig.class);%0A        Assert.assertTrue(propertyNames.contains(%22dataSourceClassName%22));%0A    %7D%0A
 %7D%0A

Add a test for PropertyBeanSetter.getPropertyNames().