database #2

Merged
Ferryry merged 8 commits from database into main 2025-12-03 20:16:50 +01:00
21 changed files with 53 additions and 8 deletions
Showing only changes of commit 57144fa772 - Show all commits

View File

@@ -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

8
.idea/modules.xml generated Normal file
View 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
View 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>

File diff suppressed because one or more lines are too long

View File

@@ -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;
}

View File

@@ -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");
}
}

View File

@@ -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();
}
}