database #2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
||||
#Wed Dec 03 17:27:55 CET 2025
|
||||
gradle.version=8.14
|
||||
#Wed Dec 03 19:45:38 CET 2025
|
||||
gradle.version=9.1.0
|
||||
|
||||
Binary file not shown.
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/Template.test.iml" filepath="$PROJECT_DIR$/.idea/modules/Template.test.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules/Template.test.iml
generated
Normal file
8
.idea/modules/Template.test.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$/../../src/test" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,7 +1,9 @@
|
||||
package hhn.temp.project.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface Database {
|
||||
public void connect() throws SQLException;
|
||||
public void connect() throws SQLException, IOException;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package hhn.temp.project.provider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleDatabaseManager<E> implements DatabaseManager<E> {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@Override
|
||||
public void saveObjects(Collection<E> objects) {
|
||||
|
||||
@@ -26,7 +35,7 @@ public class SimpleDatabaseManager<E> implements DatabaseManager<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws SQLException {
|
||||
throw new SQLException("");
|
||||
public void connect() throws SQLException, IOException {
|
||||
connection = DriverManager.getConnection("jdbc:mysql://sql7.freesqldatabase.com/sql7810540?user=sql7810540&password=mXdJCFtDZz");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DatabaseGoodCasesTest {
|
||||
@@ -29,10 +30,27 @@ public class DatabaseGoodCasesTest {
|
||||
databaseManager = new SimpleDatabaseManager<>();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
||||
public void assertGetTestClass() throws SQLException, IOException {
|
||||
TestClass testClass = new TestClass(1, "Hello World", 123);
|
||||
|
||||
databaseManager.connect();
|
||||
databaseManager.getObject(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
||||
public void assertInsertTestClass() throws SQLException, IOException {
|
||||
TestClass testClass = new TestClass(1, "Hello World", 123);
|
||||
|
||||
databaseManager.connect();
|
||||
databaseManager.saveObject(testClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Assert connecting to database")
|
||||
public void assertConnectToDatabase() throws SQLException {
|
||||
public void assertConnectToDatabase() throws SQLException, IOException {
|
||||
databaseManager.connect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user