Kaynağa Gözat

CensusEntryRelationship

Andrew Grant 5 ay önce
ebeveyn
işleme
8b2268c13c

+ 6 - 0
docs/enums.txt

@@ -0,0 +1,6 @@
+1:Create Enum
+2: Domain
+3: Domain getter and setter
+4 : Random Value
+5: test getter and setter
+6: Enums Test

+ 11 - 3
src/main/java/scot/carricksoftware/grants/domains/census/CensusEntry.java

@@ -5,11 +5,10 @@
 
 package scot.carricksoftware.grants.domains.census;
 
-import jakarta.persistence.Entity;
-import jakarta.persistence.JoinColumn;
-import jakarta.persistence.ManyToOne;
+import jakarta.persistence.*;
 import scot.carricksoftware.grants.BaseEntity;
 import scot.carricksoftware.grants.domains.people.Person;
+import scot.carricksoftware.grants.enums.censusentry.CensusEntryRelationship;
 
 @Entity
 public class CensusEntry extends BaseEntity {
@@ -26,6 +25,9 @@ public class CensusEntry extends BaseEntity {
     @JoinColumn(name = "person_id")
     private Person person;
 
+    @Enumerated(EnumType.STRING)
+    private CensusEntryRelationship relationship;
+
     public Person getPerson() {
         return person;
     }
@@ -54,5 +56,11 @@ public class CensusEntry extends BaseEntity {
         return census.toString();
     }
 
+    public CensusEntryRelationship getRelationship() {
+        return relationship;
+    }
 
+    public void setRelationship(CensusEntryRelationship relationship) {
+        this.relationship = relationship;
+    }
 }

+ 28 - 0
src/test/java/scot/carricksoftware/grants/GenerateCensusEntryRelationshipRandomValue.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.CensusEntryRelationship;
+
+import java.util.Random;
+
+@SuppressWarnings("unused")
+@Component
+public class GenerateCensusEntryRelationshipRandomValue {
+
+    public static CensusEntryRelationship GetRandomCensusEntryRelationship() {
+
+        CensusEntryRelationship[] relationships = CensusEntryRelationship.values();
+
+        Random random = new Random();
+        int randomInt = random.nextInt(0, relationships.length );
+        return relationships[randomInt];
+    }
+
+
+
+}

+ 40 - 0
src/test/java/scot/carricksoftware/grants/domains/census/CensusEntryEnumTest.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 20/03/2025, 11:01. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.domains.census;
+
+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.CensusEntryRelationship;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static scot.carricksoftware.grants.GenerateCensusEntryRelationshipRandomValue.GetRandomCensusEntryRelationship;
+
+@ExtendWith(MockitoExtension.class)
+class CensusEntryEnumTest {
+
+    private CensusEntry entry;
+
+    @BeforeEach
+    void setUp() {
+        entry = new CensusEntry();
+    }
+
+    @Test
+    void getRelationShipTest() {
+        assertNull(entry.getRelationship());
+    }
+
+    @Test
+    void setPersonTest() {
+        CensusEntryRelationship relationship = GetRandomCensusEntryRelationship();
+        entry.setRelationship(relationship);
+        assertEquals(relationship, entry.getRelationship());
+    }
+
+}

+ 0 - 1
src/test/java/scot/carricksoftware/grants/domains/census/CensusEntryTest.java

@@ -65,7 +65,6 @@ class CensusEntryTest {
         assertEquals(string, entry.toString());
     }
 
-
     @Test
     void getPersonTest() {
         assertNull(entry.getPerson());