Updated from origin/main
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -6,4 +6,5 @@ import java.sql.SQLException;
|
|||||||
|
|
||||||
public interface Database {
|
public interface Database {
|
||||||
public void connect() throws SQLException, IOException;
|
public void connect() throws SQLException, IOException;
|
||||||
|
public void close() throws SQLException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class SimpleDatabaseManager<E> implements DatabaseManager<E> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveObject(E object) {
|
public void saveObject(E object) {
|
||||||
|
g
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,4 +38,11 @@ public class SimpleDatabaseManager<E> implements DatabaseManager<E> {
|
|||||||
public void connect() throws SQLException, IOException {
|
public void connect() throws SQLException, IOException {
|
||||||
connection = DriverManager.getConnection("jdbc:mysql://sql7.freesqldatabase.com/sql7810540?user=sql7810540&password=mXdJCFtDZz");
|
connection = DriverManager.getConnection("jdbc:mysql://sql7.freesqldatabase.com/sql7810540?user=sql7810540&password=mXdJCFtDZz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SQLException {
|
||||||
|
if (connection != null) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,18 +13,6 @@ public class DatabaseGoodCasesTest {
|
|||||||
|
|
||||||
private DatabaseManager<DatabaseGoodCasesTest.TestClass> databaseManager;
|
private DatabaseManager<DatabaseGoodCasesTest.TestClass> databaseManager;
|
||||||
|
|
||||||
public class TestClass {
|
|
||||||
private int id;
|
|
||||||
private String dataString;
|
|
||||||
private int dataInteger;
|
|
||||||
|
|
||||||
public TestClass(int id, String dataString, int dataInteger) {
|
|
||||||
this.id = id;
|
|
||||||
this.dataString = dataString;
|
|
||||||
this.dataInteger = dataInteger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
databaseManager = new SimpleDatabaseManager<>();
|
databaseManager = new SimpleDatabaseManager<>();
|
||||||
@@ -33,7 +21,6 @@ public class DatabaseGoodCasesTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
@DisplayName("Assert that the TestClass could be inserted into the database")
|
||||||
public void assertGetTestClass() throws SQLException, IOException {
|
public void assertGetTestClass() throws SQLException, IOException {
|
||||||
TestClass testClass = new TestClass(1, "Hello World", 123);
|
|
||||||
|
|
||||||
databaseManager.connect();
|
databaseManager.connect();
|
||||||
databaseManager.getObject(1);
|
databaseManager.getObject(1);
|
||||||
@@ -42,7 +29,6 @@ public class DatabaseGoodCasesTest {
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
@DisplayName("Assert that the TestClass could be inserted into the database")
|
||||||
public void assertInsertTestClass() throws SQLException, IOException {
|
public void assertInsertTestClass() throws SQLException, IOException {
|
||||||
TestClass testClass = new TestClass(1, "Hello World", 123);
|
|
||||||
|
|
||||||
databaseManager.connect();
|
databaseManager.connect();
|
||||||
databaseManager.saveObject(testClass);
|
databaseManager.saveObject(testClass);
|
||||||
|
|||||||
Reference in New Issue
Block a user