Selaa lähdekoodia

MarriageCertificateGroomCommandConverterTest

Andrew Grant 4 kuukautta sitten
vanhempi
commit
797007f010
11 muutettua tiedostoa jossa 128 lisäystä ja 91 poistoa
  1. 14 14
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/MarriageCertificateCommandConverterImpl.java
  2. 1 1
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateBrideCommandConverter.java
  3. 1 1
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateBrideCommandConverterImpl.java
  4. 15 0
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateCertificateCommandConverter.java
  5. 26 0
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateCertificateCommandConverterImpl.java
  6. 1 1
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateGroomCommandConverter.java
  7. 1 1
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateGroomCommandConverterImpl.java
  8. 15 0
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateWitnessCommandConverter.java
  9. 24 0
      src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateWitnessCommandConverterImpl.java
  10. 2 2
      src/test/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/MarriageCertificateBrideCommandConverterTest.java
  11. 28 71
      src/test/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/MarriageCertificateCommandConverterTest.java

+ 14 - 14
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/MarriageCertificateCommandConverterImpl.java

@@ -7,8 +7,10 @@ package scot.carricksoftware.grants.converters.certificates.marriagecertificates
 
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
-import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.MarriageCertificateBrideCommandConverter;
-import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.MarriageCertificateGroomCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateBrideCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateCertificateCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateGroomCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateWitnessCommandConverter;
 import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
 
 @Component
@@ -16,10 +18,17 @@ public class MarriageCertificateCommandConverterImpl implements MarriageCertific
 
     private final MarriageCertificateBrideCommandConverter brideConverter;
     private final MarriageCertificateGroomCommandConverter groomConverter;
+    private final MarriageCertificateWitnessCommandConverter witnessConverter;
+    private final MarriageCertificateCertificateCommandConverter certificateConverter;
 
-    public MarriageCertificateCommandConverterImpl(MarriageCertificateBrideCommandConverter brideConverter, MarriageCertificateGroomCommandConverter groomConverter) {
+    public MarriageCertificateCommandConverterImpl(MarriageCertificateBrideCommandConverter brideConverter,
+                                                   MarriageCertificateGroomCommandConverter groomConverter,
+                                                   MarriageCertificateWitnessCommandConverter witnessConverter,
+                                                   MarriageCertificateCertificateCommandConverter certificateConverter) {
         this.brideConverter = brideConverter;
         this.groomConverter = groomConverter;
+        this.witnessConverter = witnessConverter;
+        this.certificateConverter = certificateConverter;
     }
 
     @Override
@@ -27,17 +36,8 @@ public class MarriageCertificateCommandConverterImpl implements MarriageCertific
         MarriageCertificate target = new MarriageCertificate();
         brideConverter.convert(source, target);
         groomConverter.convert(source, target);
-
-        target.setId(source.getId());
-        target.setNumber(source.getNumber());
-        target.setRegistrationAuthority(source.getRegistrationAuthority());
-        target.setSecondWitness(source.getSecondWitness());
-        target.setUntrackedFirstWitness(source.getUntrackedFirstWitness());
-        target.setUntrackedSecondWitness(source.getUntrackedSecondWitness());
-        target.setUntrackedWhereMarried(source.getUntrackedWhereMarried());
-        target.setVolume(source.getVolume());
-        target.setWhenMarried(source.getWhenMarried());
-        target.setWhereMarried(source.getWhereMarried());
+        witnessConverter.convert(source, target);
+        certificateConverter.convert(source, target);
 
         return target;
     }

+ 1 - 1
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/MarriageCertificateBrideCommandConverter.java → src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateBrideCommandConverter.java

@@ -3,7 +3,7 @@
  *
  */
 
-package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers;
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
 
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
 import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;

+ 1 - 1
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/MarriageCertificateBrideCommandConverterImpl.java → src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateBrideCommandConverterImpl.java

@@ -3,7 +3,7 @@
  *
  */
 
-package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers;
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
 
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;

+ 15 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateCertificateCommandConverter.java

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
+
+import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
+import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
+
+public interface MarriageCertificateCertificateCommandConverter {
+
+    void convert(MarriageCertificateCommand source, MarriageCertificate target);
+
+}

+ 26 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateCertificateCommandConverterImpl.java

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
+import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
+
+@Component
+public class MarriageCertificateCertificateCommandConverterImpl implements MarriageCertificateCertificateCommandConverter {
+
+    @Override
+    public void convert(MarriageCertificateCommand source, MarriageCertificate target) {
+
+        target.setId(source.getId());
+        target.setNumber(source.getNumber());
+        target.setRegistrationAuthority(source.getRegistrationAuthority());
+        target.setUntrackedWhereMarried(source.getUntrackedWhereMarried());
+        target.setVolume(source.getVolume());
+        target.setWhenMarried(source.getWhenMarried());
+        target.setWhereMarried(source.getWhereMarried());
+    }
+}

+ 1 - 1
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/MarriageCertificateGroomCommandConverter.java → src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateGroomCommandConverter.java

@@ -3,7 +3,7 @@
  *
  */
 
-package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers;
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
 
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
 import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;

+ 1 - 1
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/MarriageCertificateGroomCommandConverterImpl.java → src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateGroomCommandConverterImpl.java

@@ -3,7 +3,7 @@
  *
  */
 
-package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers;
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
 
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;

+ 15 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateWitnessCommandConverter.java

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
+
+import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
+import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
+
+public interface MarriageCertificateWitnessCommandConverter {
+
+    void convert(MarriageCertificateCommand source, MarriageCertificate target);
+
+}

+ 24 - 0
src/main/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/helpers/command/MarriageCertificateWitnessCommandConverterImpl.java

@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
+import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
+
+@Component
+public class MarriageCertificateWitnessCommandConverterImpl implements MarriageCertificateWitnessCommandConverter {
+
+    @Override
+    public void convert(MarriageCertificateCommand source, MarriageCertificate target) {
+
+        target.setSecondWitness(source.getFirstWitness());
+        target.setSecondWitness(source.getSecondWitness());
+        target.setUntrackedFirstWitness(source.getUntrackedFirstWitness());
+        target.setUntrackedSecondWitness(source.getUntrackedSecondWitness());
+
+    }
+}

+ 2 - 2
src/test/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/MarriageCertificateBrideCommandConverterTest.java

@@ -10,8 +10,8 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommandImpl;
-import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.MarriageCertificateBrideCommandConverter;
-import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.MarriageCertificateBrideCommandConverterImpl;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateBrideCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateBrideCommandConverterImpl;
 import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;

+ 28 - 71
src/test/java/scot/carricksoftware/grants/converters/certificates/marriagecertificates/MarriageCertificateCommandConverterTest.java

@@ -13,16 +13,13 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommand;
 import scot.carricksoftware.grants.commands.certificates.marriagecertificates.MarriageCertificateCommandImpl;
-import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.MarriageCertificateBrideCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateBrideCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateCertificateCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateGroomCommandConverter;
+import scot.carricksoftware.grants.converters.certificates.marriagecertificates.helpers.command.MarriageCertificateWitnessCommandConverter;
 import scot.carricksoftware.grants.domains.certificates.MarriageCertificate;
-import scot.carricksoftware.grants.enums.certificates.CertificateType;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
-import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
-import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
-import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomOrganisation;
-import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
+import static org.mockito.Mockito.verify;
 
 @ExtendWith(MockitoExtension.class)
 class MarriageCertificateCommandConverterTest {
@@ -32,74 +29,34 @@ class MarriageCertificateCommandConverterTest {
     @Mock
     private MarriageCertificateBrideCommandConverter marriageCertificateBrideConverterMock;
 
-    @BeforeEach
-    void setUp() {
-        converter = new MarriageCertificateCommandConverterImpl(marriageCertificateBrideConverterMock);
-    }
-
-    @Test
-    void convertTest() {
-
-        MarriageCertificateCommand source = new MarriageCertificateCommandImpl();
+    @Mock
+    private MarriageCertificateGroomCommandConverter marriageCertificateGroomConverterMock;
 
-        source.setCertificateDate(GetRandomString());
-        source.setCertificateNumber(GetRandomString());
-        source.setCertificateSource(GetRandomOrganisation());
-        source.setCertificateType(CertificateType.EXTRACT);
-        source.setFirstWitness(GetRandomPerson());
-        source.setGroom(GetRandomPerson());
-        source.setGroomAge(GetRandomString());
-        source.setGroomCondition(GetRandomString());
-        source.setGroomFather(GetRandomPerson());
-        source.setGroomFatherRank(GetRandomString());
-        source.setGroomRank(GetRandomString());
-        source.setGroomUntrackedFather(GetRandomString());
-        source.setGroomUntrackedResidence(GetRandomString());
-        source.setGroomUsualResidence(GetRandomPlace());
-        source.setId(GetRandomLong());
-        source.setNumber(GetRandomString());
-        source.setRegistrationAuthority(GetRandomOrganisation());
-        source.setSecondWitness(GetRandomPerson());
-        source.setUntrackedFirstWitness(GetRandomString());
-        source.setUntrackedSecondWitness(GetRandomString());
-        source.setUntrackedWhereMarried(GetRandomString());
-        source.setVolume(GetRandomString());
-        source.setWhenMarried(GetRandomString());
-        source.setWhereMarried(GetRandomPlace());
+    @Mock
+    private MarriageCertificateWitnessCommandConverter marriageCertificateWitnessConverterMock;
 
+    @Mock
+    private MarriageCertificateCertificateCommandConverter marriageCertificateCertificateConverterMock;
 
-        MarriageCertificate target = converter.convert(source);
+    private MarriageCertificateCommand marriageCertificateCommand;
 
-        assert target != null;
-        assertEquals(source.getCertificateDate(), target.getCertificateDate());
-        assertEquals(source.getCertificateNumber(), target.getCertificateNumber());
-        assertEquals(source.getCertificateSource(), target.getCertificateSource());
-        assertEquals(source.getCertificateType(), target.getCertificateType());
-        assertEquals(source.getFirstWitness(), target.getFirstWitness());
-        assertEquals(source.getFirstWitness(), target.getFirstWitness());
-        assertEquals(source.getGroom(), target.getGroom());
-        assertEquals(source.getGroomAge(), target.getGroomAge());
-        assertEquals(source.getGroomCondition(), target.getGroomCondition());
-        assertEquals(source.getGroomFather(), target.getGroomFather());
-        assertEquals(source.getGroomFatherRank(), target.getGroomFatherRank());
-        assertEquals(source.getGroomRank(), target.getGroomRank());
-        assertEquals(source.getGroomRank(), target.getGroomRank());
-        assertEquals(source.getGroomUntrackedFather(), target.getGroomUntrackedFather());
-        assertEquals(source.getGroomUntrackedResidence(), target.getGroomUntrackedResidence());
-        assertEquals(source.getGroomUsualResidence(), target.getGroomUsualResidence());
-        assertEquals(source.getId(), target.getId());
-        assertEquals(source.getNumber(), target.getNumber());
-        assertEquals(source.getRegistrationAuthority(), target.getRegistrationAuthority());
-        assertEquals(source.getSecondWitness(), target.getSecondWitness());
-        assertEquals(source.getSecondWitness(), target.getSecondWitness());
-        assertEquals(source.getUntrackedFirstWitness(), target.getUntrackedFirstWitness());
-        assertEquals(source.getUntrackedSecondWitness(), target.getUntrackedSecondWitness());
-        assertEquals(source.getUntrackedWhereMarried(), target.getUntrackedWhereMarried());
-        assertEquals(source.getVolume(), target.getVolume());
-        assertEquals(source.getWhenMarried(), target.getWhenMarried());
-        assertEquals(source.getWhereMarried(), target.getWhereMarried());
-        assertEquals(source.getWhereMarried(), target.getWhereMarried());
 
+    @BeforeEach
+    void setUp() {
+        converter = new MarriageCertificateCommandConverterImpl(
+                marriageCertificateBrideConverterMock,
+                marriageCertificateGroomConverterMock,
+                marriageCertificateWitnessConverterMock,
+                marriageCertificateCertificateConverterMock);
+        marriageCertificateCommand = new MarriageCertificateCommandImpl();
+    }
 
+    @Test
+    void helpersGetCalledTest() {
+        MarriageCertificate certificate = converter.convert(marriageCertificateCommand);
+        verify(marriageCertificateBrideConverterMock).convert(marriageCertificateCommand, certificate);
+        verify(marriageCertificateGroomConverterMock).convert(marriageCertificateCommand, certificate);
+        verify(marriageCertificateWitnessConverterMock).convert(marriageCertificateCommand, certificate);
+        verify(marriageCertificateCertificateConverterMock).convert(marriageCertificateCommand, certificate);
     }
 }