Heavily refactored DatabaseManager.java and SimpleDatabaseManager.java. Fully refactored DatabaseGoodCasesTest.java and DatabaseBadCasesTest.java.
This commit is contained in:
@@ -13,36 +13,34 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DatabaseBadCasesTest {
|
||||
|
||||
private DatabaseManager<Task> 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;
|
||||
}
|
||||
}
|
||||
private DatabaseManager databaseManager;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws SQLException, IOException {
|
||||
databaseManager = new SimpleDatabaseManager<>();
|
||||
public void setup() throws SQLException {
|
||||
databaseManager = new SimpleDatabaseManager();
|
||||
databaseManager.connect();
|
||||
databaseManager.clearDatabase();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Gets an object that may not be existent")
|
||||
public void assertObjectShouldNotBeExistent() throws SQLException {
|
||||
assertNull(databaseManager.getObject(999));
|
||||
@DisplayName("Inserting Tasks with the same ID")
|
||||
public void insertTasksWithTheSameId() throws SQLException {
|
||||
Task task = new Task(10, 10, "ABC", "XYZ");
|
||||
Task taskFaker = new Task(10, 5, "ABC!", "XYZ!");
|
||||
|
||||
databaseManager.saveTask(task);
|
||||
|
||||
databaseManager.saveTask(taskFaker);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Updates an object that does not exist")
|
||||
public void assertUpdateNonExistentObject() throws SQLException {
|
||||
assertNull(databaseManager.updateObject(123, new Task(123, 2, "", "")));
|
||||
@DisplayName("Inserting Workers with the same ID")
|
||||
public void insertWorkersWithTheSameId() throws SQLException {
|
||||
Worker worker = new Worker("Worker-1", 1);
|
||||
Worker workerFaker = new Worker("Worker-100", 1);
|
||||
|
||||
databaseManager.saveWorker(worker);
|
||||
|
||||
databaseManager.saveWorker(workerFaker);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user