3131import java .io .File ;
3232import java .io .IOException ;
3333import java .io .PrintWriter ;
34+ import java .sql .SQLException ;
3435
35- import static org .junit .Assert .assertEquals ;
36- import static org .junit .Assert .assertNotNull ;
37- import static org .junit .Assert .fail ;
36+ import static org .junit .Assert .*;
3837
3938@ RunWith (IOTestRunner .class )
4039public class DatabaseConfigTest {
@@ -54,7 +53,7 @@ public void tearDown() {
5453 }
5554
5655 @ Test
57- public void testLoadAndGetDataSource () throws IOException {
56+ public void testLoadAndGetDataSource () throws IOException , SQLException {
5857 final File databaseConfigFile = TestUtil .createFileInTestDir ("database.properties" );
5958
6059 final PrintWriter printWriter = new PrintWriter (databaseConfigFile );
@@ -74,6 +73,35 @@ public void testLoadAndGetDataSource() throws IOException {
7473 assertEquals ("pass-word" , dataSource .getPassword ());
7574 }
7675
76+ @ Test
77+ public void testLoadAndGetTimeout () throws IOException {
78+ final File databaseConfigFile = TestUtil .createFileInTestDir ("database.properties" );
79+
80+ final PrintWriter printWriter = new PrintWriter (databaseConfigFile );
81+ printWriter .write ("timeout = 654" );
82+ printWriter .close ();
83+
84+ databaseConfig .loadFrom (testDirectory );
85+
86+ assertEquals (654 , databaseConfig .getTimeoutInSeconds ());
87+ }
88+
89+ @ Test
90+ public void testLoadAndGetTimeout_default () throws IOException {
91+ final File databaseConfigFile = TestUtil .createFileInTestDir ("database.properties" );
92+
93+ final PrintWriter printWriter = new PrintWriter (databaseConfigFile );
94+ printWriter .write ("driverClassName = driver-class\n " );
95+ printWriter .write ("url = database-url\n " );
96+ printWriter .write ("username = user-name\n " );
97+ printWriter .write ("password = pass-word" );
98+ printWriter .close ();
99+
100+ databaseConfig .loadFrom (testDirectory );
101+
102+ assertEquals (120 , databaseConfig .getTimeoutInSeconds ());
103+ }
104+
77105 @ Test
78106 public void testLoad_throwsWhenFileNotPresent () throws IOException {
79107 try {
@@ -84,7 +112,7 @@ public void testLoad_throwsWhenFileNotPresent() throws IOException {
84112 }
85113
86114 @ Test
87- public void testGetDatasource_throwsWhenNotLoaded () {
115+ public void testGetDatasource_throwsWhenNotLoaded () throws SQLException {
88116 try {
89117 databaseConfig .getDataSource ();
90118 fail ("RuntimeException expected" );
0 commit comments