Sfoglia il codice sorgente

MarriageCertificateCommandValidatorTest - not the same person

Andrew Grant 7 mesi fa
parent
commit
95bed7c45f

+ 1 - 1
src/main/java/scot/carricksoftware/grants/validators/certificates/MarriageCertificateCommandValidator.java

@@ -44,7 +44,7 @@ public class MarriageCertificateCommandValidator {
     }
 
     private void validateBrideAndGroomTogether(MarriageCertificateCommand marriageCertificateCommand, BindingResult bindingResult) {
-        if (marriageCertificateCommand.getBride().equals(marriageCertificateCommand.getBride())) {
+        if (marriageCertificateCommand.getBride().equals(marriageCertificateCommand.getGroom())) {
             bindingResult.rejectValue("groom", ApplicationConstants.EMPTY_STRING,
                     null,
                     ValidationConstants.SAME_BRIDE_AND_GROOM);

+ 16 - 3
src/test/java/scot/carricksoftware/grants/validators/certificates/MarriageCertificateCommandValidatorTest.java

@@ -18,8 +18,7 @@ import scot.carricksoftware.grants.domains.people.Person;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
 import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
 
 @ExtendWith(MockitoExtension.class)
@@ -45,7 +44,6 @@ class MarriageCertificateCommandValidatorTest {
         stringArgumentCaptor2 = ArgumentCaptor.forClass(String.class);
         stringArgumentCaptor3 = ArgumentCaptor.forClass(String.class);
         objectArgumentCaptor = ArgumentCaptor.forClass(Object[].class);
-
     }
 
     @Test
@@ -67,6 +65,21 @@ class MarriageCertificateCommandValidatorTest {
         assertEquals("The groom cannot be null.", stringArgumentCaptor3.getValue());
     }
 
+    @Test
+    public void notNullPeopleTest() {
+        Person bride = GetRandomPerson();
+        Person groom = GetRandomPerson();
+        while (!bride.getFirstName().equals(groom.getFirstName())) {
+            groom = GetRandomPerson();
+        }
+
+        marriageCertificateCommand.setBride(bride);
+        marriageCertificateCommand.setGroom(groom);
+        commandValidator.validate(marriageCertificateCommand, bindingResultMock);
+
+        verify(bindingResultMock, times(0)).rejectValue(any(), any());
+    }
+
     private void runAndCapture() {
         commandValidator.validate(marriageCertificateCommand, bindingResultMock);
         verify(bindingResultMock, atLeast(1)).rejectValue(stringArgumentCaptor.capture(),