소스 검색

CensusEntryServiceImpl::findAllByPerson test

Andrew Grant 3 달 전
부모
커밋
ada86d7926

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

@@ -31,7 +31,7 @@ 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);
@@ -40,6 +40,4 @@ public class CensusEntryServiceImpl implements CensusEntryService {
     }
 
 
-
-
 }

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

@@ -11,9 +11,16 @@ 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.repositories.censusentry.CensusEntryRepository;
 
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import static scot.carricksoftware.grantswriter.GenerateRandomPeopleValues.GetRandomPerson;
 
 @ExtendWith(MockitoExtension.class)
 class CensusEntryServiceTest {
@@ -29,8 +36,13 @@ class CensusEntryServiceTest {
     }
 
     @Test
-    void constructorTest() {
-        assertNotNull(censusEntryService);
+    void findAllByPersonTest() {
+        List<CensusEntry> censusEntryList = new ArrayList<>();
+        CensusEntry censusEntry = new CensusEntry();
+        censusEntryList.add(censusEntry);
+
+        when(censusEntryRepositoryMock.findAllByPerson(any())).thenReturn(censusEntryList);
+        assertEquals(censusEntryList, censusEntryService.findAllByPerson(GetRandomPerson()));
     }