database #3
@@ -5,10 +5,8 @@ public class Task {
|
||||
String description;
|
||||
int taskId;
|
||||
int workerId;
|
||||
AssignmentManager manager;
|
||||
TaskState state;
|
||||
public Task(int taskId, int workerId, String name, String description, AssignmentManager manager) {
|
||||
this.manager = manager;
|
||||
public Task(int taskId, int workerId, String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.taskId = taskId;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package hhn.temp.project.provider;
|
||||
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface DatabaseManager<E> extends Database {
|
||||
public void saveObjects(Collection<E> objects);
|
||||
public Collection<E> getObjects();
|
||||
public void saveObject(E object);
|
||||
public E getObject(int id);
|
||||
public Collection<E> getObjects() throws ExecutionControl.NotImplementedException;
|
||||
public void saveObject(E object) throws ExecutionControl.NotImplementedException;
|
||||
public E getObject(int id) throws ExecutionControl.NotImplementedException;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package hhn.temp.project.provider;
|
||||
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -20,18 +22,18 @@ public class SimpleDatabaseManager<E> implements DatabaseManager<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<E> getObjects() {
|
||||
return List.of();
|
||||
public Collection<E> getObjects() throws ExecutionControl.NotImplementedException {
|
||||
throw new ExecutionControl.NotImplementedException("Not Implemented!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveObject(E object) {
|
||||
g
|
||||
public void saveObject(E object) throws ExecutionControl.NotImplementedException {
|
||||
throw new ExecutionControl.NotImplementedException("Not Implemented!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getObject(int id) {
|
||||
return null;
|
||||
public E getObject(int id) throws ExecutionControl.NotImplementedException {
|
||||
throw new ExecutionControl.NotImplementedException("Not Implemented!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DatabaseBadCasesTest {
|
||||
|
||||
private DatabaseManager<DatabaseGoodCasesTest.TestClass> databaseManager;
|
||||
private DatabaseManager<Task> databaseManager;
|
||||
|
||||
public class TestClass {
|
||||
private int id;
|
||||
@@ -30,10 +30,4 @@ public class DatabaseBadCasesTest {
|
||||
public void setup() {
|
||||
databaseManager = new SimpleDatabaseManager<>();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Assert connection failed")
|
||||
public void assertConnectionFailed() {
|
||||
assertThrows(SQLException.class, () -> databaseManager.connect());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package hhn.temp.project;
|
||||
|
||||
import hhn.temp.project.provider.DatabaseManager;
|
||||
import hhn.temp.project.provider.SimpleDatabaseManager;
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -11,27 +12,31 @@ import java.sql.SQLException;
|
||||
|
||||
public class DatabaseGoodCasesTest {
|
||||
|
||||
private DatabaseManager<DatabaseGoodCasesTest.TestClass> databaseManager;
|
||||
private DatabaseManager<Task> databaseManager;
|
||||
private AssignmentManager manager;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
databaseManager = new SimpleDatabaseManager<>();
|
||||
manager = new AssignmentManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
||||
public void assertGetTestClass() throws SQLException, IOException {
|
||||
public void assertGetTestClass() throws SQLException, IOException, ExecutionControl.NotImplementedException {
|
||||
|
||||
databaseManager.connect();
|
||||
databaseManager.getObject(1);
|
||||
Task task = databaseManager.getObject(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
||||
public void assertInsertTestClass() throws SQLException, IOException {
|
||||
@DisplayName("Assert that a simple Task could be inserted into the database")
|
||||
public void assertInsertTestClass() throws SQLException, IOException, ExecutionControl.NotImplementedException {
|
||||
|
||||
Task testTask = new Task(1, 1, "Hello World", "Description");
|
||||
|
||||
databaseManager.connect();
|
||||
databaseManager.saveObject(testClass);
|
||||
databaseManager.saveObject(testTask);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user