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

Military attributes added to certificate converter

Andrew Grant 4 сар өмнө
parent
commit
4aa90d3ba2

+ 2 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/deathcertificates/DeathCertificateCommandConverterImpl.java

@@ -13,6 +13,8 @@ import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
 @Component
 public class DeathCertificateCommandConverterImpl implements DeathCertificateCommandConverter {
 
+
+
     @Override
     public DeathCertificate convert(DeathCertificateCommand source) {
 

+ 7 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/deathcertificates/DeathCertificateConverterImpl.java

@@ -15,10 +15,17 @@ import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
 @Component
 public class DeathCertificateConverterImpl implements DeathCertificateConverter {
 
+    private final DeathCertificateMilitaryConverter militaryConverter;
+
+    public DeathCertificateConverterImpl(DeathCertificateMilitaryConverter militaryConverter) {
+        this.militaryConverter = militaryConverter;
+    }
+
     @Override
     public DeathCertificateCommand convert(DeathCertificate source) {
         DeathCertificateCommand target = new DeathCertificateCommandImpl();
 
+        militaryConverter.convert(source, target);
         target.setAge(source.getAge());
         target.setCauseOfDeath(source.getCauseOfDeath());
         target.setCertificateDate(source.getCertificateDate());

+ 14 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/deathcertificates/DeathCertificateMilitaryConverter.java

@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.deathcertificates;
+
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
+
+public interface DeathCertificateMilitaryConverter {
+
+    void convert(DeathCertificate source, DeathCertificateCommand target);
+}

+ 22 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/deathcertificates/DeathCertificateMilitaryConverterImpl.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.deathcertificates;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
+
+
+@Component
+public class DeathCertificateMilitaryConverterImpl implements DeathCertificateMilitaryConverter {
+
+    @Override
+    public void convert(DeathCertificate source, DeathCertificateCommand target) {
+        target.setRegiment(source.getRegiment());
+        target.setServiceNumber(source.getServiceNumber());
+        target.setServiceRank(source.getServiceRank());
+    }
+}

+ 8 - 1
src/test/java/scot/carricksoftware/grants/converters/certificates/deathcertificates/DeathCertificateConverterTest.java

@@ -8,6 +8,9 @@ package scot.carricksoftware.grants.converters.certificates.deathcertificates;
 
 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.grants.domains.certificates.DeathCertificate;
 import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
 import scot.carricksoftware.grants.domains.people.Person;
@@ -24,14 +27,18 @@ import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPe
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomOrganisation;
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
 
+@ExtendWith(MockitoExtension.class)
 class DeathCertificateConverterTest {
 
     private DeathCertificateConverter converter;
     private DeathCertificate deathCertificate;
 
+    @Mock
+    private DeathCertificateMilitaryConverter militaryConverterMock;
+
     @BeforeEach
     void setUp() {
-        converter = new DeathCertificateConverterImpl();
+        converter = new DeathCertificateConverterImpl(militaryConverterMock);
         deathCertificate = new DeathCertificate();
     }
 

+ 49 - 0
src/test/java/scot/carricksoftware/grants/converters/certificates/deathcertificates/DeathCertificateMilitaryConverterTest.java

@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.deathcertificates;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommandImpl;
+import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+
+class DeathCertificateMilitaryConverterTest {
+
+    private DeathCertificateMilitaryConverter militaryConverter;
+    private DeathCertificate source;
+    private DeathCertificateCommand target;
+
+
+    @BeforeEach
+    void setUp() {
+        militaryConverter = new DeathCertificateMilitaryConverterImpl();
+        source = new DeathCertificate();
+        target = new DeathCertificateCommandImpl();
+    }
+
+    @Test
+    void convertTest() {
+        String regiment = GetRandomString();
+        String serviceNumber = GetRandomString();
+        String serviceRank = GetRandomString();
+
+        source.setRegiment(regiment);
+        source.setServiceNumber(serviceNumber);
+        source.setServiceRank(serviceRank);
+
+        militaryConverter.convert(source, target);
+
+        assertEquals(regiment, target.getRegiment());
+        assertEquals(serviceNumber, target.getServiceNumber());
+        assertEquals(serviceRank, target.getServiceRank());
+    }
+
+
+}