Browse Source

PersonImageCommand height and width validation tests

Andrew Grant 1 month ago
parent
commit
f5876f10cd

+ 1 - 1
src/main/java/scot/carricksoftware/grants/constants/ApplicationConstants.java

@@ -30,7 +30,7 @@ public class ApplicationConstants {
     public static final int LATEX_SUB_PARAGRAPH = 5;
 
     private static final int MINIMUM_SIZE = 100;
-    private static final int MAXIMUM_SIZE = 100;
+    private static final int MAXIMUM_SIZE = 10000;
 
     public static final int MINIMUM_IMAGE_WIDTH = MINIMUM_SIZE;
     public static final int MAXIMUM_IMAGE_WIDTH = MAXIMUM_SIZE;

+ 74 - 0
src/test/java/scot/carricksoftware/grants/validators/images/PersonImageCommandValidatorImageSizeTest.java

@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 30/03/2025, 14:31. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.validators.images;
+
+
+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.images.PersonImageCommand;
+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;
+
+
+@ExtendWith(MockitoExtension.class)
+class PersonImageCommandValidatorImageSizeTest {
+
+    private PersonImageCommandValidator validator;
+
+    @Mock
+    private BindingResult bindingResultMock;
+
+    @Mock
+    private ValidateTypes validateTypesMock;
+
+    @Mock
+    private PersonImageCommand personImageCommandMock;
+
+    @BeforeEach
+    void setUp() {
+        validator = new PersonImageCommandValidatorImpl(validateTypesMock);
+    }
+
+    @Test
+    void validateHeightIsRunTest() {
+        String height = GetRandomString();
+        when(personImageCommandMock.getHeight()).thenReturn(height);
+        validator.validate(personImageCommandMock, bindingResultMock);
+
+        verify(validateTypesMock).validateIntegerRange(height,
+                100, 10000,
+                "height",
+                "Height cannot be null.",
+                "Height must be an integer.",
+                "Height must be between 100 and 10000",
+                bindingResultMock);
+    }
+
+    @Test
+    void validateWidthIsRunTest() {
+        String width = GetRandomString();
+        when(personImageCommandMock.getWidth()).thenReturn(width);
+        validator.validate(personImageCommandMock, bindingResultMock);
+
+        verify(validateTypesMock).validateIntegerRange(width,
+                100, 10000,
+                "width",
+                "Width cannot be null.",
+                "Width must be an integer.",
+                "Width must be between 100 and 10000",
+                bindingResultMock);
+    }
+
+
+
+}