The JDBC Appender should use keys and values from a Log4j
MapMessage. Use try-with-resources.
@@ -85,33 +85,33 @@ public class FactoryMethodConnectionSourceTest {
@Test
public void testDataSourceReturnType() throws SQLException {
final DataSource dataSource = mock(DataSource.class);
- final Connection connection1 = mock(Connection.class);
- final Connection connection2 = mock(Connection.class);
+ try (final Connection connection1 = mock(Connection.class);
+ final Connection connection2 = mock(Connection.class)) {
given(dataSource.getConnection()).willReturn(connection1, connection2);
holder.set(dataSource);
- final FactoryMethodConnectionSource source = FactoryMethodConnectionSource.createConnectionSource(
- DataSourceFactory.class.getName(), "factoryMethod02"
- );
+ final FactoryMethodConnectionSource source = FactoryMethodConnectionSource
+ .createConnectionSource(DataSourceFactory.class.getName(), "factoryMethod02");
assertNotNull("The connection source should not be null.", source);
- assertEquals("The toString value is not correct.", "factory{ public static javax.sql.DataSource[" + dataSource
- + "] " + DataSourceFactory.class.getName() + ".factoryMethod02() }", source.toString());
+ assertEquals("The toString value is not correct.", "factory{ public static javax.sql.DataSource["
+ + dataSource + "] " + DataSourceFactory.class.getName() + ".factoryMethod02() }",
+ source.toString());
assertSame("The connection is not correct (1).", connection1, source.getConnection());
assertSame("The connection is not correct (2).", connection2, source.getConnection());
}
+ }
@Test
public void testConnectionReturnType() throws SQLException {
- final Connection connection = mock(Connection.class);
+ try (final Connection connection = mock(Connection.class)) {
holder.set(connection);
- final FactoryMethodConnectionSource source = FactoryMethodConnectionSource.createConnectionSource(
- ConnectionFactory.class.getName(), "anotherMethod03"
- );
+ final FactoryMethodConnectionSource source = FactoryMethodConnectionSource
+ .createConnectionSource(ConnectionFactory.class.getName(), "anotherMethod03");
assertNotNull("The connection source should not be null.", source);
assertEquals("The toString value is not correct.", "factory{ public static java.sql.Connection "
@@ -119,6 +119,7 @@ public class FactoryMethodConnectionSourceTest {
assertSame("The connection is not correct (1).", connection, source.getConnection());
assertSame("The connection is not correct (2).", connection, source.getConnection());
}
+ }
@SuppressWarnings("unused")
protected static final class BadReturnTypeFactory {
