Extended testcoverage for classes
This commit is contained in:
parent
e75ececedb
commit
1dc2ad1774
|
@ -30,6 +30,7 @@ public class JsonCropListTest {
|
||||||
*/
|
*/
|
||||||
private final URL dbDataSource = 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");
|
private final URL testFile = this.getClass().getResource("template-user-crops.json");
|
||||||
|
private final URL corruptTestFile = this.getClass().getResource("corrupt-template-user-crops.json");
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void connectToDb() throws URISyntaxException, IOException {
|
void connectToDb() throws URISyntaxException, IOException {
|
||||||
|
@ -101,5 +102,13 @@ public class JsonCropListTest {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void detectCorruptJsonResource(){
|
||||||
|
JsonCropList tL = new JsonCropList(corruptTestFile);
|
||||||
|
Assertions.assertThrows(InvalidJsonException.class, () -> {
|
||||||
|
tL.getCrops();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
public class JsonPlantListTest {
|
public class JsonPlantListTest {
|
||||||
private final URL testFile = this.getClass().getResource("test-plantdb.json");
|
private final URL testFile = this.getClass().getResource("test-plantdb.json");
|
||||||
|
@ -62,6 +63,8 @@ public class JsonPlantListTest {
|
||||||
void getPlantByIdAndZone() {
|
void getPlantByIdAndZone() {
|
||||||
Optional<Plant> testPlant;
|
Optional<Plant> testPlant;
|
||||||
try {
|
try {
|
||||||
|
assertThrows(HardinessZoneNotSetException.class, () -> testDatabase.getPlantById(null,1).get());
|
||||||
|
|
||||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
||||||
} catch (IOException | HardinessZoneNotSetException e) {
|
} catch (IOException | HardinessZoneNotSetException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -188,6 +188,7 @@ class GardenScheduleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException {
|
void planTasksForCrop() throws HardinessZoneNotSetException, PlantNotFoundException, IOException {
|
||||||
|
assertThrows(PlantNotFoundException.class,()-> model.planTasksForCrop(new Crop()));
|
||||||
model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30));
|
model.planTasksForCrop(new Crop(20, exampleStartDate).withId(30));
|
||||||
verify(exampleTaskTemplateList.get(0), times(1)).generateTask(exampleStartDate, 30);
|
verify(exampleTaskTemplateList.get(0), times(1)).generateTask(exampleStartDate, 30);
|
||||||
verify(exampleTaskTemplateList.get(1), times(1)).generateTask(exampleStartDate, 30);
|
verify(exampleTaskTemplateList.get(1), times(1)).generateTask(exampleStartDate, 30);
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"plantId": 1,
|
||||||
|
"startDate": "2023-02-25",
|
||||||
|
"area": 0.5
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue