Selaa lähdekoodia

Validate RecordedYearOf Birth refactored (2)

Andrew Grant 7 kuukautta sitten
vanhempi
commit
8a9d1530df

+ 1 - 1
src/main/java/scot/carricksoftware/grants/services/census/censusentry/UpdateRecordedYearOfBirthImpl.java

@@ -67,6 +67,6 @@ public class UpdateRecordedYearOfBirthImpl implements UpdateRecordedYearOfBirth
     }
 
     private void logNoCommandError(){
-        logger.info("Person could not be converted to PersonCommand");
+        throw new NullPointerException("Person Command is null");
     }
 }

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

@@ -17,6 +17,7 @@ import scot.carricksoftware.grants.domains.census.Census;
 import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.services.people.PersonService;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.*;
 import static scot.carricksoftware.grants.enums.census.CensusDate.CENSUS_1881;
 
@@ -65,10 +66,27 @@ class UpdateRecordedYearOfBirthFailingTest {
     @Test
     public void theYearOfBirthIsNotResetTest() {
         when(personMock.getRecordedYearOfBirth()).thenReturn("1874");
-        when(personMock.getRecordedYearOfBirth()).thenReturn("1800");
         updateRecordedYearOfBirth.updateRecordedYearOfBirth(censusEntryCommandMock);
         verify(personCommandMock, times(0)).setRecordedYearOfBirth(anyString());
     }
 
+    @Test
+    public void anExceptionsIsThrownOnNullPersonCommandWithABirthYearTest() {
+        when(personMock.getRecordedYearOfBirth()).thenReturn(null);
+        when(censusEntryCommandMock.getBirthYear()).thenReturn("1880");
+        when(personConverterMock.convert(personMock)).thenReturn(null);
+        assertThrows(NullPointerException.class, () -> updateRecordedYearOfBirth.updateRecordedYearOfBirth(censusEntryCommandMock));
+    }
+
+    @Test
+    public void anExceptionsIsThrownOnNullPersonCommandWithNoBirthYearTest() {
+        when(personMock.getRecordedYearOfBirth()).thenReturn(null);
+        when(censusEntryCommandMock.getBirthYear()).thenReturn(null);
+        when(censusEntryCommandMock.getCensus()).thenReturn(censusMock);
+        when(censusEntryCommandMock.getAge()).thenReturn("7");
+        when(censusMock.getCensusDate()).thenReturn(CENSUS_1881);
+        assertThrows(NullPointerException.class, () -> updateRecordedYearOfBirth.updateRecordedYearOfBirth(censusEntryCommandMock));
+    }
+
 
 }