diff options
| -rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java | 57 | 
1 files changed, 57 insertions, 0 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java new file mode 100644 index 0000000..09d7c89 --- /dev/null +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java @@ -0,0 +1,57 @@ +package com.ufund.api.ufundapi.service; + +import java.io.IOException; +import java.util.TreeMap; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.ufund.api.ufundapi.DuplicateKeyException; +import com.ufund.api.ufundapi.model.Need; +import com.ufund.api.ufundapi.model.Need.GoalType; +import com.ufund.api.ufundapi.persistence.CupboardDAO; + +@Tag("Service-tier") +public class CupboardServiceTest { + +    private CupboardDAO mockCupboardDAO; +    private AuthService mockAuthService; +    private CupboardService cupboardService; + +    @BeforeEach +    public void setupCupboardService() throws IOException { +        mockCupboardDAO = mock(CupboardDAO.class); +        mockAuthService = mock(AuthService.class); +        cupboardService = new CupboardService(mockCupboardDAO); + +    } + +    @Test +    public void testCreateNeed() throws IOException, DuplicateKeyException { +        // Setup +        String name = "Jellyfish"; +        double maxGoal = 100.00; +        int id = 0; +        GoalType type = GoalType.MONETARY; +        Need need = new Need(name, type, maxGoal); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.getNeed(id)).thenReturn(need); +        when(mockCupboardDAO.addNeed(need)).thenReturn(need); +        when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); +         + +        // Invoke +        Need response = cupboardService.createNeed(name, maxGoal, type); + +        // Analyze +        assertNotNull(response); +        assertEquals(need, response); +    } + +}  | 
