Przeglądaj źródła

CensusEntryFormControllerCapitalisationAndValidationTest

Andrew Grant 5 miesięcy temu
rodzic
commit
de8bea6a91

+ 0 - 11
src/test/java/scot/carricksoftware/grants/controllers/census/census/CensusFormControllerSaveOrUpdateTest.java

@@ -22,7 +22,6 @@ import scot.carricksoftware.grants.validators.census.census.CensusCommandValidat
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 
@@ -81,14 +80,4 @@ public class CensusFormControllerSaveOrUpdateTest {
         assertEquals("census/form", censusController.saveOrUpdate(censusCommand, bindingResultMock, modelMock));
     }
 
-    @Test
-    public void validationTakesPlaceTest() {
-        Long id = 4L;
-        censusCommand.setId(id);
-        when(censusServiceMock.saveCensusCommand(any(CensusCommand.class))).thenReturn(censusCommand);
-        censusController.saveOrUpdate(censusCommand, bindingResultMock, modelMock);
-        verify(censusCommandValidatorImplMock).validate(censusCommand, bindingResultMock);
-    }
-
-
 }

+ 95 - 0
src/test/java/scot/carricksoftware/grants/controllers/census/censusentry/CensusEntryFormControllerCapitalisationAndValidationTest.java

@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 21/03/2025, 00:30. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.controllers.census.censusentry;
+
+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.ui.Model;
+import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.capitalisation.census.censusentry.CapitaliseCensusEntry;
+import scot.carricksoftware.grants.commands.census.CensusEntryCommand;
+import scot.carricksoftware.grants.commands.census.CensusEntryCommandImpl;
+import scot.carricksoftware.grants.converters.census.CensusEntryConverterImpl;
+import scot.carricksoftware.grants.services.census.census.CensusService;
+import scot.carricksoftware.grants.services.census.censusentry.CensusEntryService;
+import scot.carricksoftware.grants.services.census.censusentry.UpdateRecordedYearOfBirth;
+import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.validators.census.censusentry.CensusEntryCommandValidatorImpl;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+@ExtendWith(MockitoExtension.class)
+public class CensusEntryFormControllerCapitalisationAndValidationTest {
+
+    @SuppressWarnings("unused")
+    private CensusEntryFormControllerImpl censusEntryController;
+
+    @Mock
+    private CensusEntryService censusEntryServiceMock;
+
+    @Mock
+    CensusEntryCommandValidatorImpl censusEntryCommandValidatorImplMock;
+
+    @Mock
+    private CensusEntryConverterImpl censusEntryConverterMock;
+
+    @Mock
+    private CapitaliseCensusEntry capitaliseCensusEntryMock;
+
+    @Mock
+    private PersonService personServiceMock;
+
+    @Mock
+    private CensusService censusServiceMock;
+
+    @Mock
+    Model modelMock;
+
+    @Mock
+    BindingResult bindingResultMock;
+
+    @Mock
+    private UpdateRecordedYearOfBirth updateRecordedYearOfBirthMock;
+
+    CensusEntryCommand censusEntryCommand;
+
+    @BeforeEach
+    public void setUp() {
+        censusEntryController = new CensusEntryFormControllerImpl(censusEntryServiceMock,
+                censusEntryCommandValidatorImplMock,
+                censusEntryConverterMock,
+                capitaliseCensusEntryMock,
+                personServiceMock,
+                censusServiceMock,
+                updateRecordedYearOfBirthMock);
+        censusEntryCommand = new CensusEntryCommandImpl();
+    }
+
+    @Test
+    public void validationTakesPlaceTest() {
+        Long id = 4L;
+        censusEntryCommand.setId(id);
+        when(censusEntryServiceMock.saveCensusEntryCommand(any(CensusEntryCommand.class))).thenReturn(censusEntryCommand);
+        censusEntryController.saveOrUpdate(censusEntryCommand, bindingResultMock, modelMock);
+        verify(censusEntryCommandValidatorImplMock).validate(censusEntryCommand, bindingResultMock);
+    }
+
+    @Test
+    public void capitalisationTakesPlaceTest() {
+        Long id = 4L;
+        censusEntryCommand.setId(id);
+        when(censusEntryServiceMock.saveCensusEntryCommand(any(CensusEntryCommand.class))).thenReturn(censusEntryCommand);
+        censusEntryController.saveOrUpdate(censusEntryCommand, bindingResultMock, modelMock);
+        verify(capitaliseCensusEntryMock).capitalise(censusEntryCommand);
+    }
+
+}

+ 0 - 11
src/test/java/scot/carricksoftware/grants/controllers/census/censusentry/CensusEntryFormControllerSaveOrUpdateTest.java

@@ -24,7 +24,6 @@ import scot.carricksoftware.grants.validators.census.censusentry.CensusEntryComm
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 
@@ -91,14 +90,4 @@ public class CensusEntryFormControllerSaveOrUpdateTest {
         assertEquals("censusEntry/form", censusEntryController.saveOrUpdate(censusEntryCommand, bindingResultMock, modelMock));
     }
 
-    @Test
-    public void validationTakesPlaceTest() {
-        Long id = 4L;
-        censusEntryCommand.setId(id);
-        when(censusEntryServiceMock.saveCensusEntryCommand(any(CensusEntryCommand.class))).thenReturn(censusEntryCommand);
-        censusEntryController.saveOrUpdate(censusEntryCommand, bindingResultMock, modelMock);
-        verify(censusEntryCommandValidatorImplMock).validate(censusEntryCommand, bindingResultMock);
-    }
-
-
 }