Forráskód Böngészése

CertificateType added

Andrew Grant 6 hónapja
szülő
commit
7a9d4dde24

+ 71 - 0
src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorCertificateTypeTest.java

@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 19/03/2025, 11:37. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.validators.certificates;
+
+
+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 org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.verify;
+import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
+import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
+import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomOrganisation;
+
+@ExtendWith(MockitoExtension.class)
+class BirthCertificateCommandValidatorCertificateTypeTest {
+
+    private BirthCertificateCommandValidator commandValidator;
+
+    private ArgumentCaptor<String> stringArgumentCaptor;
+    private ArgumentCaptor<String> stringArgumentCaptor2;
+    private ArgumentCaptor<String> stringArgumentCaptor3;
+    private ArgumentCaptor<Object[]> objectArgumentCaptor;
+
+    private BirthCertificateCommand birthCertificateCommand;
+
+    @Mock
+    BindingResult bindingResultMock;
+
+    @BeforeEach
+    void setUp() {
+        commandValidator = new BirthCertificateCommandValidator();
+        stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
+        stringArgumentCaptor2 = ArgumentCaptor.forClass(String.class);
+        stringArgumentCaptor3 = ArgumentCaptor.forClass(String.class);
+        objectArgumentCaptor = ArgumentCaptor.forClass(Object[].class);
+
+        birthCertificateCommand = new BirthCertificateCommandImpl();
+        birthCertificateCommand.setCertificateDate("25/01/1953");
+        birthCertificateCommand.setNewBorn(GetRandomPerson());
+        birthCertificateCommand.setCertificateNumber(Long.toString(GetRandomLong()));
+        birthCertificateCommand.setCertificateSource(GetRandomOrganisation());
+    }
+
+    @Test
+    public void nullTypeTest() {
+        commandValidator.validate(birthCertificateCommand, bindingResultMock);
+
+        verify(bindingResultMock).rejectValue(stringArgumentCaptor.capture(),
+                stringArgumentCaptor2.capture(),
+                objectArgumentCaptor.capture(),
+                stringArgumentCaptor3.capture());
+
+        assertEquals("certificateType", stringArgumentCaptor.getValue());
+        assertEquals("The certificate type cannot be null.", stringArgumentCaptor3.getValue());
+
+    }
+
+
+
+}