소스 검색

DeathCertificateUntrackedFieldsValidatorTest

Andrew Grant 4 달 전
부모
커밋
17aed7c7cc

+ 59 - 0
src/test/java/scot/carricksoftware/grants/validators/certificates/deathcertificate/DeathCertificateUntrackedFieldsValidatorTest.java

@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates.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 org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommandImpl;
+import scot.carricksoftware.grants.domains.people.Person;
+import scot.carricksoftware.grants.validators.helpers.ValidateTwoFieldTypes;
+
+import static org.mockito.Mockito.verify;
+import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
+
+@ExtendWith(MockitoExtension.class)
+class DeathCertificateUntrackedFieldsValidatorTest {
+
+    private DeathCertificateUntrackedFieldsValidator deathCertificateUntrackedFieldsValidator;
+
+    @Mock
+    private ValidateTwoFieldTypes validateTwoFieldTypesMock;
+
+    @Mock
+    private BindingResult bindingResultMock;
+
+    private DeathCertificateCommand deathCertificateCommand;
+
+    private Person spouse;
+    private String untrackedSpouse;
+
+
+    @BeforeEach
+    void setUp() {
+        deathCertificateUntrackedFieldsValidator = new DeathCertificateUntrackedFieldsValidatorImpl(validateTwoFieldTypesMock);
+        deathCertificateCommand = new DeathCertificateCommandImpl();
+        spouse = GetRandomPerson();
+        untrackedSpouse = GetRandomString();
+
+        deathCertificateCommand.setSpouse(spouse);
+        deathCertificateCommand.setUntrackedSpouse(untrackedSpouse);
+    }
+
+    @Test
+    void theTestAreRunTest() {
+        deathCertificateUntrackedFieldsValidator.validate(deathCertificateCommand, bindingResultMock);
+        verify(validateTwoFieldTypesMock).validatePersonAndUntrackedPerson(spouse, untrackedSpouse, "spouse", "untrackedSpouse",
+                "One and only one spouse and untracked spouse must be specified.", bindingResultMock);
+    }
+
+
+}