Merge remote-tracking branch 'origin/feature_json-gardenplan_M2' into feature_json-task-db_M2
# Conflicts: # build.gradle
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package ch.zhaw.gartenverwaltung.io;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonPlantDatabaseTest {
|
||||
PlantDatabase testDatabase;
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
|
||||
|
||||
@BeforeEach
|
||||
void connectToDb() {
|
||||
testDatabase = new JsonPlantDatabase();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Check if results are retrieved completely")
|
||||
void getPlantList() {
|
||||
List<Plant> testList;
|
||||
try {
|
||||
testList = testDatabase.getPlantList(HardinessZone.ZONE_8A);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Assertions.assertEquals(3, testList.size());
|
||||
|
||||
List<String> names = testList.stream().map(Plant::name).collect(Collectors.toList());
|
||||
List<String> expected = Arrays.asList("Potato","Early Carrot","Summertime Onion");
|
||||
Assertions.assertEquals(expected,names);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check whether single access works.")
|
||||
void getPlantById() {
|
||||
Optional<Plant> testPlant;
|
||||
try {
|
||||
testDatabase.getPlantList(HardinessZone.ZONE_8A);
|
||||
testPlant = testDatabase.getPlantById(1);
|
||||
} catch (IOException e) {
|
||||
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 for a nonexisting plant.")
|
||||
void getPlantByIdMustFail() {
|
||||
Optional<Plant> testPlant;
|
||||
try {
|
||||
testDatabase.getPlantList(HardinessZone.ZONE_8A);
|
||||
testPlant = testDatabase.getPlantById(99);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (HardinessZoneNotSetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Assertions.assertFalse(testPlant.isPresent());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user