|
|
@@ -0,0 +1,81 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 19 Feb 2025, Andrew Grant of Carrick Software .
|
|
|
+ * All rights reserved.
|
|
|
+ */
|
|
|
+
|
|
|
+package scot.carricksoftware.grants.controllers.places.countries;
|
|
|
+
|
|
|
+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.places.countries.CapitaliseCountry;
|
|
|
+import scot.carricksoftware.grants.commands.places.countries.CountryCommand;
|
|
|
+import scot.carricksoftware.grants.commands.places.countries.CountryCommandImpl;
|
|
|
+import scot.carricksoftware.grants.converters.places.countries.CountryCommandConverterImpl;
|
|
|
+import scot.carricksoftware.grants.converters.places.countries.CountryConverterImpl;
|
|
|
+import scot.carricksoftware.grants.services.places.countries.CountryService;
|
|
|
+import scot.carricksoftware.grants.validators.places.CountryCommandValidator;
|
|
|
+
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+
|
|
|
+@ExtendWith(MockitoExtension.class)
|
|
|
+public class CountryFormControllerValidationAndCapitalisationTest {
|
|
|
+
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ private CountryFormControllerImpl countryController;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private CountryService countryServiceMock;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private CountryCommandConverterImpl countryCommandConverterMock;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private CountryConverterImpl countryConverterMock;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private CapitaliseCountry capitaliseCountryMock;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ Model modelMock;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ BindingResult bindingResultMock;
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ CountryCommandValidator countryCommandValidatorMock;
|
|
|
+
|
|
|
+ private CountryCommand countryCommand;
|
|
|
+
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ public void setUp() {
|
|
|
+ countryController = new CountryFormControllerImpl(countryServiceMock,
|
|
|
+ countryCommandConverterMock,
|
|
|
+ countryConverterMock,
|
|
|
+ capitaliseCountryMock,
|
|
|
+ countryCommandValidatorMock);
|
|
|
+ countryCommand = new CountryCommandImpl();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void validationTakesPlaceTest() {
|
|
|
+ when(countryServiceMock.saveCountryCommand(countryCommand)).thenReturn(countryCommand);
|
|
|
+ countryController.saveOrUpdate(countryCommand, bindingResultMock, modelMock);
|
|
|
+ verify(countryCommandValidatorMock).validate(countryCommand, bindingResultMock);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void capitalisationTakesPlaceTest() {
|
|
|
+ when(countryServiceMock.saveCountryCommand(countryCommand)).thenReturn(countryCommand);
|
|
|
+ countryController.saveOrUpdate(countryCommand, bindingResultMock, modelMock);
|
|
|
+ verify(capitaliseCountryMock).capitalise(countryCommand);
|
|
|
+ }
|
|
|
+}
|