Эх сурвалжийг харах

GatherDeathCertificateDeceasedTimeLineDateDeceasedTest

Andrew Grant 2 сар өмнө
parent
commit
744db79826

+ 4 - 3
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/deathcertificate/GatherDeathCertificateDeceasedTimeLineDataImpl.java

@@ -34,7 +34,7 @@ public class GatherDeathCertificateDeceasedTimeLineDataImpl implements GatherDea
         logger.info("GatherDeathCertificateDeceasedTimeLineDataImpl::Gather");
         for (DeathCertificate deathCertificate : deathCertificates) {
             addWhenDied(timelineData.getTimeLine(), deathCertificate);
-            addWhenRegistered(timelineData.getTimeLine(), deathCertificate);
+            addWhereRegistered(timelineData.getTimeLine(), deathCertificate);
             addRefs(deathCertificate);
         }
     }
@@ -62,7 +62,7 @@ public class GatherDeathCertificateDeceasedTimeLineDataImpl implements GatherDea
     }
 
     @SuppressWarnings("unused")
-    private void addWhenRegistered(TreeMap<DMY, List<String>> timeLine, DeathCertificate deathCertificate) {
+    private void addWhereRegistered(TreeMap<DMY, List<String>> timeLine, DeathCertificate deathCertificate) {
         logger.info("GatherDeathCertificateDeceasedTimeLineDataImpl::AddWhenRegistered");
 
         if (deathCertificate.getWhenRegistered() != null  && !deathCertificate.getWhenRegistered().isEmpty()) {
@@ -86,7 +86,8 @@ public class GatherDeathCertificateDeceasedTimeLineDataImpl implements GatherDea
             } else {
                 informant = deathCertificate.getUntrackedInformant();
             }
-            existingValues.add("Death Registered by " + informant + " at " + whereRegistered);
+            var debug = deathCertificate.getWhereRegistered();
+            existingValues.add("Death registered by " + informant + " at " + whereRegistered);
             timeLine.put(getDMY(deathCertificate.getWhenRegistered()), existingValues);
         }
     }

+ 100 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/deathcertificate/GatherDeathCertificateDeceasedTimeLineDataWhenRegisteredTest.java

@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate;
+
+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.DMY;
+import scot.carricksoftware.grantswriter.data.TimeLineData;
+import scot.carricksoftware.grantswriter.domains.certificates.deathcertificate.DeathCertificate;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.domains.places.Organisation;
+import scot.carricksoftware.grantswriter.domains.places.Place;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertTrue;
+import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grantswriter.GenerateRandomPeopleValues.GetRandomPerson;
+import static scot.carricksoftware.grantswriter.GenerateRandomPlaceValues.GetRandomPlace;
+
+@ExtendWith(MockitoExtension.class)
+class GatherDeathCertificateDeceasedTimeLineDataWhenRegisteredTest {
+
+    GatherDeathCertificateDeceasedTimeLineData gatherDeathCertificateDeceasedTimeLineData;
+
+    @Mock
+    private TimeLineData timelineDataMock;
+
+    private List<DeathCertificate> deathCertificates;
+
+    private TreeMap<DMY, List<String>> timeLine ;
+
+    private Place place;
+
+    private Person deceased;
+
+    private Organisation registrationAuthority;
+
+    private Person informant;
+
+    private String whereRegistered;
+
+    @BeforeEach
+    void setUp() {
+        gatherDeathCertificateDeceasedTimeLineData = new GatherDeathCertificateDeceasedTimeLineDataImpl(this.timelineDataMock);
+        deathCertificates = new ArrayList<>();
+
+        DeathCertificate deathCertificate = new DeathCertificate();
+        timeLine = new TreeMap<>();
+        place = GetRandomPlace();
+        registrationAuthority = new Organisation();
+        registrationAuthority.setName(place.getName());
+        deceased = GetRandomPerson();
+        informant = GetRandomPerson();
+        whereRegistered = GetRandomString();
+        setUpCertificate(deathCertificate);
+        deathCertificates.add(deathCertificate);
+
+    }
+
+    private void setUpCertificate(DeathCertificate deathCertificate) {
+        deathCertificate.setWhenDied("25/01/1953 01:01");
+        deathCertificate.setWhenRegistered("25/01/1953 01:01");
+        deathCertificate.setWhereRegistered(whereRegistered);
+        deathCertificate.setWhereDied(place);
+        deathCertificate.setDeceased(deceased);
+        deathCertificate.setRegistrationAuthority(registrationAuthority);
+        deathCertificate.setInformant(informant);
+    }
+
+    @Test
+    void registeredByTest() {
+        when(timelineDataMock.getTimeLine()).thenReturn(timeLine);
+        gatherDeathCertificateDeceasedTimeLineData.gather(deathCertificates);
+        String expected = "Death registered by " + informant + " at " + whereRegistered;
+        assertTrue(timelineContains(expected));
+    }
+
+    private boolean timelineContains(String expected) {
+        for (Map.Entry<DMY, List<String>> dmyListEntry : timeLine.entrySet()) {
+            List<String> list = dmyListEntry.getValue();
+            if (list.contains(expected)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+}

+ 2 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/deathcertificate/GatherDeathCertificateDeceasedTimeLineDataWhereDiedTest.java

@@ -23,6 +23,7 @@ import java.util.TreeMap;
 
 import static org.mockito.Mockito.when;
 import static org.testng.Assert.assertTrue;
+import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
 import static scot.carricksoftware.grantswriter.GenerateRandomPeopleValues.GetRandomPerson;
 import static scot.carricksoftware.grantswriter.GenerateRandomPlaceValues.GetRandomPlace;
 
@@ -63,6 +64,7 @@ class GatherDeathCertificateDeceasedTimeLineDataWhereDiedTest {
         deathCertificate.setWhenDied("25/01/1953 01:01");
         deathCertificate.setWhenRegistered("25/01/1953 01:01");
         deathCertificate.setWhereDied(place);
+        deathCertificate.setWhereRegistered(GetRandomString());
         deathCertificate.setDeceased(deceased);
         deathCertificate.setRegistrationAuthority(registrationAuthority);
     }