Compare commits

..

No commits in common. "146c43d5d9cf792a3aa916348bd5a5fac477ff04" and "1e14a07ef8e7b34174b427b521d887ab23f08315" have entirely different histories.

3 changed files with 8 additions and 48 deletions

View File

@ -1,6 +1,5 @@
package ch.zhaw.gartenverwaltung.io; package ch.zhaw.gartenverwaltung.io;
import ch.zhaw.gartenverwaltung.types.GrowthPhase;
import ch.zhaw.gartenverwaltung.types.HardinessZone; import ch.zhaw.gartenverwaltung.types.HardinessZone;
import ch.zhaw.gartenverwaltung.types.Plant; import ch.zhaw.gartenverwaltung.types.Plant;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -83,12 +82,6 @@ public class JsonPlantDatabase implements PlantDatabase {
result = mapper.readerForListOf(Plant.class).readValue(dataSource); result = mapper.readerForListOf(Plant.class).readValue(dataSource);
for (Plant plant : result) { for (Plant plant : result) {
// for discussion because of failing tests:
// for(GrowthPhase growthPhase: plant.lifecycle()) {
// if(growthPhase.zone()==zone) {
// keep in result, remove if no match
// }
// }
plant.inZone(currentZone); plant.inZone(currentZone);
} }

View File

@ -30,7 +30,7 @@
"name": "Germinate", "name": "Germinate",
"relativeStartDate": -14, "relativeStartDate": -14,
"relativeEndDate": null, "relativeEndDate": null,
"description": "Take an egg carton and fill it with soil. Put the seedling deep enough so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.", "description": "\"Take an egg carton and fill it with soil. Put the seedling deep enaugh so its half covered with soil. Keep it in 10-15 * Celsius with lots of light.\"",
"interval": null, "interval": null,
"isOptional": false "isOptional": false
} }
@ -52,7 +52,7 @@
"name": "hilling", "name": "hilling",
"relativeStartDate": 0, "relativeStartDate": 0,
"relativeEndDate": null, "relativeEndDate": null,
"description": "When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.", "description": "\"When the plants are 20 cm tall, begin hilling the potatoes by gently mounding the soil from the center of your rows around the stems of the plant. Mound up the soil around the plant until just the top few leaves show above the soil. Two weeks later, hill up the soil again when the plants grow another 20 cm.\"",
"interval": 21, "interval": 21,
"isOptional": false "isOptional": false
} }

View File

@ -26,7 +26,7 @@ public class JsonPlantDatabaseTest {
@Test @Test
@DisplayName("Check if results are retrieved completely") @DisplayName("Check if results are retrieved completely")
void getPlantListNotEmpty() { void getPlantList() {
List<Plant> testList; List<Plant> testList;
try { try {
testList = testDatabase.getPlantList(HardinessZone.ZONE_8A); testList = testDatabase.getPlantList(HardinessZone.ZONE_8A);
@ -42,47 +42,13 @@ public class JsonPlantDatabaseTest {
Assertions.assertEquals(expected,names); Assertions.assertEquals(expected,names);
} }
@Test
@DisplayName("Check if results are retrieved correctly when empty")
void getPlantListEmpty() {
List<Plant> testList;
try {
testList = testDatabase.getPlantList(HardinessZone.ZONE_1A);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (HardinessZoneNotSetException e) {
throw new RuntimeException(e);
}
Assertions.assertEquals(0, testList.size());
}
@Test @Test
@DisplayName("Check whether single access works.") @DisplayName("Check whether single access works.")
void getPlantByIdAndZone() { void getPlantById() {
Optional<Plant> testPlant; Optional<Plant> testPlant;
try { try {
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 1); testDatabase.getPlantList(HardinessZone.ZONE_8A);
} catch (IOException e) { testPlant = testDatabase.getPlantById(1);
throw new RuntimeException(e);
} catch (HardinessZoneNotSetException e) {
throw new RuntimeException(e);
}
Assertions.assertTrue(testPlant.isPresent());
Assertions.assertEquals("Early Carrot", testPlant.get().name());
}
@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) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (HardinessZoneNotSetException e) { } catch (HardinessZoneNotSetException e) {
@ -97,7 +63,8 @@ public class JsonPlantDatabaseTest {
void getPlantByIdMustFail() { void getPlantByIdMustFail() {
Optional<Plant> testPlant; Optional<Plant> testPlant;
try { try {
testPlant = testDatabase.getPlantById(HardinessZone.ZONE_8A, 99); testDatabase.getPlantList(HardinessZone.ZONE_8A);
testPlant = testDatabase.getPlantById(99);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (HardinessZoneNotSetException e) { } catch (HardinessZoneNotSetException e) {