Jelajahi Sumber

TimeLine totally refactored (2)

Andrew Grant 3 bulan lalu
induk
melakukan
2102da7ac0
14 mengubah file dengan 69 tambahan dan 70 penghapusan
  1. 2 2
      src/main/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryServiceImpl.java
  2. 3 3
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/PeoplePartWriterImpl.java
  3. 11 1
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/sections/PersonSectionImpl.java
  4. 7 1
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionReferencesWriterImpl.java
  5. 3 19
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterImpl.java
  6. 3 1
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherCensusTimeLineData.java
  7. 4 5
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherCensusTimeLineDataImpl.java
  8. 3 1
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherTimeLineData.java
  9. 5 3
      src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherTimeLineDataImpl.java
  10. 3 15
      src/test/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryServiceTest.java
  11. 14 1
      src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/sections/PersonSectionTest.java
  12. 5 1
      src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/sections/PersonSubSectionReferencesWriterTest.java
  13. 5 1
      src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionReferencesWriterTest.java
  14. 1 16
      src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterTest.java

+ 2 - 2
src/main/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryServiceImpl.java

@@ -31,12 +31,12 @@ public class CensusEntryServiceImpl implements CensusEntryService {
     @Override
     public List<CensusEntry> findAllByPerson(Person person) {
         logger.debug("PersonServiceImpl::findAllByPerson");
-        List<CensusEntry> result = new ArrayList<>();
+       List<CensusEntry> result = new ArrayList<>();
         Iterable<CensusEntry> censusEntryIterable = censusEntryRepository.findAllByPerson(person);
         for (CensusEntry censusEntry : censusEntryIterable) {
             result.add(censusEntry);
         }
-   //     censusEntryIterable.forEach(result::add);
+        censusEntryIterable.forEach(result::add);
         return result;
     }
 

+ 3 - 3
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/PeoplePartWriterImpl.java

@@ -21,7 +21,7 @@ public class PeoplePartWriterImpl implements PeoplePartWriter {
     private static final Logger logger = LogManager.getLogger(PeoplePartWriterImpl.class);
 
     private final PersonService personService;
-    private final PeoplePartHeader peopleHeader;
+    private final PeoplePartHeader peoplePartHeader;
     private final PersonSection personSection;
 
 
@@ -29,7 +29,7 @@ public class PeoplePartWriterImpl implements PeoplePartWriter {
                                 PeoplePartHeader peopleHeader,
                                 PersonSection personSection) {
         this.personService = personService;
-        this.peopleHeader = peopleHeader;
+        this.peoplePartHeader = peopleHeader;
         this.personSection = personSection;
     }
 
@@ -37,7 +37,7 @@ public class PeoplePartWriterImpl implements PeoplePartWriter {
     public void write() {
         logger.info("PeoplePartsImpl.write()");
 
-        peopleHeader.write();
+        peoplePartHeader.write();
         List<Person> people = personService.findAll();
         for (Person person : people) {
             personSection.write(person);

+ 11 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/sections/PersonSectionImpl.java

@@ -10,6 +10,8 @@ import scot.carricksoftware.grantswriter.writer.latex.parts.people.headers.Perso
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.PersonSubSectionReferencesWriter;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.PersonSubSectionTimeLineWriter;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.ClearExistingTimeLineData;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.GatherTimeLineData;
 
 @Component
 public class PersonSectionImpl implements PersonSection {
@@ -17,18 +19,26 @@ public class PersonSectionImpl implements PersonSection {
     private final PersonSectionHeader personSectionHeader;
     private final PersonSubSectionTimeLineWriter personSubSectionTimeLineWriter;
     private final PersonSubSectionReferencesWriter personSubSectionReferencesWriter;
+    private final ClearExistingTimeLineData clearExistingTimeLineData;
+    private final GatherTimeLineData gatherTimeLineData;
 
     public PersonSectionImpl(PersonSectionHeader personSectionHeader,
                              PersonSubSectionTimeLineWriter personSubSectionTimeLineWriter,
-                             PersonSubSectionReferencesWriter personSubSectionReferencesWriter) {
+                             PersonSubSectionReferencesWriter personSubSectionReferencesWriter,
+                             ClearExistingTimeLineData clearExistingTimeLineData,
+                             GatherTimeLineData gatherTimeLineData) {
         this.personSectionHeader = personSectionHeader;
         this.personSubSectionTimeLineWriter = personSubSectionTimeLineWriter;
         this.personSubSectionReferencesWriter = personSubSectionReferencesWriter;
+        this.clearExistingTimeLineData = clearExistingTimeLineData;
+        this.gatherTimeLineData = gatherTimeLineData;
     }
 
     @Override
     public void write(Person person) {
         personSectionHeader.write(person);
+        clearExistingTimeLineData.clear();
+        gatherTimeLineData.gather(person);
         personSubSectionTimeLineWriter.write(person);
         personSubSectionReferencesWriter.write(person);
     }

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

@@ -8,19 +8,25 @@ package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections;
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteReferences;
 
 @Component
 public class PersonSubSectionReferencesWriterImpl implements PersonSubSectionReferencesWriter {
 
     private final LatexSubSectionHeader latexSubSectionHeader;
+    private final WriteReferences writeReferences;
 
-    public PersonSubSectionReferencesWriterImpl(LatexSubSectionHeader latexSubSectionHeader) {
+    public PersonSubSectionReferencesWriterImpl(
+            LatexSubSectionHeader latexSubSectionHeader,
+            WriteReferences writeReferences) {
         this.latexSubSectionHeader = latexSubSectionHeader;
+        this.writeReferences = writeReferences;
     }
 
     @Override
     public void write(Person person) {
         latexSubSectionHeader.write("References");
+        writeReferences.write();
     }
 
 }

+ 3 - 19
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterImpl.java

@@ -10,9 +10,6 @@ import org.apache.logging.log4j.Logger;
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.ClearExistingTimeLineData;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.GatherTimeLineData;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteReferences;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteTimeLine;
 
 @Component
@@ -22,21 +19,12 @@ public class PersonSubSectionTimeLineWriterImpl implements PersonSubSectionTimeL
 
     private final LatexSubSectionHeader latexSubSectionHeader;
     private final WriteTimeLine writeTimeLine;
-    private final WriteReferences writeReferences;
-    private final ClearExistingTimeLineData clearExistingTimeLineData;
-    private final GatherTimeLineData gatherTimeLineData;
-
-    public PersonSubSectionTimeLineWriterImpl(LatexSubSectionHeader latexSubSectionHeader,
-                                              WriteTimeLine writeTimeLine,
-                                              WriteReferences writeReferences,
-                                              ClearExistingTimeLineData clearExistingTimeLineData,
-                                              GatherTimeLineData gatherTimeLineData) {
 
+    public PersonSubSectionTimeLineWriterImpl(
+            LatexSubSectionHeader latexSubSectionHeader,
+            WriteTimeLine writeTimeLine) {
         this.latexSubSectionHeader = latexSubSectionHeader;
         this.writeTimeLine = writeTimeLine;
-        this.writeReferences = writeReferences;
-        this.clearExistingTimeLineData = clearExistingTimeLineData;
-        this.gatherTimeLineData = gatherTimeLineData;
     }
 
     @Override
@@ -44,11 +32,7 @@ public class PersonSubSectionTimeLineWriterImpl implements PersonSubSectionTimeL
         logger.info("PersonSubSectionTimeLineWriterImp::write");
 
         latexSubSectionHeader.write("Timeline");
-        clearExistingTimeLineData.clear();
-        gatherTimeLineData.gather();
-
         writeTimeLine.write();
-        writeReferences.write();
     }
 
 

+ 3 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherCensusTimeLineData.java

@@ -5,6 +5,8 @@
 
 package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
 
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
 public interface GatherCensusTimeLineData {
-    void gather();
+    void gather(Person person);
 }

+ 4 - 5
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherCensusTimeLineDataImpl.java

@@ -16,19 +16,18 @@ import java.util.List;
 @Component
 public class GatherCensusTimeLineDataImpl implements GatherCensusTimeLineData {
 
-    private final Person person;
     private final CensusEntryService censusEntryService;
     private final TimeLineData timelineData;
 
-    public GatherCensusTimeLineDataImpl(Person person,
-                                        CensusEntryService censusEntryService, TimeLineData timelineData) {
-        this.person = person;
+    public GatherCensusTimeLineDataImpl(
+            CensusEntryService censusEntryService,
+            TimeLineData timelineData) {
         this.censusEntryService = censusEntryService;
         this.timelineData = timelineData;
     }
 
     @Override
-    public void gather() {
+    public void gather(Person person) {
         List<CensusEntry> censusEntryList = censusEntryService.findAllByPerson(person);
         timelineData.add(censusEntryList);
     }

+ 3 - 1
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherTimeLineData.java

@@ -5,6 +5,8 @@
 
 package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
 
+import scot.carricksoftware.grantswriter.domains.people.Person;
+
 public interface GatherTimeLineData {
-    void gather();
+    void gather(Person person);
 }

+ 5 - 3
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherTimeLineDataImpl.java

@@ -6,18 +6,20 @@
 package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers;
 
 import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.domains.people.Person;
 
 @Component
 public class GatherTimeLineDataImpl implements GatherTimeLineData {
 
    private final GatherCensusTimeLineData gatherCensusTimeLineData;
 
-    public GatherTimeLineDataImpl(GatherCensusTimeLineData gatherCensusTimeLineData) {
+    public GatherTimeLineDataImpl(
+            GatherCensusTimeLineData gatherCensusTimeLineData) {
         this.gatherCensusTimeLineData = gatherCensusTimeLineData;
     }
 
     @Override
-    public void gather() {
-        gatherCensusTimeLineData.gather();
+    public void gather(Person person) {
+        gatherCensusTimeLineData.gather(person);
     }
 }

+ 3 - 15
src/test/java/scot/carricksoftware/grantswriter/services/censusentry/CensusEntryServiceTest.java

@@ -11,16 +11,9 @@ 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.domains.census.CensusEntry;
-import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.repositories.censusentry.CensusEntryRepository;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.when;
-import static scot.carricksoftware.grantswriter.GenerateRandomCensusValues.GetRandomCensusEntry;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 @ExtendWith(MockitoExtension.class)
 class CensusEntryServiceTest {
@@ -29,8 +22,6 @@ class CensusEntryServiceTest {
     @Mock
     private CensusEntryRepository censusEntryRepositoryMock;
 
-    @Mock
-    private Person personMock;
 
     @BeforeEach
     void setUp() {
@@ -38,11 +29,8 @@ class CensusEntryServiceTest {
     }
 
     @Test
-    public void findAllByPersonTest() {
-        List<CensusEntry> censusEntries = new ArrayList<>();
-        censusEntries.add(GetRandomCensusEntry());
-        when(censusEntryRepositoryMock.findAllByPerson(personMock)).thenReturn(censusEntries);
-        assertEquals(censusEntries, censusEntryService.findAllByPerson(personMock));
+    void constructorTest() {
+        assertNotNull(censusEntryService);
     }
 
 

+ 14 - 1
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/sections/PersonSectionTest.java

@@ -14,6 +14,8 @@ import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.headers.PersonSectionHeader;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.PersonSubSectionReferencesWriter;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.PersonSubSectionTimeLineWriter;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.ClearExistingTimeLineData;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.GatherTimeLineData;
 
 import static org.mockito.Mockito.verify;
 
@@ -34,9 +36,20 @@ class PersonSectionTest {
     @Mock
     private Person personMock;
 
+    @Mock
+    private GatherTimeLineData gatherTimeLineDataMock;
+
+    @Mock
+    ClearExistingTimeLineData clearExistingTimeLineDataMock;
+
     @BeforeEach
     void setUp() {
-        personSection = new PersonSectionImpl(personSectionHeaderMock, personSubSectionTimeLineWriterMock, personSubSectionReferencesWriterMock);
+        personSection = new PersonSectionImpl(
+                personSectionHeaderMock,
+                personSubSectionTimeLineWriterMock,
+                personSubSectionReferencesWriterMock,
+                clearExistingTimeLineDataMock,
+                gatherTimeLineDataMock);
     }
 
     @Test

+ 5 - 1
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/sections/PersonSubSectionReferencesWriterTest.java

@@ -14,6 +14,7 @@ import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.PersonSubSectionReferencesWriter;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.PersonSubSectionReferencesWriterImpl;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteReferences;
 
 import static org.mockito.Mockito.verify;
 
@@ -28,9 +29,12 @@ class PersonSubSectionReferencesWriterTest {
     @Mock
     private Person personMock;
 
+    @Mock
+    private WriteReferences writeReferencesMock;
+
     @BeforeEach
     void setUp() {
-        writer = new PersonSubSectionReferencesWriterImpl(latexSubSectionHeaderMock);
+        writer = new PersonSubSectionReferencesWriterImpl(latexSubSectionHeaderMock, writeReferencesMock);
     }
 
     @Test

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

@@ -14,6 +14,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteReferences;
 
 
 import static org.mockito.Mockito.verify;
@@ -26,12 +27,15 @@ class PersonSubSectionReferencesWriterTest {
     @Mock
     private LatexSubSectionHeader latexSubSectionHeaderMock;
 
+    @Mock
+    private WriteReferences writeReferencesMock;
+
     @Mock
     private Person personMock;
 
     @BeforeEach
     void setUp() {
-        personSubSectionReferencesWriter = new PersonSubSectionReferencesWriterImpl(latexSubSectionHeaderMock);
+        personSubSectionReferencesWriter = new PersonSubSectionReferencesWriterImpl(latexSubSectionHeaderMock, writeReferencesMock);
     }
 
     @Test

+ 1 - 16
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/PersonSubSectionTimeLineWriterTest.java

@@ -12,9 +12,6 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.writer.latex.LatexSubSectionHeader;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.ClearExistingTimeLineData;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.GatherTimeLineData;
-import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteReferences;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.WriteTimeLine;
 
 import static org.mockito.Mockito.verify;
@@ -33,23 +30,11 @@ class PersonSubSectionTimeLineWriterTest {
     @Mock
     private Person personMock;
 
-    @Mock
-    private WriteReferences writeReferencesMock;
-
-    @Mock
-    private ClearExistingTimeLineData clearExistingTimeLineDataMock;
-
-    @Mock
-    private GatherTimeLineData gatherTimeLineDataMock;
-
     @BeforeEach
     void setUp() {
         writer = new PersonSubSectionTimeLineWriterImpl(
                 latexSubSectionHeaderMock,
-                writeTimeLineMock,
-                writeReferencesMock,
-                clearExistingTimeLineDataMock,
-                gatherTimeLineDataMock);
+                writeTimeLineMock);
     }
 
     @Test