Parcourir la source

ValidateTypes interface introduced

Andrew Grant il y a 6 mois
Parent
commit
a84f4ad45f

+ 2 - 10
src/main/java/scot/carricksoftware/grants/validators/helpers/ValidateTypes.java

@@ -5,17 +5,9 @@
 
 package scot.carricksoftware.grants.validators.helpers;
 
-import org.springframework.stereotype.Component;
 import org.springframework.validation.BindingResult;
-import scot.carricksoftware.grants.constants.ApplicationConstants;
 import scot.carricksoftware.grants.domains.people.Person;
 
-@Component
-public class ValidateTypes {
-
-    public void validatePerson(Person person, String field, String message, BindingResult bindingResult) {
-        if (person == null ) {
-            bindingResult.rejectValue(field, ApplicationConstants.EMPTY_STRING, null, message);
-        }
-    }
+public interface ValidateTypes {
+    void validatePerson(Person person, String field, String message, BindingResult bindingResult);
 }

+ 22 - 0
src/main/java/scot/carricksoftware/grants/validators/helpers/ValidateTypesImpl.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.validators.helpers;
+
+import org.springframework.stereotype.Component;
+import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.constants.ApplicationConstants;
+import scot.carricksoftware.grants.domains.people.Person;
+
+@Component
+public class ValidateTypesImpl implements ValidateTypes {
+
+    @Override
+    public void validatePerson(Person person, String field, String message, BindingResult bindingResult) {
+        if (person == null ) {
+            bindingResult.rejectValue(field, ApplicationConstants.EMPTY_STRING, null, message);
+        }
+    }
+}

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

@@ -16,7 +16,7 @@ import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
 import scot.carricksoftware.grants.enums.certificates.CertificateType;
-import scot.carricksoftware.grants.validators.helpers.ValidateTypes;
+import scot.carricksoftware.grants.validators.helpers.ValidateTypesImpl;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
@@ -40,11 +40,11 @@ class BirthCertificateCommandPartOneValidatorDateTest {
     @Mock
     BindingResult bindingResultMock;
 
-    ValidateTypes validateTypes;
+    ValidateTypesImpl validateTypes;
 
     @BeforeEach
     void setUp() {
-        validateTypes = new ValidateTypes();
+        validateTypes = new ValidateTypesImpl();
         commandValidator = new BirthCertificateCommandPartOneValidator(validateTypes);
         stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
         stringArgumentCaptor2 = ArgumentCaptor.forClass(String.class);

+ 2 - 1
src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandPartOneValidatorPersonTest.java

@@ -17,6 +17,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
 import scot.carricksoftware.grants.enums.certificates.CertificateType;
 import scot.carricksoftware.grants.validators.helpers.ValidateTypes;
+import scot.carricksoftware.grants.validators.helpers.ValidateTypesImpl;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
@@ -45,7 +46,7 @@ class BirthCertificateCommandPartOneValidatorPersonTest {
 
     @BeforeEach
     void setUp() {
-        validateTypes = new ValidateTypes();
+        validateTypes = new ValidateTypesImpl();
         commandValidator = new BirthCertificateCommandPartOneValidator(validateTypes);
         stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
         stringArgumentCaptor2 = ArgumentCaptor.forClass(String.class);

+ 2 - 1
src/test/java/scot/carricksoftware/grants/validators/certificates/BirthCertificateCommandValidatorPartOneTest.java

@@ -17,6 +17,7 @@ import scot.carricksoftware.grants.commands.certificates.birthcertificates.Birth
 import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
 import scot.carricksoftware.grants.enums.certificates.CertificateType;
 import scot.carricksoftware.grants.validators.helpers.ValidateTypes;
+import scot.carricksoftware.grants.validators.helpers.ValidateTypesImpl;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
@@ -44,7 +45,7 @@ class BirthCertificateCommandValidatorPartOneTest {
 
     @BeforeEach
     void setUp() {
-        validateTypes = new ValidateTypes();
+        validateTypes = new ValidateTypesImpl();
         commandValidator = new BirthCertificateCommandPartOneValidator(validateTypes);
         stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
         stringArgumentCaptor2 = ArgumentCaptor.forClass(String.class);