Эх сурвалжийг харах

Census date changed to CensusDate type in command

Andrew Grant 7 сар өмнө
parent
commit
0ea17532f0

+ 2 - 5
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCensus.java

@@ -15,6 +15,7 @@ import scot.carricksoftware.grants.commands.census.CensusEntryCommand;
 import scot.carricksoftware.grants.commands.census.CensusEntryCommandImpl;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
+import scot.carricksoftware.grants.enums.census.CensusDate;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryCondition;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryGaelic;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryRelationship;
@@ -24,10 +25,6 @@ import scot.carricksoftware.grants.services.census.CensusService;
 import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
 
-
-
-import java.time.LocalDate;
-
 @Component
 @Profile("dev")
 public class DataLoadCensus {
@@ -61,7 +58,7 @@ public class DataLoadCensus {
         logger.debug("DataLoadCensus::loadCensus");
         CensusCommand censusCommand = new CensusCommandImpl();
         Place place = placeService.findById(1L);
-        censusCommand.setDate(LocalDate.now());
+        censusCommand.setDate(CensusDate.CENSUS_1881);
         censusCommand.setPlace(place);
         censusCommand.setBoundaryType(CensusBoundaryType.ISLAND);
         censusService.saveCensusCommand(censusCommand);

+ 3 - 3
src/main/java/scot/carricksoftware/grants/commands/census/CensusCommand.java

@@ -8,8 +8,8 @@ package scot.carricksoftware.grants.commands.census;
 import scot.carricksoftware.grants.domains.census.CensusEntry;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
+import scot.carricksoftware.grants.enums.census.CensusDate;
 
-import java.time.LocalDate;
 import java.util.List;
 
 public interface CensusCommand {
@@ -17,9 +17,9 @@ public interface CensusCommand {
 
     void setId(Long id);
 
-    LocalDate getDate();
+    CensusDate getDate();
 
-    void setDate(LocalDate date);
+    void setDate(CensusDate date);
 
     List<CensusEntry> getCensusEntries();
 

+ 4 - 4
src/main/java/scot/carricksoftware/grants/commands/census/CensusCommandImpl.java

@@ -8,8 +8,8 @@ package scot.carricksoftware.grants.commands.census;
 import scot.carricksoftware.grants.domains.census.CensusEntry;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
+import scot.carricksoftware.grants.enums.census.CensusDate;
 
-import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -17,7 +17,7 @@ public class CensusCommandImpl implements CensusCommand {
 
     private Long id;
 
-    private LocalDate date;
+    private CensusDate date;
 
     private List<CensusEntry> censusEntries = new ArrayList<>();
 
@@ -36,12 +36,12 @@ public class CensusCommandImpl implements CensusCommand {
     }
 
     @Override
-    public LocalDate getDate() {
+    public CensusDate getDate() {
         return date;
     }
 
     @Override
-    public void setDate(LocalDate date) {
+    public void setDate(CensusDate date) {
         this.date = date;
     }
 

+ 0 - 6
src/main/java/scot/carricksoftware/grants/validators/census/CensusCommandValidator.java

@@ -11,8 +11,6 @@ import scot.carricksoftware.grants.commands.census.CensusCommand;
 import scot.carricksoftware.grants.constants.ApplicationConstants;
 import scot.carricksoftware.grants.constants.ValidationConstants;
 
-import java.time.LocalDate;
-
 @Component
 public class CensusCommandValidator {
 
@@ -25,10 +23,6 @@ public class CensusCommandValidator {
             bindingResult.rejectValue("date", ApplicationConstants.EMPTY_STRING,
                     null,
                     ValidationConstants.DATE_IS_NULL);
-        } else if (censusCommand.getDate().isAfter(LocalDate.now())) {
-            bindingResult.rejectValue("date", ApplicationConstants.EMPTY_STRING,
-                    null,
-                    ValidationConstants.DATE_IN_FUTURE);
         }
     }
 }

+ 4 - 4
src/test/java/scot/carricksoftware/grants/GenerateCensusEntryRandomEnums.java

@@ -22,7 +22,7 @@ public class GenerateCensusEntryRandomEnums {
         CensusEntryCondition[] conditions = CensusEntryCondition.values();
 
         Random random = new Random();
-        int randomInt = random.nextInt(0, conditions.length);
+        int randomInt = random.nextInt(0, conditions.length );
         return conditions[randomInt];
     }
 
@@ -30,7 +30,7 @@ public class GenerateCensusEntryRandomEnums {
         CensusEntryGaelic[] gaelicArray = CensusEntryGaelic.values();
 
         Random random = new Random();
-        int randomInt = random.nextInt(0, gaelicArray.length);
+        int randomInt = random.nextInt(0, gaelicArray.length );
         return gaelicArray[randomInt];
     }
 
@@ -38,7 +38,7 @@ public class GenerateCensusEntryRandomEnums {
         CensusEntryRelationship[] relationships = CensusEntryRelationship.values();
 
         Random random = new Random();
-        int randomInt = random.nextInt(0, relationships.length);
+        int randomInt = random.nextInt(0, relationships.length );
         return relationships[randomInt];
     }
 
@@ -46,7 +46,7 @@ public class GenerateCensusEntryRandomEnums {
         CensusEntryWorker[] workers = CensusEntryWorker.values();
 
         Random random = new Random();
-        int randomInt = random.nextInt(0, workers.length);
+        int randomInt = random.nextInt(0, workers.length );
         return workers[randomInt];
     }
 }

+ 3 - 5
src/test/java/scot/carricksoftware/grants/GenerateCensusRandomEnums.java

@@ -3,9 +3,7 @@
  *
  */
 
-package scot.carricksoftware.grants;
-
-import org.springframework.stereotype.Component;
+package scot.carricksoftware.grants;import org.springframework.stereotype.Component;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
 import scot.carricksoftware.grants.enums.census.CensusDate;
 
@@ -20,7 +18,7 @@ public class GenerateCensusRandomEnums {
         CensusBoundaryType[] boundaryTypes = CensusBoundaryType.values();
 
         Random random = new Random();
-        int randomInt = random.nextInt(0, boundaryTypes.length);
+        int randomInt = random.nextInt(0, boundaryTypes.length );
         return boundaryTypes[randomInt];
     }
 
@@ -29,7 +27,7 @@ public class GenerateCensusRandomEnums {
         CensusDate[] dates = CensusDate.values();
 
         Random random = new Random();
-        int randomInt = random.nextInt(0, dates.length);
+        int randomInt = random.nextInt(0, dates.length );
         return dates[randomInt];
     }
 

+ 2 - 3
src/test/java/scot/carricksoftware/grants/GenerateRandomCensusValues.java

@@ -13,8 +13,7 @@ import scot.carricksoftware.grants.commands.census.CensusEntryCommandImpl;
 import scot.carricksoftware.grants.domains.census.Census;
 import scot.carricksoftware.grants.domains.census.CensusEntry;
 
-import java.time.LocalDate;
-
+import static scot.carricksoftware.grants.GenerateCensusRandomEnums.GetRandomCensusDate;
 import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
 import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
 
@@ -32,7 +31,7 @@ public class GenerateRandomCensusValues {
     public static CensusCommand GetRandomCensusCommand() {
         CensusCommand censusCommand = new CensusCommandImpl();
         censusCommand.setId(GetRandomLong());
-        censusCommand.setDate(LocalDate.now());
+        censusCommand.setDate(GetRandomCensusDate());
         return censusCommand;
     }
 

+ 3 - 3
src/test/java/scot/carricksoftware/grants/GenerateRandomTextValues.java

@@ -21,9 +21,9 @@ import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPla
 public class GenerateRandomTextValues {
 
     public static DocumentText GetRandomDocumentText() {
-        DocumentText documentText = new DocumentText();
-        documentText.setId(GetRandomLong());
-        return documentText;
+       DocumentText documentText = new DocumentText();
+       documentText.setId(GetRandomLong());
+       return documentText;
     }
 
     @SuppressWarnings("unused")

+ 2 - 3
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCensusTest.java

@@ -12,6 +12,7 @@ import scot.carricksoftware.grants.domains.census.Census;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
+import scot.carricksoftware.grants.enums.census.CensusDate;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryCondition;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryGaelic;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryRelationship;
@@ -22,8 +23,6 @@ import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
 
 
-import java.time.LocalDate;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -66,7 +65,7 @@ public class DataLoadCensusTest {
         dataLoadCensus.load();
         verify(censusServiceMock).saveCensusCommand(captor.capture());
 
-        assertEquals(captor.getValue().getDate(), LocalDate.now());
+        assertEquals( CensusDate.CENSUS_1881, captor.getValue().getDate());
         assertEquals(captor.getValue().getPlace(), place);
         assertEquals(CensusBoundaryType.ISLAND, captor.getValue().getBoundaryType());
     }

+ 12 - 0
src/test/java/scot/carricksoftware/grants/commands/census/CensusCommandEnumTest.java

@@ -9,10 +9,12 @@ package scot.carricksoftware.grants.commands.census;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
+import scot.carricksoftware.grants.enums.census.CensusDate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static scot.carricksoftware.grants.GenerateCensusRandomEnums.GetRandomCensusBoundaryType;
+import static scot.carricksoftware.grants.GenerateCensusRandomEnums.GetRandomCensusDate;
 
 class CensusCommandEnumTest {
 
@@ -35,5 +37,15 @@ class CensusCommandEnumTest {
         assertEquals(boundaryType, command.getBoundaryType());
     }
 
+    @Test
+    void getDateTest() {
+        assertNull(command.getDate());
+    }
 
+    @Test
+    void setDateTest() {
+        CensusDate date = GetRandomCensusDate();
+        command.setDate(date);
+        assertEquals(date, command.getDate());
+    }
 }

+ 0 - 23
src/test/java/scot/carricksoftware/grants/commands/census/CensusCommandTest.java

@@ -10,13 +10,11 @@ import org.junit.jupiter.api.Test;
 import scot.carricksoftware.grants.domains.census.CensusEntry;
 import scot.carricksoftware.grants.domains.places.Place;
 
-import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 
 import static org.junit.jupiter.api.Assertions.*;
 import static scot.carricksoftware.grants.GenerateRandomCensusValues.GetRandomCensusEntry;
-import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
 
 class CensusCommandTest {
@@ -28,29 +26,8 @@ class CensusCommandTest {
         command = new CensusCommandImpl();
     }
 
-    @Test
-    void getIdTest() {
-        assertNull(command.getId());
-    }
 
-    @Test
-    void setIdTest() {
-        Long id = GetRandomLong();
-        command.setId(id);
-        assertEquals(id, command.getId());
-    }
 
-    @Test
-    void getDateTest() {
-        assertNull(command.getDate());
-    }
-
-    @Test
-    void setDateTest() {
-        LocalDate date = LocalDate.now();
-        command.setDate(date);
-        assertEquals(date, command.getDate());
-    }
 
     @Test
     void getCensusEntriesTest() {

+ 3 - 2
src/test/java/scot/carricksoftware/grants/converters/census/CensusCommandConverterTest.java

@@ -13,13 +13,14 @@ import scot.carricksoftware.grants.domains.census.Census;
 import scot.carricksoftware.grants.domains.census.CensusEntry;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.enums.census.CensusBoundaryType;
+import scot.carricksoftware.grants.enums.census.CensusDate;
 
-import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static scot.carricksoftware.grants.GenerateCensusRandomEnums.GetRandomCensusBoundaryType;
+import static scot.carricksoftware.grants.GenerateCensusRandomEnums.GetRandomCensusDate;
 import static scot.carricksoftware.grants.GenerateRandomCensusValues.GetRandomCensusEntry;
 import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
@@ -35,7 +36,7 @@ class CensusCommandConverterTest {
     @Test
     void convertTest() {
         Long id = GetRandomLong();
-        LocalDate date = LocalDate.now();
+        CensusDate date = GetRandomCensusDate();
         CensusCommand source = new CensusCommandImpl();
         List<CensusEntry> censusEntries = new ArrayList<>();
         censusEntries.add(GetRandomCensusEntry());

+ 0 - 18
src/test/java/scot/carricksoftware/grants/validators/census/CensusCommandValidatorTest.java

@@ -16,8 +16,6 @@ import org.springframework.validation.BindingResult;
 import scot.carricksoftware.grants.commands.census.CensusCommand;
 import scot.carricksoftware.grants.commands.census.CensusCommandImpl;
 
-import java.time.LocalDate;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
 import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
@@ -65,21 +63,5 @@ class CensusCommandValidatorTest {
 
     }
 
-    @Test
-    public void DateInTheFutureTest() {
-        censusCommand.setId(GetRandomLong());
-        censusCommand.setDate(LocalDate.now().plusDays(1));
-
-        censusCommandValidator.validate(censusCommand, bindingResultMock);
-
-        verify(bindingResultMock).rejectValue(stringArgumentCaptor.capture(),
-                stringArgumentCaptor2.capture(),
-                objectArgumentCaptor.capture(),
-                stringArgumentCaptor3.capture());
-
-        assertEquals("date", stringArgumentCaptor.getValue());
-        assertEquals("Date should not be in the future.", stringArgumentCaptor3.getValue());
-
-    }
 
 }