Explorar o código

CensusEntryCondition

Andrew Grant hai 5 meses
pai
achega
12f83ecd32

+ 14 - 0
src/main/java/scot/carricksoftware/grants/domains/census/CensusEntry.java

@@ -9,6 +9,7 @@ import jakarta.persistence.*;
 import scot.carricksoftware.grants.BaseEntity;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryRelationship;
+import scot.carricksoftware.grants.enums.censusentry.CensusEntryCondition;
 
 @Entity
 public class CensusEntry extends BaseEntity {
@@ -28,6 +29,9 @@ public class CensusEntry extends BaseEntity {
     @Enumerated(EnumType.STRING)
     private CensusEntryRelationship relationship;
 
+    @Enumerated(EnumType.STRING)
+    private CensusEntryCondition condition;
+
     public Person getPerson() {
         return person;
     }
@@ -63,4 +67,14 @@ public class CensusEntry extends BaseEntity {
     public void setRelationship(CensusEntryRelationship relationship) {
         this.relationship = relationship;
     }
+
+    public CensusEntryCondition getCondition() {
+        return this.condition;
+    }
+
+    public void setCondition(CensusEntryCondition condition) {
+        this.condition = condition;
+    }
+
+
 }

+ 21 - 0
src/main/java/scot/carricksoftware/grants/enums/censusentry/CensusEntryCondition.java

@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grants.enums.censusentry;
+
+public enum CensusEntryCondition {
+    @SuppressWarnings("unused") WIDOW("Widow"),
+    @SuppressWarnings("unused") WIDOWER("Widower"),
+    @SuppressWarnings("unused") MARRIED("Married"),
+    @SuppressWarnings("unused") SINGLE("Single");
+
+    @SuppressWarnings("unused")
+    public final String label;
+
+    @SuppressWarnings("unused")
+    CensusEntryCondition(String label) {
+        this.label = label;
+    }
+}

+ 1 - 1
src/main/resources/application.properties

@@ -2,7 +2,7 @@ spring.application.name=grants
 server.port=8086
 server.servlet.context-path=/grants
 spring.mvc.format.date=dd-MM-yyyy
-spring.profiles.active=uat
+spring.profiles.active=dev
 logging.level.scot.carricksoftware=debug
 
 

+ 28 - 0
src/test/java/scot/carricksoftware/grants/GenerateCensusEntryConditionRandomValue.java

@@ -0,0 +1,28 @@
+/*
+ * Copyright (c)  04 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.enums.censusentry.CensusEntryCondition;
+
+import java.util.Random;
+
+@SuppressWarnings("unused")
+@Component
+public class GenerateCensusEntryConditionRandomValue {
+
+    public static CensusEntryCondition GetRandomCensusEntryCondition() {
+
+        CensusEntryCondition[] conditions = CensusEntryCondition.values();
+
+        Random random = new Random();
+        int randomInt = random.nextInt(0, conditions.length );
+        return conditions[randomInt];
+    }
+
+
+
+}

+ 15 - 1
src/test/java/scot/carricksoftware/grants/domains/census/CensusEntryEnumTest.java

@@ -9,10 +9,12 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
+import scot.carricksoftware.grants.enums.censusentry.CensusEntryCondition;
 import scot.carricksoftware.grants.enums.censusentry.CensusEntryRelationship;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static scot.carricksoftware.grants.GenerateCensusEntryConditionRandomValue.GetRandomCensusEntryCondition;
 import static scot.carricksoftware.grants.GenerateCensusEntryRelationshipRandomValue.GetRandomCensusEntryRelationship;
 
 @ExtendWith(MockitoExtension.class)
@@ -31,10 +33,22 @@ class CensusEntryEnumTest {
     }
 
     @Test
-    void setPersonTest() {
+    void setRelationshipTest() {
         CensusEntryRelationship relationship = GetRandomCensusEntryRelationship();
         entry.setRelationship(relationship);
         assertEquals(relationship, entry.getRelationship());
     }
 
+    @Test
+    void getConditionTest() {
+        assertNull(entry.getCondition());
+    }
+
+    @Test
+    void setConditionTest() {
+        CensusEntryCondition condition = GetRandomCensusEntryCondition();
+        entry.setCondition(condition);
+        assertEquals(condition, entry.getCondition());
+    }
+
 }