浏览代码

DeathCertificateCommand Bootstrap test

Andrew Grant 4 月之前
父节点
当前提交
8857065ce6

+ 5 - 4
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificates.java

@@ -35,7 +35,8 @@ public class DataLoadCertificates {
 
     public DataLoadCertificates(OrganisationService organisationService,
                                 BirthCertificateService birthCertificateService,
-                                PersonService personService, PlaceService placeService, DeathCertificateService deathCertificateService) {
+                                PersonService personService, PlaceService placeService,
+                                DeathCertificateService deathCertificateService) {
         this.organisationService = organisationService;
         this.birthCertificateService = birthCertificateService;
         this.personService = personService;
@@ -91,9 +92,9 @@ public class DataLoadCertificates {
         DeathCertificateCommand deathCertificateCommand = new DeathCertificateCommandImpl();
         deathCertificateCommand.setDeceased(personService.findById(1L));
         deathCertificateCommand.setFather(personService.findById(2L));
-        deathCertificateCommand.setInformant(personService.findById(1L));
-        deathCertificateCommand.setMother(personService.findById(2L));
-        deathCertificateCommand.setSpouse(personService.findById(2L));
+        deathCertificateCommand.setInformant(personService.findById(3L));
+        deathCertificateCommand.setMother(personService.findById(4L));
+        deathCertificateCommand.setSpouse(personService.findById(5L));
 
         deathCertificateService.saveDeathCertificateCommand(deathCertificateCommand);
     }

+ 31 - 2
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesDeathCertificatesTest.java

@@ -3,16 +3,20 @@ package scot.carricksoftware.grants.bootstrap;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.organisations.OrganisationService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
 
-import static org.mockito.ArgumentMatchers.any;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 
 @ExtendWith(MockitoExtension.class)
@@ -35,6 +39,18 @@ public class DataLoadCertificatesDeathCertificatesTest {
     @Mock
     private PlaceService placeServiceMock;
 
+    @SuppressWarnings("unused")
+    private Person father;
+    @SuppressWarnings("unused")
+    private Person mother;
+    @SuppressWarnings("unused")
+    private Person deceased;
+    @SuppressWarnings("unused")
+    private Person spouse;
+    @SuppressWarnings("unused")
+    private Person informant;
+
+
 
     @BeforeEach
     public void setup() {
@@ -44,12 +60,25 @@ public class DataLoadCertificatesDeathCertificatesTest {
                 personServiceMock,
                 placeServiceMock,
                 deathCertificateServiceMock);
+        when(personServiceMock.findById(1L)).thenReturn(deceased);
+        when(personServiceMock.findById(2L)).thenReturn(father);
+        when(personServiceMock.findById(3L)).thenReturn(informant);
+        when(personServiceMock.findById(4L)).thenReturn(mother);
+        when(personServiceMock.findById(5L)).thenReturn(spouse);
     }
 
     @Test
     void DeathCertificateIsCreatedTest() {
+        ArgumentCaptor<DeathCertificateCommand> captor = ArgumentCaptor.forClass(DeathCertificateCommand.class);
+
         dataLoadCertificates.load();
-        verify(deathCertificateServiceMock).saveDeathCertificateCommand(any());
+
+        verify(deathCertificateServiceMock).saveDeathCertificateCommand(captor.capture());
+        assertEquals(deceased, captor.getValue().getDeceased());
+        assertEquals(father, captor.getValue().getFather());
+        assertEquals(mother, captor.getValue().getMother());
+        assertEquals(spouse, captor.getValue().getSpouse());
+        assertEquals(informant, captor.getValue().getInformant());
     }
 
 }