Browse Source

UpdateRecordedYearOfBirth with no person

Andrew Grant 7 months ago
parent
commit
af0af3a5a7

+ 11 - 1
src/test/java/scot/carricksoftware/grants/services/census/censusentry/UpdateRecordedYearOfBirthFailingTest.java

@@ -48,13 +48,13 @@ class UpdateRecordedYearOfBirthFailingTest {
     @BeforeEach
     void setUp() {
         updateRecordedYearOfBirth = new UpdateRecordedYearOfBirthImpl(personConverterMock, personServiceMock);
-        when(censusEntryCommandMock.getPerson()).thenReturn(personMock);
     }
 
 
     @Test
     public void theYearOfBirthIsNotUpdatedIfAgeIsInvalidTest() {
         updateRecordedYearOfBirth = new UpdateRecordedYearOfBirthImpl(personConverterMock, personServiceMock);
+        when(censusEntryCommandMock.getPerson()).thenReturn(personMock);
         when(censusEntryCommandMock.getAge()).thenReturn("3 months");
         when(personMock.getRecordedYearOfBirth()).thenReturn(null);
         when(censusEntryCommandMock.getCensus()).thenReturn(censusMock);
@@ -63,8 +63,16 @@ class UpdateRecordedYearOfBirthFailingTest {
         verify(personCommandMock, times(0)).setRecordedYearOfBirth(anyString());
     }
 
+    @Test
+    public void theYearOfBirthIsNotUpdatedIfPersonIsNullTest() {
+        updateRecordedYearOfBirth = new UpdateRecordedYearOfBirthImpl(personConverterMock, personServiceMock);
+        verifyNoInteractions(personCommandMock);
+    }
+
+
     @Test
     public void theYearOfBirthIsNotResetTest() {
+        when(censusEntryCommandMock.getPerson()).thenReturn(personMock);
         when(personMock.getRecordedYearOfBirth()).thenReturn("1874");
         updateRecordedYearOfBirth.updateRecordedYearOfBirth(censusEntryCommandMock);
         verify(personCommandMock, times(0)).setRecordedYearOfBirth(anyString());
@@ -72,6 +80,7 @@ class UpdateRecordedYearOfBirthFailingTest {
 
     @Test
     public void anExceptionsIsThrownOnNullPersonCommandWithABirthYearTest() {
+        when(censusEntryCommandMock.getPerson()).thenReturn(personMock);
         when(personMock.getRecordedYearOfBirth()).thenReturn(null);
         when(censusEntryCommandMock.getBirthYear()).thenReturn("1880");
         when(personConverterMock.convert(personMock)).thenReturn(null);
@@ -81,6 +90,7 @@ class UpdateRecordedYearOfBirthFailingTest {
     @Test
     public void anExceptionsIsThrownOnNullPersonCommandWithNoBirthYearTest() {
         when(personMock.getRecordedYearOfBirth()).thenReturn(null);
+        when(censusEntryCommandMock.getPerson()).thenReturn(personMock);
         when(censusEntryCommandMock.getBirthYear()).thenReturn(null);
         when(censusEntryCommandMock.getCensus()).thenReturn(censusMock);
         when(censusEntryCommandMock.getAge()).thenReturn("7");