2929import org .reactivestreams .Publisher ;
3030
3131import java .io .FileNotFoundException ;
32- import java .io .IOException ;
3332import java .io .InputStream ;
3433import java .sql .DriverManager ;
3534import java .sql .SQLException ;
3635import java .time .Duration ;
3736import java .util .Properties ;
3837
39- import static org .junit .jupiter .api .Assertions .fail ;
40-
4138/**
4239 * Stores configuration used by integration tests that connect to a database.
4340 * The configuration is read from a resource file named "config.properties"
@@ -194,12 +191,13 @@ public static int databaseVersion() {
194191
195192 if (inputStream == null ) {
196193 throw new FileNotFoundException (
197- "property file ' " + CONFIG_FILE_NAME
198- + "' not found in the classpath " );
194+ CONFIG_FILE_NAME + " resource not found. " +
195+ "Check if it exists under src/test/resources/ " );
199196 }
200197
201198 Properties prop = new Properties ();
202199 prop .load (inputStream );
200+
203201 HOST = prop .getProperty ("HOST" );
204202 PORT = Integer .parseInt (prop .getProperty ("PORT" ));
205203 SERVICE_NAME = prop .getProperty ("DATABASE" );
@@ -224,8 +222,17 @@ public static int databaseVersion() {
224222 CONNECTION_FACTORY .create (),
225223 CONNECTION_FACTORY .getMetadata ());
226224 }
227- catch (IOException loadFileException ) {
228- throw new RuntimeException (loadFileException );
225+ catch (Throwable initializationFailure ) {
226+ // Most test cases require a database connection; If it can't be
227+ // configured, then the test run can not proceed. Print the failure and
228+ // terminate the JVM:
229+ initializationFailure .printStackTrace ();
230+ System .exit (-1 );
231+
232+ // This throw is dead code; exit(-1) doesn't return. This throw helps
233+ // javac to understand that the final fields are always initialized when
234+ // this static initialization block returns successfully.
235+ throw new RuntimeException (initializationFailure );
229236 }
230237 }
231238}
0 commit comments