Selaa lähdekoodia

BirthCertificateCommandPartOneValidatorTest::getCertificateCertificateType() and ::getCertificateDate

Andrew Grant 6 kuukautta sitten
vanhempi
commit
66c55546bf

+ 10 - 0
src/test/java/scot/carricksoftware/grants/GenerateGeneralRandomEnums.java

@@ -6,6 +6,7 @@
 package scot.carricksoftware.grants;
 
 import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 import scot.carricksoftware.grants.enums.general.YesNo;
 
 import java.util.Random;
@@ -23,5 +24,14 @@ public class GenerateGeneralRandomEnums {
         return yesNoArray[randomInt];
     }
 
+    public static CertificateType GetRandomCertificateType() {
+
+        CertificateType[] certificateTypes = CertificateType.values();
+
+        Random random = new Random();
+        int randomInt = random.nextInt(0, certificateTypes.length);
+        return certificateTypes[randomInt];
+    }
+
 
 }

+ 26 - 0
src/test/java/scot/carricksoftware/grants/validators/certificates/birthcertificate/BirthCertificateCommandPartOneValidatorTest.java

@@ -14,11 +14,13 @@ import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Organisation;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
 import scot.carricksoftware.grants.validators.helpers.ValidateTypes;
 
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grants.GenerateGeneralRandomEnums.GetRandomCertificateType;
 
 @ExtendWith(MockitoExtension.class)
 class BirthCertificateCommandPartOneValidatorTest {
@@ -60,4 +62,28 @@ class BirthCertificateCommandPartOneValidatorTest {
         validator.validate(birthCertificateCommandMock, bindingResultMock);
         verify(validateTypesMock).validateOrganisation(birthCertificateCommandMock.getCertificateSource(), "certificateSource", "The certificate source cannot be null.", bindingResultMock);
     }
+
+    @Test
+    void validateCertificateTypeTest() {
+        CertificateType certificateType = GetRandomCertificateType();
+        when(birthCertificateCommandMock.getCertificateType()).thenReturn(certificateType);
+        validator.validate(birthCertificateCommandMock, bindingResultMock);
+        verify(validateTypesMock).validateCertificateType(certificateType, "certificateType", "The certificate type cannot be null.", bindingResultMock);
+    }
+
+    @Test
+    void validateCertificateDateTest() {
+        String string = GetRandomString();
+        when(birthCertificateCommandMock.getCertificateDate()).thenReturn(string);
+        validator.validate(birthCertificateCommandMock, bindingResultMock);
+        verify(validateTypesMock).validatePastDate(
+                string,
+                "certificateDate",
+                "The certificate date cannot be null.",
+                "The certificate date is invalid or of the wrong format.",
+                "Date should not be in the future.",
+                bindingResultMock);
+    }
+
+
 }