fix: pre-copying test files

By some accursed class loading magic, files in the test-resources with the same name as one in the main resources were read/written in the main resources, causing some problems.

Renamed all of the test files to fix this.
This commit is contained in:
David Guler
2022-11-20 08:53:56 +01:00
parent b70a758099
commit bfe3fcfb79
14 changed files with 72 additions and 360 deletions
@@ -28,8 +28,8 @@ public class JsonCropListTest {
/**
* Files to isolate the test-units
*/
private final URL dbDataSource = this.getClass().getResource("user-crops.json");
private final URL testFile = this.getClass().getResource("test-user-crops.json");
private final URL dbDataSource = this.getClass().getResource("test-user-crops.json");
private final URL testFile = this.getClass().getResource("template-user-crops.json");
@BeforeEach
void connectToDb() throws URISyntaxException, IOException {
@@ -8,17 +8,22 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class JsonPlantListTest {
private final URL testFile = this.getClass().getResource("test-plantdb.json");
PlantList testDatabase;
@BeforeEach
void connectToDb() {
testDatabase = new JsonPlantList();
assertNotNull(testFile);
testDatabase = new JsonPlantList(testFile);
}
@@ -18,27 +18,27 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class JsonTaskListTest {
TaskList testDatabase;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private final URL dbDataSource = this.getClass().getResource("taskdb.json");
private final URL testFile = this.getClass().getResource("test-taskdb.json");
private final URL dbDataSource = this.getClass().getResource("test-taskdb.json");
private final URL testFile = this.getClass().getResource("template-taskdb.json");
@BeforeEach
void connectToDb() throws URISyntaxException, IOException {
assertNotNull(testFile);
assertNotNull(dbDataSource);
Files.copy(Path.of(testFile.toURI()), Path.of(dbDataSource.toURI()), StandardCopyOption.REPLACE_EXISTING);
testDatabase = new JsonTaskList();
testDatabase = new JsonTaskList(dbDataSource);
}
@Test
@DisplayName("Check if results are retrieved completely")
void getTasks() {
List<Task> taskList = null;
List<Task> taskList;
try {
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
LocalDate.parse("2022-05-31", formatter));
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -54,7 +54,7 @@ public class JsonTaskListTest {
Task task = new Task("Testtask", "This is a test Task.", LocalDate.parse("01.05.2022", formatter), 1);
try {
testDatabase.saveTask(task);
List<Task> taskList = null;
List<Task> taskList;
try {
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
@@ -72,13 +72,13 @@ public class JsonTaskListTest {
@Test
@DisplayName("Remove task.")
void removeTask() {
Task task = new Task("Dummy", "Dummy", LocalDate.parse("31.05.2022", formatter), 1).withId(2);
Task task = new Task("Dummy", "Dummy", LocalDate.parse("2022-05-31", formatter), 1).withId(2);
try {
testDatabase.removeTask(task);
List<Task> taskList = null;
List<Task> taskList;
taskList = testDatabase.getTaskList(LocalDate.parse("30.04.2022", formatter),
LocalDate.parse("31.05.2022", formatter));
taskList = testDatabase.getTaskList(LocalDate.parse("2022-04-30", formatter),
LocalDate.parse("2022-05-31", formatter));
Assertions.assertEquals(2, taskList.size());
} catch (IOException e) {
@@ -90,7 +90,7 @@ public class JsonTaskListTest {
@Test
void getTaskForCrop() {
List<Task> taskList = null;
List<Task> taskList;
try {
taskList = testDatabase.getTaskForCrop(0);
} catch (IOException e) {
@@ -104,7 +104,7 @@ public class JsonTaskListTest {
@Disabled("Disabled until removing works")
@Test
void removeTasksForCrop() {
List<Task> taskList = null;
List<Task> taskList;
try {
testDatabase.removeTasksForCrop(0);
taskList = testDatabase.getTaskForCrop(0);
@@ -22,8 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;
public class GardenPlanModelTest {
private final URL dbDataSource = JsonCropList.class.getResource("user-crops.json");
private final URL testFile = JsonCropList.class.getResource("test-user-crops.json");
private final URL dbDataSource = JsonCropListTest.class.getResource("test-user-crops.json");
private final URL testFile = JsonCropListTest.class.getResource("template-user-crops.json");
CropList cropList;
List<Crop> exampleCrops;