@@ -28,9 +28,9 @@ public class TestRunner {
28
28
private static final Logger logger = LoggerFactory .getLogger (TestRunner .class );
29
29
30
30
private final TestRunnerOptions options = new TestRunnerOptions ();
31
+ private final List <String > reporterNames = new ArrayList <>();
31
32
private CompatibilityProxy compatibilityProxy ;
32
33
private ReporterFactory reporterFactory ;
33
- private final List <String > reporterNames = new ArrayList <>();
34
34
35
35
public TestRunner addPath (String path ) {
36
36
options .pathList .add (path );
@@ -47,11 +47,12 @@ public TestRunner addReporter(Reporter reporter) {
47
47
return this ;
48
48
}
49
49
50
- public TestRunner addReporter ( String reporterName ) {
51
- if ( reporterFactory != null )
50
+ public TestRunner addReporter (String reporterName ) {
51
+ if (reporterFactory != null ) {
52
52
options .reporterList .add (reporterFactory .createReporter (reporterName ));
53
- else
53
+ } else {
54
54
reporterNames .add (reporterName );
55
+ }
55
56
return this ;
56
57
}
57
58
@@ -105,22 +106,22 @@ public TestRunner failOnErrors(boolean failOnErrors) {
105
106
return this ;
106
107
}
107
108
108
- public TestRunner skipCompatibilityCheck ( boolean skipCompatibilityCheck )
109
- {
109
+ public TestRunner skipCompatibilityCheck (boolean skipCompatibilityCheck ) {
110
110
options .skipCompatibilityCheck = skipCompatibilityCheck ;
111
111
return this ;
112
112
}
113
113
114
- public TestRunner setReporterFactory ( ReporterFactory reporterFactory ) {
114
+ public TestRunner setReporterFactory (ReporterFactory reporterFactory ) {
115
115
this .reporterFactory = reporterFactory ;
116
116
return this ;
117
117
}
118
118
119
119
private void delayedAddReporters () {
120
- if ( reporterFactory != null )
121
- reporterNames .forEach ( this ::addReporter );
122
- else
120
+ if (reporterFactory != null ) {
121
+ reporterNames .forEach (this ::addReporter );
122
+ } else {
123
123
throw new IllegalStateException ("ReporterFactory must be set to add delayed Reporters!" );
124
+ }
124
125
}
125
126
126
127
public void run (Connection conn ) throws SQLException {
@@ -132,17 +133,19 @@ public void run(Connection conn) throws SQLException {
132
133
compatibilityProxy = new CompatibilityProxy (conn , options .skipCompatibilityCheck , databaseInformation );
133
134
logger .info ("Running on utPLSQL {}" , compatibilityProxy .getDatabaseVersion ());
134
135
135
- if ( reporterFactory == null )
136
+ if (reporterFactory == null ) {
136
137
reporterFactory = ReporterFactory .createDefault (compatibilityProxy );
138
+ }
137
139
138
140
delayedAddReporters ();
139
141
140
142
// First of all check version compatibility
141
143
compatibilityProxy .failOnNotCompatible ();
142
144
143
145
logger .info ("Initializing reporters" );
144
- for (Reporter r : options .reporterList )
146
+ for (Reporter r : options .reporterList ) {
145
147
validateReporter (conn , r );
148
+ }
146
149
147
150
if (options .pathList .isEmpty ()) {
148
151
options .pathList .add (databaseInformation .getCurrentSchema (conn ));
@@ -153,43 +156,45 @@ public void run(Connection conn) throws SQLException {
153
156
options .reporterList .add (new DocumentationReporter ().init (conn ));
154
157
}
155
158
156
- try (TestRunnerStatement testRunnerStatement = compatibilityProxy .getTestRunnerStatement (options , conn )) {
159
+ try (TestRunnerStatement testRunnerStatement = compatibilityProxy .getTestRunnerStatement (options , conn )) {
157
160
logger .info ("Running tests" );
158
161
testRunnerStatement .execute ();
159
162
logger .info ("Running tests finished." );
160
163
} catch (SQLException e ) {
161
164
if (e .getErrorCode () == SomeTestsFailedException .ERROR_CODE ) {
162
165
throw new SomeTestsFailedException (e .getMessage (), e );
163
- }
164
- else if (e .getErrorCode () == UtPLSQLNotInstalledException .ERROR_CODE ) {
166
+ } else if (e .getErrorCode () == UtPLSQLNotInstalledException .ERROR_CODE ) {
165
167
throw new UtPLSQLNotInstalledException (e );
166
- }
167
- else {
168
+ } else {
168
169
throw e ;
169
170
}
170
171
}
171
172
}
172
173
173
174
/**
174
175
* Check if the reporter was initialized, if not call reporter.init.
175
- * @param conn the database connection
176
+ *
177
+ * @param conn the database connection
176
178
* @param reporter the reporter
177
179
* @throws SQLException any sql exception
178
180
*/
179
181
private void validateReporter (Connection conn , Reporter reporter ) throws SQLException {
180
- if (!reporter .isInit () || reporter .getId () == null || reporter .getId ().isEmpty ())
182
+ if (!reporter .isInit () || reporter .getId () == null || reporter .getId ().isEmpty ()) {
181
183
reporter .init (conn , compatibilityProxy , reporterFactory );
184
+ }
182
185
}
183
186
184
- /** Returns the databaseVersion the TestRunner was run against
187
+ /**
188
+ * Returns the databaseVersion the TestRunner was run against
185
189
*
186
190
* @return Version of the database the TestRunner was run against
187
191
*/
188
192
public Version getUsedDatabaseVersion () {
189
- if ( compatibilityProxy != null )
193
+ if (compatibilityProxy != null ) {
190
194
return compatibilityProxy .getDatabaseVersion ();
191
- else
195
+ } else {
192
196
return null ;
197
+ }
193
198
}
194
199
195
200
}
0 commit comments