-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: DatabaseConnectionTest implemented
- Loading branch information
AdrianBalunan
committed
Mar 15, 2026
1 parent
ac74eff
commit 3c3035e
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...application/src/test/java/ntnu/systemutvikling/team6/database/DatabaseConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package ntnu.systemutvikling.team6.database; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class DatabaseConnectionTest { | ||
|
|
||
| @Test | ||
| void constructorShouldCreateInstanceWithValidCredentials() { | ||
| DatabaseConnection db = new DatabaseConnection( | ||
| "jdbc:mysql://localhost:3306/test", | ||
| "user", | ||
| "password" | ||
| ); | ||
|
|
||
| assertNotNull(db); | ||
| } | ||
|
|
||
| @Test | ||
| void constructorShouldThrowExceptionIfUrlIsNull() { | ||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new DatabaseConnection(null, "user", "password"); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void constructorShouldThrowExceptionIfUsernameIsBlank() { | ||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new DatabaseConnection("jdbc:mysql://localhost:3306/test", "", "password"); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void constructorShouldThrowExceptionIfPasswordIsBlank() { | ||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new DatabaseConnection("jdbc:mysql://localhost:3306/test", "user", ""); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void getMySqlConnectionShouldReturnConnection() throws SQLException { | ||
|
|
||
| DatabaseConnection db = new DatabaseConnection(); | ||
|
|
||
| Connection connection = db.getMySqlConnection(); | ||
|
|
||
| assertNotNull(connection); | ||
| assertFalse(connection.isClosed()); | ||
|
|
||
| connection.close(); | ||
| } | ||
| } |