|
@@ -11,18 +11,23 @@ import org.junit.jupiter.api.Test;
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
import org.mockito.Mock;
|
|
import org.mockito.Mock;
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
import scot.carricksoftware.grants.capitalisation.places.places.CapitalisePlace;
|
|
import scot.carricksoftware.grants.capitalisation.places.places.CapitalisePlace;
|
|
|
|
|
+import scot.carricksoftware.grants.commands.places.places.PlaceCommand;
|
|
|
|
|
+import scot.carricksoftware.grants.commands.places.places.PlaceCommandImpl;
|
|
|
import scot.carricksoftware.grants.converters.places.places.PlaceCommandConverterImpl;
|
|
import scot.carricksoftware.grants.converters.places.places.PlaceCommandConverterImpl;
|
|
|
import scot.carricksoftware.grants.converters.places.places.PlaceConverterImpl;
|
|
import scot.carricksoftware.grants.converters.places.places.PlaceConverterImpl;
|
|
|
import scot.carricksoftware.grants.services.places.places.PlaceService;
|
|
import scot.carricksoftware.grants.services.places.places.PlaceService;
|
|
|
import scot.carricksoftware.grants.services.places.regions.RegionService;
|
|
import scot.carricksoftware.grants.services.places.regions.RegionService;
|
|
|
import scot.carricksoftware.grants.validators.places.PlaceCommandValidator;
|
|
import scot.carricksoftware.grants.validators.places.PlaceCommandValidator;
|
|
|
|
|
|
|
|
-import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
-public class PlaceFormControllerCleansingTest {
|
|
|
|
|
|
|
+public class PlaceFormControllerValidationAndCapitalisationTest {
|
|
|
|
|
|
|
|
@SuppressWarnings({"unused", "FieldCanBeLocal"})
|
|
@SuppressWarnings({"unused", "FieldCanBeLocal"})
|
|
|
private PlaceFormControllerImpl placeController;
|
|
private PlaceFormControllerImpl placeController;
|
|
@@ -43,7 +48,15 @@ public class PlaceFormControllerCleansingTest {
|
|
|
private CapitalisePlace capitalisePlaceMock;
|
|
private CapitalisePlace capitalisePlaceMock;
|
|
|
|
|
|
|
|
@Mock
|
|
@Mock
|
|
|
- PlaceCommandValidator placeCommandValidatorMock;
|
|
|
|
|
|
|
+ private PlaceCommandValidator placeCommandValidatorMock;
|
|
|
|
|
+
|
|
|
|
|
+ @Mock
|
|
|
|
|
+ private BindingResult bindingResultMock;
|
|
|
|
|
+
|
|
|
|
|
+ @Mock
|
|
|
|
|
+ Model modelMock;
|
|
|
|
|
+
|
|
|
|
|
+ PlaceCommand placeCommand;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
|
public void setUp() {
|
|
public void setUp() {
|
|
@@ -53,12 +66,20 @@ public class PlaceFormControllerCleansingTest {
|
|
|
capitalisePlaceMock,
|
|
capitalisePlaceMock,
|
|
|
placeCommandValidatorMock,
|
|
placeCommandValidatorMock,
|
|
|
regionServiceMock);
|
|
regionServiceMock);
|
|
|
|
|
+ placeCommand = new PlaceCommandImpl();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
- void dummyTest(){
|
|
|
|
|
- assertTrue(true);
|
|
|
|
|
|
|
+ public void validationTakesPlaceTest() {
|
|
|
|
|
+ when(placeServiceMock.savePlaceCommand(placeCommand)).thenReturn(placeCommand);
|
|
|
|
|
+ placeController.saveOrUpdate(placeCommand, bindingResultMock, modelMock);
|
|
|
|
|
+ verify(placeCommandValidatorMock).validate(placeCommand, bindingResultMock);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void capitalisationTakesPlaceTest() {
|
|
|
|
|
+ when(placeServiceMock.savePlaceCommand(placeCommand)).thenReturn(placeCommand);
|
|
|
|
|
+ placeController.saveOrUpdate(placeCommand, bindingResultMock, modelMock);
|
|
|
|
|
+ verify(capitalisePlaceMock).capitalise(placeCommand);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|