Bladeren bron

AddCensusEntry created

Andrew Grant 2 maanden geleden
bovenliggende
commit
177d746d8c

+ 0 - 22
src/main/java/scot/carricksoftware/grantswriter/data/TimeLineDataImpl.java

@@ -9,7 +9,6 @@ import org.springframework.stereotype.Component;
 import scot.carricksoftware.grantswriter.data.helpers.AddCensusEntry;
 import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -34,30 +33,9 @@ public class TimeLineDataImpl implements TimeLineData {
         this.refs = new TreeSet<>();
     }
 
-
     @Override
     public void addCensusEntry(List<CensusEntry> censusEntryList) {
         addCensusEntry.add(timeLine, refs, censusEntryList);
-        for (CensusEntry censusEntry : censusEntryList) {
-            String key = censusEntry.getCensus().getCensusDate().label;
-            DMY dmyKey = new DMYImpl();
-            dmyKey.parse(key);
-
-            List<String> existingValues = timeLine.get(dmyKey);
-            if (existingValues == null) {
-                existingValues = new ArrayList<>();
-            }
-            existingValues.add( "Recorded as being at " +
-                    censusEntry.getCensus().getPlace().toString());
-            timeLine.put(dmyKey, existingValues);
-
-            if (censusEntry.getPersonalOccupation() != null && !censusEntry.getPersonalOccupation().isEmpty()) {
-                existingValues.add("Occupation recorded as " +
-                                censusEntry.getPersonalOccupation());
-                timeLine.put(dmyKey, existingValues);
-            }
-            refs.add("Census: " + censusEntry.getCensus().toString());
-        }
     }
 
     @Override

+ 1 - 1
src/main/java/scot/carricksoftware/grantswriter/data/helpers/AddCensusEntry.java

@@ -15,5 +15,5 @@ import java.util.TreeMap;
 public interface AddCensusEntry {
 
     @SuppressWarnings({"EmptyMethod", "unused"})
-    void add(TreeMap<DMY, List<String>> timeline, SortedSet<String> refs, List<CensusEntry> censusEntryList);
+    void add(TreeMap<DMY, List<String>> timeLine, SortedSet<String> refs, List<CensusEntry> censusEntryList);
 }

+ 23 - 1
src/main/java/scot/carricksoftware/grantswriter/data/helpers/AddCensusEntryImpl.java

@@ -9,8 +9,10 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grantswriter.data.DMY;
+import scot.carricksoftware.grantswriter.data.DMYImpl;
 import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -21,7 +23,27 @@ public class AddCensusEntryImpl implements AddCensusEntry {
     private static final Logger logger = LogManager.getLogger(AddCensusEntryImpl.class);
 
     @Override
-    public void add(TreeMap<DMY, List<String>> timeline, SortedSet<String> refs, List<CensusEntry> censusEntryList) {
+    public void add(TreeMap<DMY, List<String>> timeLine, SortedSet<String> refs, List<CensusEntry> censusEntryList) {
         logger.info("AddCensusEntry::addCensusEntry");
+        for (CensusEntry censusEntry : censusEntryList) {
+            String key = censusEntry.getCensus().getCensusDate().label;
+            DMY dmyKey = new DMYImpl();
+            dmyKey.parse(key);
+
+            List<String> existingValues = timeLine.get(dmyKey);
+            if (existingValues == null) {
+                existingValues = new ArrayList<>();
+            }
+            existingValues.add("Recorded as being at " +
+                    censusEntry.getCensus().getPlace().toString());
+            timeLine.put(dmyKey, existingValues);
+
+            if (censusEntry.getPersonalOccupation() != null && !censusEntry.getPersonalOccupation().isEmpty()) {
+                existingValues.add("Occupation recorded as " +
+                        censusEntry.getPersonalOccupation());
+                timeLine.put(dmyKey, existingValues);
+            }
+            refs.add("Census: " + censusEntry.getCensus().toString());
+        }
     }
 }

+ 0 - 102
src/test/java/scot/carricksoftware/grantswriter/data/TimeLineDataAddTest.java

@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
- *
- */
-
-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.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import scot.carricksoftware.grantswriter.data.helpers.AddCensusEntry;
-import scot.carricksoftware.grantswriter.domains.census.Census;
-import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
-import scot.carricksoftware.grantswriter.domains.places.Place;
-import scot.carricksoftware.grantswriter.enums.census.CensusDate;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeMap;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.when;
-import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
-
-@ExtendWith(MockitoExtension.class)
-class TimeLineDataAddTest {
-
-
-    private TimeLineData timeLineData;
-
-    @Mock
-    private TimeLineDateComparator timeLineDateComparatorMock;
-
-    @Mock
-    private Place placeMock;
-
-    @Mock
-    private Census censusMock;
-
-    @Mock
-    AddCensusEntry addCensusEntryMock;
-
-    @BeforeEach
-    void setUp() {
-        timeLineData = new TimeLineDataImpl(addCensusEntryMock, timeLineDateComparatorMock);
-    }
-
-    @Test
-    void timeLineAddRefsTest() {
-        String censusString = GetRandomString();
-        List<CensusEntry> censusEntryList = new ArrayList<>();
-        CensusEntry censusEntry = new CensusEntry();
-
-        censusEntry.setCensus(censusMock);
-        censusEntryList.add(censusEntry);
-        when(censusMock.getCensusDate()).thenReturn(CensusDate.CENSUS_1861);
-        when(censusMock.getPlace()).thenReturn(placeMock);
-        when(censusMock.toString()).thenReturn(censusString);
-
-
-        SortedSet<String> refs;
-        timeLineData.addCensusEntry(censusEntryList);
-        refs = timeLineData.getRefs();
-
-        assertEquals("Census: " + censusString, refs.first());
-    }
-
-    @Test
-    void timeLineAddCensusEntryTest() {
-        List<CensusEntry> censusEntryList = new ArrayList<>();
-        CensusEntry censusEntry = new CensusEntry();
-
-        censusEntry.setCensus(censusMock);
-        censusEntry.setPersonalOccupation("Work");
-        censusEntryList.add(censusEntry);
-
-        when(placeMock.toString()).thenReturn("Edinburgh");
-
-        when(censusMock.getCensusDate()).thenReturn(CensusDate.CENSUS_1861);
-        when(censusMock.getPlace()).thenReturn(placeMock);
-
-
-        timeLineData.addCensusEntry(censusEntryList);
-
-        TreeMap<DMY, List<String>> timeLine = timeLineData.getTimeLine();
-
-        String requiredRecorded = "Recorded as being at Edinburgh";
-        String requiredOccupation = "Occupation recorded as Work";
-        assertEquals(1, timeLine.size());
-
-        Set<DMY> keys = timeLine.keySet();
-        for (DMY key : keys) {
-            List<String> values = timeLine.get(key);
-            assert (values.contains(requiredRecorded));
-            assert (values.contains(requiredOccupation));
-        }
-    }
-}