浏览代码

PersonSectionHeader

Andrew Grant 3 月之前
父节点
当前提交
2e29633656

+ 1 - 0
src/main/java/scot/carricksoftware/grantswriter/constants/LatexConstants.java

@@ -20,6 +20,7 @@ public class LatexConstants {
     public static final String DOCUMENT_END = "\\end{document}";
 
     public static final String PART_TERM = "\\part{";
+    public static final String SECTION_TERM = "\\section{";
     public static final String TERM_END = "}";
 
 }

+ 1 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/LatexSectionHeader.java

@@ -8,5 +8,5 @@ package scot.carricksoftware.grantswriter.writer.latex;
 public interface LatexSectionHeader {
 
     @SuppressWarnings({"EmptyMethod", "unused"})
-    void write(@SuppressWarnings("unused") String title);
+    void write(String title);
 }

+ 17 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/LatexSectionHeaderImpl.java

@@ -5,10 +5,26 @@
 
 package scot.carricksoftware.grantswriter.writer.latex;
 
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.constants.LatexConstants;
+import scot.carricksoftware.grantswriter.writer.FileWriter;
+
+@Component
 public class LatexSectionHeaderImpl implements LatexSectionHeader {
 
+
+    private final FileWriter fileWriter;
+
+    public LatexSectionHeaderImpl(FileWriter fileWriter) {
+        this.fileWriter = fileWriter;
+    }
+
+
     @Override
     public void write(String title) {
-
+        String sb = LatexConstants.SECTION_TERM +
+                title +
+                LatexConstants.TERM_END;
+        fileWriter.writeLine(sb);
     }
 }

+ 12 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/PersonSectionHeader.java

@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people;
+
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
+public interface PersonSectionHeader {
+    void write(Person person);
+}

+ 25 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/PersonSectionHeaderImpl.java

@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people;
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.writer.latex.LatexSectionHeader;
+
+@Component
+public class PersonSectionHeaderImpl implements PersonSectionHeader {
+
+    private final LatexSectionHeader latexSectionHeader;
+
+    public PersonSectionHeaderImpl(LatexSectionHeader latexSectionHeader) {
+        this.latexSectionHeader = latexSectionHeader;
+    }
+
+    @Override
+    public void write(Person person) {
+        latexSectionHeader.write(person.toString());
+    }
+}

+ 8 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/sections/PersonSectionImpl.java

@@ -7,12 +7,19 @@ package scot.carricksoftware.grantswriter.writer.latex.sections;
 
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grantswriter.domains.people.Person;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.PersonSectionHeader;
 
 @Component
 public class PersonSectionImpl implements PersonSection {
 
+    private final PersonSectionHeader personSectionHeader;
+
+    public PersonSectionImpl(PersonSectionHeader personSectionHeader) {
+        this.personSectionHeader = personSectionHeader;
+    }
+
     @Override
     public void write(Person person) {
-
+        personSectionHeader.write(person);
     }
 }

+ 6 - 1
src/test/java/scot/carricksoftware/grantswriter/writer/latex/LatexSectionHeaderTest.java

@@ -7,6 +7,8 @@ package scot.carricksoftware.grantswriter.writer.latex;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import scot.carricksoftware.grantswriter.writer.FileWriter;
 
 import static org.junit.jupiter.api.Assertions.*;
 
@@ -14,9 +16,12 @@ class LatexSectionHeaderTest {
 
    private LatexSectionHeader header;
 
+   @Mock
+   private FileWriter fileWriterMock;
+
     @BeforeEach
     void setUp() {
-        header = new LatexSectionHeaderImpl();
+        header = new LatexSectionHeaderImpl(fileWriterMock);
     }
 
     @Test

+ 34 - 0
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/PersonSectionHeaderTest.java

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import scot.carricksoftware.grantswriter.writer.latex.LatexSectionHeader;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@ExtendWith(MockitoExtension.class)
+class PersonSectionHeaderTest {
+
+    PersonSectionHeader personSectionHeader;
+
+    @Mock
+    LatexSectionHeader latexSectionHeaderMock;
+
+    @BeforeEach
+    void setUp() {
+        personSectionHeader = new PersonSectionHeaderImpl(latexSectionHeaderMock);
+    }
+
+    @Test
+    void constructorTest() {
+        assertNotNull(personSectionHeader);
+    }
+}

+ 6 - 1
src/test/java/scot/carricksoftware/grantswriter/writer/latex/sections/PersonSectionTest.java

@@ -7,6 +7,8 @@ package scot.carricksoftware.grantswriter.writer.latex.sections;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.PersonSectionHeader;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
@@ -15,9 +17,12 @@ class PersonSectionTest {
 
     private PersonSection personSection;
 
+    @Mock
+    PersonSectionHeader personSectionHeaderMock;
+
     @BeforeEach
     void setUp() {
-        personSection = new PersonSectionImpl();
+        personSection = new PersonSectionImpl(personSectionHeaderMock);
     }
 
     @Test