Forráskód Böngészése

PersonSectionContentsWriterOnyContentsTest

Andrew Grant 1 hete
szülő
commit
f6050122e1

+ 6 - 6
src/main/java/scot/carricksoftware/grantswriter/domains/text/PersonText.java

@@ -23,11 +23,11 @@ public class PersonText extends BaseEntity {
 
     @SuppressWarnings("JpaDataSourceORMInspection")
     @Column(name = "`level`")
-    private Long level;
+    private String level;
 
     @SuppressWarnings("JpaDataSourceORMInspection")
     @Column(name = "`order`")
-    private Long order;
+    private String order;
 
     @SuppressWarnings("JpaDataSourceORMInspection")
     @Column(name = "`heading`")
@@ -46,19 +46,19 @@ public class PersonText extends BaseEntity {
         this.person = person;
     }
 
-    public Long getLevel() {
+    public String getLevel() {
         return level;
     }
 
-    public void setLevel(Long level) {
+    public void setLevel(String level) {
         this.level = level;
     }
 
-    public Long getOrder() {
+    public String getOrder() {
         return order;
     }
 
-    public void setOrder(Long order) {
+    public void setOrder(String order) {
         this.order = order;
     }
 

+ 2 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/LatexDivisionHeader.java

@@ -8,4 +8,6 @@ package scot.carricksoftware.grantswriter.writer.latex;
 public interface LatexDivisionHeader {
 
     void write(Integer level, String title);
+    @SuppressWarnings("unused")
+    void write(String levelString, String title);
 }

+ 6 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/LatexDivisionHeaderImpl.java

@@ -32,4 +32,10 @@ public class LatexDivisionHeaderImpl implements LatexDivisionHeader {
         fileWriter.writeLine(latexDivision.header(level)
                 + title + LatexConstants.TERM_END);
     }
+
+    @Override
+    public void write(String levelString, String title) {
+        Integer level = Integer.valueOf(levelString);
+        write(level, title);
+    }
 }

+ 7 - 4
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSectionContentsWriterImpl.java

@@ -13,8 +13,8 @@ import scot.carricksoftware.grantswriter.domains.text.PersonText;
 import scot.carricksoftware.grantswriter.services.text.PersonTextService;
 import scot.carricksoftware.grantswriter.writer.FileWriter;
 import scot.carricksoftware.grantswriter.writer.latex.LatexDivisionHeader;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.PersonListSortByOrder;
 
-import java.util.Comparator;
 import java.util.List;
 
 @Component
@@ -28,10 +28,13 @@ public class PersonSectionContentsWriterImpl implements PersonSectionContentsWri
 
     private final LatexDivisionHeader latexDivisionHeader;
 
-    public PersonSectionContentsWriterImpl(PersonTextService personTextService, FileWriter fileWriter, LatexDivisionHeader latexDivisionHeader) {
+    private final PersonListSortByOrder personListSortByOrder;
+
+    public PersonSectionContentsWriterImpl(PersonTextService personTextService, FileWriter fileWriter, LatexDivisionHeader latexDivisionHeader, PersonListSortByOrder personListSortByOrder) {
         this.personTextService = personTextService;
         this.fileWriter = fileWriter;
         this.latexDivisionHeader = latexDivisionHeader;
+        this.personListSortByOrder = personListSortByOrder;
     }
 
 
@@ -40,10 +43,10 @@ public class PersonSectionContentsWriterImpl implements PersonSectionContentsWri
         logger.info("PersonSectionContentsWriterImpl.write()");
         List<PersonText> contents = personTextService.findAllByPerson(person);
         if (!contents.isEmpty()) {
-            contents.sort(Comparator.comparing(PersonText::getOrder));
+            personListSortByOrder.sort(contents);
             for (PersonText personText : contents) {
                 if (personText.getHeading() != null) {
-                    latexDivisionHeader.write(personText.getLevel().intValue(), personText.getHeading());
+                    latexDivisionHeader.write(Integer.parseInt(personText.getLevel()), personText.getHeading());
                 }
                 writeContent (personText);
             }

+ 14 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/PersonListSortByOrder.java

@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
+
+import scot.carricksoftware.grantswriter.domains.text.PersonText;
+
+import java.util.List;
+
+public interface PersonListSortByOrder {
+    void sort(List<PersonText> personTextList);
+}

+ 21 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/PersonListSortByOrderImpl.java

@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.text.PersonText;
+
+import java.util.Comparator;
+import java.util.List;
+
+@Component
+public class PersonListSortByOrderImpl implements PersonListSortByOrder {
+
+    @Override
+    public void sort(List<PersonText> personTextList) {
+        personTextList.sort(Comparator.comparing(PersonText::getOrder));
+    }
+}

+ 2 - 3
src/test/java/scot/carricksoftware/grantswriter/domains/text/PersonTextTest.java

@@ -12,7 +12,6 @@ import scot.carricksoftware.grantswriter.domains.people.Person;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
-import static scot.carricksoftware.grantswriter.GenerateRandomNumberValues.GetRandomLong;
 import static scot.carricksoftware.grantswriter.GenerateRandomPeopleValues.GetRandomPerson;
 
 class PersonTextTest {
@@ -43,7 +42,7 @@ class PersonTextTest {
 
     @Test
     void setLevelTest() {
-        Long level = GetRandomLong();
+        String level = GetRandomString();
         personText.setLevel(level);
         assertEquals(level, personText.getLevel());
     }
@@ -55,7 +54,7 @@ class PersonTextTest {
 
     @Test
     void setOrderTest() {
-        Long order = GetRandomLong();
+        String order = GetRandomString();
         personText.setOrder(order);
         assertEquals(order, personText.getOrder());
     }

+ 12 - 5
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSectionContentsWriterOnyContentsTest.java

@@ -15,17 +15,18 @@ import scot.carricksoftware.grantswriter.domains.text.PersonText;
 import scot.carricksoftware.grantswriter.services.text.PersonTextService;
 import scot.carricksoftware.grantswriter.writer.FileWriter;
 import scot.carricksoftware.grantswriter.writer.latex.LatexDivisionHeader;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.PersonListSortByOrder;
 
 import java.util.ArrayList;
 import java.util.List;
 
-
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
-import static scot.carricksoftware.grantswriter.GenerateRandomNumberValues.GetRandomLong;
+import static scot.carricksoftware.grantswriter.GenerateRandomNumberValues.GetRandomInteger;
+
 
 @ExtendWith(MockitoExtension.class)
 class PersonSectionContentsWriterOnyContentsTest {
@@ -41,6 +42,9 @@ class PersonSectionContentsWriterOnyContentsTest {
     @Mock
     private LatexDivisionHeader latexDivisionHeaderMock;
 
+    @Mock
+    private PersonListSortByOrder personListSortByOrderMock;
+
     private List<PersonText> contents;
 
     private PersonText personText;
@@ -49,7 +53,10 @@ class PersonSectionContentsWriterOnyContentsTest {
 
     @BeforeEach
     void setUp() {
-        writer = new PersonSectionContentsWriterImpl(personTextServiceMock, fileWriterMock, latexDivisionHeaderMock);
+        writer = new PersonSectionContentsWriterImpl(personTextServiceMock,
+                fileWriterMock,
+                latexDivisionHeaderMock,
+                personListSortByOrderMock);
         person = new Person();
         personText = new PersonText();
     }
@@ -77,10 +84,10 @@ class PersonSectionContentsWriterOnyContentsTest {
     void latexDivisionHeaderIsCalled() {
         contents = new ArrayList<>();
         personText.setHeading(GetRandomString());
-        personText.setLevel(GetRandomLong());
+        personText.setLevel(GetRandomInteger().toString());
         contents.add(personText);
         when(personTextServiceMock.findAllByPerson(person)).thenReturn(contents);
         writer.write(person);
-        verify(latexDivisionHeaderMock).write(any(), any());
+        verify(latexDivisionHeaderMock).write((Integer) any(), any());
     }
 }

+ 27 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/PersonListSortByOrderTest.java

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+
+class PersonListSortByOrderTest {
+
+    private PersonListSortByOrder sorter;
+
+    @BeforeEach
+    void setUp() {
+        sorter = new PersonListSortByOrderImpl();
+    }
+
+    @Test
+    void constructorTest() {
+        assertNotNull(sorter);
+    }
+}