AddCensusEntryTest.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2025. Andrew Grant Carrick Software. All rights reserved
  3. *
  4. */
  5. package scot.carricksoftware.grantswriter.data.helpers;
  6. import org.junit.jupiter.api.BeforeEach;
  7. import org.junit.jupiter.api.Test;
  8. import org.junit.jupiter.api.extension.ExtendWith;
  9. import org.mockito.Mock;
  10. import org.mockito.junit.jupiter.MockitoExtension;
  11. import scot.carricksoftware.grantswriter.data.DMY;
  12. import scot.carricksoftware.grantswriter.domains.census.Census;
  13. import scot.carricksoftware.grantswriter.domains.census.CensusEntry;
  14. import scot.carricksoftware.grantswriter.domains.places.Place;
  15. import scot.carricksoftware.grantswriter.enums.census.CensusDate;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.SortedSet;
  19. import java.util.TreeMap;
  20. import java.util.TreeSet;
  21. import static org.junit.jupiter.api.Assertions.assertEquals;
  22. import static org.mockito.Mockito.when;
  23. import static scot.carricksoftware.grantswriter.GenerateCertificateRandomValues.GetRandomString;
  24. import static scot.carricksoftware.grantswriter.GenerateRandomPlaceValues.GetRandomPlace;
  25. @ExtendWith(MockitoExtension.class)
  26. class AddCensusEntryTest {
  27. private AddCensusEntry addCensusEntry;
  28. private TreeMap<DMY, List<String>> timeLine;
  29. private List<CensusEntry> censusEntryList;
  30. private SortedSet<String> refs;
  31. private Place place;
  32. @Mock
  33. private Census censusMock;
  34. @Mock
  35. private CensusEntry censusEntryMock;
  36. @BeforeEach
  37. void setUp() {
  38. addCensusEntry = new AddCensusEntryImpl();
  39. refs = new TreeSet<>();
  40. censusEntryList = new ArrayList<>();
  41. timeLine = new TreeMap<>();
  42. place = GetRandomPlace();
  43. when(censusEntryMock.getCensus()).thenReturn(censusMock);
  44. when(censusMock.getCensusDate()).thenReturn(CensusDate.CENSUS_1861);
  45. when(censusMock.getPlace()).thenReturn(place);
  46. censusEntryList.add(censusEntryMock);
  47. }
  48. @Test
  49. void refsTest() {
  50. String toString = GetRandomString();
  51. when(censusMock.toString()).thenReturn(toString);
  52. addCensusEntry.add(timeLine, refs, censusEntryList);
  53. assertEquals("Census: " + toString, refs.first());
  54. }
  55. @Test
  56. void timeLineTest() {
  57. addCensusEntry.add(timeLine, refs, censusEntryList);
  58. assertEquals("Recorded as being at " + place, timeLine.firstEntry().getValue().get(0));
  59. }
  60. @Test
  61. void OccupationTest() {
  62. String occupation = GetRandomString();
  63. when(censusEntryMock.getPersonalOccupation()).thenReturn(occupation);
  64. addCensusEntry.add(timeLine, refs, censusEntryList);
  65. assertEquals("Occupation recorded as " + occupation, timeLine.firstEntry().getValue().get(1));
  66. }
  67. }