|
@@ -8,44 +8,39 @@ package scot.carricksoftware.grantswriter.data;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
+import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
+import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
import scot.carricksoftware.grantswriter.domains.census.Census;
|
|
|
import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
|
|
|
-import scot.carricksoftware.grantswriter.domains.places.Country;
|
|
|
import scot.carricksoftware.grantswriter.domains.places.Place;
|
|
|
-import scot.carricksoftware.grantswriter.domains.places.Region;
|
|
|
import scot.carricksoftware.grantswriter.enums.census.CensusDate;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
-import java.util.SortedMap;
|
|
|
import java.util.SortedSet;
|
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
|
|
|
+import static scot.carricksoftware.grantswriter.GenerateRandomPlaceValues.GetRandomPlace;
|
|
|
|
|
|
-
|
|
|
+@ExtendWith(MockitoExtension.class)
|
|
|
public class TimelineDataAddTest {
|
|
|
|
|
|
@SuppressWarnings({"unused"})
|
|
|
private TimelineData timelineData;
|
|
|
private List<CensusEntry> censusEntryList;
|
|
|
- private Place place;
|
|
|
- private CensusDate censusDate;
|
|
|
private CensusEntry censusEntry;
|
|
|
+ Census census;
|
|
|
|
|
|
@BeforeEach
|
|
|
void setUp() {
|
|
|
timelineData = new TimelineDataImpl();
|
|
|
- Country country = getRandomCountry();
|
|
|
- Region region = getRandomRegion();
|
|
|
- region.setCountry(country);
|
|
|
- place = getRandomPlace();
|
|
|
- place.setRegion(region);
|
|
|
+ Place place = GetRandomPlace();
|
|
|
|
|
|
- Census census = new Census();
|
|
|
+ census = new Census();
|
|
|
census.setPlace(place);
|
|
|
- censusDate = CensusDate.CENSUS_1861;
|
|
|
census.setCensusDate(CensusDate.CENSUS_1861);
|
|
|
|
|
|
censusEntry = new CensusEntry();
|
|
@@ -56,36 +51,44 @@ public class TimelineDataAddTest {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unused")
|
|
|
@Test
|
|
|
- void addTestWhereTest() {
|
|
|
+ void placeTest() {
|
|
|
+ Place place = GetRandomPlace();
|
|
|
+ census.setPlace(place);
|
|
|
timelineData.add(censusEntryList);
|
|
|
- SortedMap<String, String> timeline = timelineData.getTimeline();
|
|
|
- String required = "Recorded as being at " + place.toString();
|
|
|
+ LinkedMultiValueMap<String, String> timeline = timelineData.getTimeline();
|
|
|
+ String required = "Recorded as being at " + place;
|
|
|
|
|
|
- assertTrue(timeline.containsKey(censusDate.label));
|
|
|
- assertTrue(timeline.containsValue(required));
|
|
|
+ assertTrue(isFound(timeline, required));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void addTestOccupationTest() {
|
|
|
+ void occupationTest() {
|
|
|
String occupation = GetRandomString();
|
|
|
censusEntry.setPersonalOccupation(occupation);
|
|
|
timelineData.add(censusEntryList);
|
|
|
- SortedMap<String, String> timeline = timelineData.getTimeline();
|
|
|
+ LinkedMultiValueMap<String, String> timeline = timelineData.getTimeline();
|
|
|
String required = "Occupation recorded as " + occupation;
|
|
|
|
|
|
- assertTrue(timeline.containsValue(required));
|
|
|
+ assertTrue(isFound(timeline, required));
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- void addTestNoOccupationTest() {
|
|
|
- timelineData.add(censusEntryList);
|
|
|
- SortedMap<String, String> timeline = timelineData.getTimeline();
|
|
|
-
|
|
|
- assertFalse(timeline.containsValue("Occupation"));
|
|
|
+ private boolean isFound(LinkedMultiValueMap<String, String> timeline, String required) {
|
|
|
+ boolean found = false;
|
|
|
+ Collection<List <String>> test = timeline.values();
|
|
|
+
|
|
|
+ for (List<String> list : test) {
|
|
|
+ for (String s : list) {
|
|
|
+ if (s.equals(required)) {
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return found;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Test
|
|
|
void refsTest() {
|
|
|
timelineData.add(censusEntryList);
|
|
@@ -93,22 +96,6 @@ public class TimelineDataAddTest {
|
|
|
assertTrue(refs.contains(censusEntry.getCensus().toString()));
|
|
|
}
|
|
|
|
|
|
- private Place getRandomPlace() {
|
|
|
- Place place = new Place();
|
|
|
- place.setName(GetRandomString());
|
|
|
- return place;
|
|
|
- }
|
|
|
|
|
|
- private Region getRandomRegion() {
|
|
|
- Region region = new Region();
|
|
|
- region.setName(GetRandomString());
|
|
|
- return region;
|
|
|
- }
|
|
|
-
|
|
|
- private Country getRandomCountry() {
|
|
|
- Country country = new Country();
|
|
|
- country.setName(GetRandomString());
|
|
|
- return country;
|
|
|
- }
|
|
|
|
|
|
}
|