You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2014/11/11 15:05:35 UTC

svn commit: r1638110 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Author: ggregory
Date: Tue Nov 11 14:05:34 2014
New Revision: 1638110

URL: http://svn.apache.org/r1638110
Log:
Refactor test to better abstract set up of fixture.

Modified:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java?rev=1638110&r1=1638109&r2=1638110&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java Tue Nov 11 14:05:34 2014
@@ -222,9 +222,9 @@ public class CSVPrinterTest {
     public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLException {
         final StringWriter sw = new StringWriter();
         final Connection connection = geH2Connection();
+        setUpTable(connection);
         try {
             final Statement stmt = connection.createStatement();
-            setUpTable(stmt);
             final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT);
             printer.printRecords(stmt.executeQuery("select ID, NAME from TEST"));
             assertEquals("1,r1" + recordSeparator + "2,r2" + recordSeparator, sw.toString());
@@ -239,11 +239,11 @@ public class CSVPrinterTest {
         final StringWriter sw = new StringWriter();
         Class.forName("org.h2.Driver");
         final Connection connection = geH2Connection();
+        setUpTable(connection);
         try {
             @SuppressWarnings("resource")
             // Closed when the connection is closed.
             final Statement stmt = connection.createStatement();
-            setUpTable(stmt);
             @SuppressWarnings("resource")
             // Closed when the connection is closed.
             final ResultSet resultSet = stmt.executeQuery("select ID, NAME from TEST");
@@ -262,11 +262,11 @@ public class CSVPrinterTest {
         final StringWriter sw = new StringWriter();
         Class.forName("org.h2.Driver");
         final Connection connection = geH2Connection();
+        setUpTable(connection);
         try {
             @SuppressWarnings("resource")
             // Closed when the connection is closed.
             final Statement stmt = connection.createStatement();
-            setUpTable(stmt);
             @SuppressWarnings("resource")
             // Closed when the connection is closed.
             final ResultSet resultSet = stmt.executeQuery("select ID, NAME from TEST");
@@ -280,10 +280,15 @@ public class CSVPrinterTest {
         }
     }
 
-    private void setUpTable(final Statement stmt) throws SQLException {
-        stmt.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
-        stmt.execute("insert into TEST values(1, 'r1')");
-        stmt.execute("insert into TEST values(2, 'r2')");
+    private void setUpTable(final Connection connection) throws SQLException {
+        Statement statement = connection.createStatement();
+        try {
+            statement.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
+            statement.execute("insert into TEST values(1, 'r1')");
+            statement.execute("insert into TEST values(2, 'r2')");
+        } finally {
+            statement.close();
+        }
     }
 
     @Test