1
1
package org .utplsql .api ;
2
2
3
- import oracle .jdbc .OracleConnection ;
4
3
import org .utplsql .api .compatibility .CompatibilityProxy ;
5
4
import org .utplsql .api .exception .DatabaseNotCompatibleException ;
6
5
import org .utplsql .api .exception .SomeTestsFailedException ;
10
9
import org .utplsql .api .reporter .ReporterFactory ;
11
10
import org .utplsql .api .testRunner .TestRunnerStatement ;
12
11
13
- import java .sql .CallableStatement ;
14
12
import java .sql .Connection ;
15
13
import java .sql .SQLException ;
16
14
import java .util .ArrayList ;
24
22
*/
25
23
public class TestRunner {
26
24
27
- private TestRunnerOptions options = new TestRunnerOptions ();
25
+ private final TestRunnerOptions options = new TestRunnerOptions ();
28
26
private CompatibilityProxy compatibilityProxy ;
29
27
private ReporterFactory reporterFactory ;
30
- private List <String > reporterNames = new ArrayList <>();
28
+ private final List <String > reporterNames = new ArrayList <>();
31
29
32
30
public TestRunner addPath (String path ) {
33
31
options .pathList .add (path );
34
32
return this ;
35
33
}
36
34
37
35
public TestRunner addPathList (List <String > paths ) {
38
- if ( options . pathList != null ) options .pathList .addAll (paths );
36
+ options .pathList .addAll (paths );
39
37
return this ;
40
38
}
41
39
@@ -115,7 +113,7 @@ public TestRunner setReporterFactory( ReporterFactory reporterFactory ) {
115
113
116
114
private void delayedAddReporters () {
117
115
if ( reporterFactory != null )
118
- reporterNames .stream (). forEach ( this ::addReporter );
116
+ reporterNames .forEach ( this ::addReporter );
119
117
else
120
118
throw new IllegalStateException ("ReporterFactory must be set to add delayed Reporters!" );
121
119
}
@@ -142,13 +140,8 @@ public void run(Connection conn) throws SomeTestsFailedException, SQLException,
142
140
options .reporterList .add (new DocumentationReporter ().init (conn ));
143
141
}
144
142
145
- TestRunnerStatement testRunnerStatement = null ;
146
-
147
- try {
148
- DBHelper .enableDBMSOutput (conn );
149
-
150
- testRunnerStatement = compatibilityProxy .getTestRunnerStatement (options , conn );
151
-
143
+ DBHelper .enableDBMSOutput (conn );
144
+ try (TestRunnerStatement testRunnerStatement = compatibilityProxy .getTestRunnerStatement (options , conn )) {
152
145
testRunnerStatement .execute ();
153
146
} catch (SQLException e ) {
154
147
if (e .getErrorCode () == SomeTestsFailedException .ERROR_CODE ) {
@@ -161,10 +154,6 @@ else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
161
154
throw e ;
162
155
}
163
156
} finally {
164
- if (testRunnerStatement != null ) {
165
- testRunnerStatement .close ();
166
- }
167
-
168
157
DBHelper .disableDBMSOutput (conn );
169
158
}
170
159
}
0 commit comments