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