#26 added fixed test files, made Crop class testable
This commit is contained in:
@@ -8,7 +8,6 @@ import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -16,7 +15,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class JsonPlantDatabaseTest {
|
||||
PlantDatabase testDatabase;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
|
||||
|
||||
@BeforeEach
|
||||
void connectToDb() {
|
||||
@@ -30,9 +28,7 @@ public class JsonPlantDatabaseTest {
|
||||
List<Plant> testList;
|
||||
try {
|
||||
testList = testDatabase.getPlantList(HardinessZone.ZONE_8A);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
} catch (IOException | HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Assertions.assertEquals(3, testList.size());
|
||||
@@ -48,9 +44,7 @@ public class JsonPlantDatabaseTest {
|
||||
List<Plant> testList;
|
||||
try {
|
||||
testList = testDatabase.getPlantList(HardinessZone.ZONE_1A);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
} catch (IOException | HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Assertions.assertEquals(0, testList.size());
|
||||
@@ -64,9 +58,7 @@ public class JsonPlantDatabaseTest {
|
||||
Optional<Plant> testPlant;
|
||||
try {
|
||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
} catch (IOException | HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Assertions.assertTrue(testPlant.isPresent());
|
||||
@@ -75,20 +67,12 @@ public class JsonPlantDatabaseTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Check whether single access respects zone correctly.")
|
||||
void getPlantByIdAndWrongZone() {
|
||||
Optional<Plant> testPlant;
|
||||
try {
|
||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_1A, 1);
|
||||
Assertions.assertFalse(testPlant.isPresent());
|
||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
||||
Assertions.assertTrue(testPlant.isPresent());
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
void getPlantByIdAndWrongZone() throws HardinessZoneNotSetException, IOException {
|
||||
Optional<Plant> testPlant = testDatabase.getPlantById(HardinessZone.ZONE_1A, 1);
|
||||
Assertions.assertFalse(testPlant.isPresent());
|
||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1);
|
||||
Assertions.assertTrue(testPlant.isPresent());
|
||||
|
||||
Assertions.assertEquals("Early Carrot", testPlant.get().name());
|
||||
}
|
||||
|
||||
@@ -98,9 +82,7 @@ public class JsonPlantDatabaseTest {
|
||||
Optional<Plant> testPlant;
|
||||
try {
|
||||
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 99);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
} catch (IOException | HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Assertions.assertFalse(testPlant.isPresent());
|
||||
|
||||
Reference in New Issue
Block a user