aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
blob: 09d7c8930b3c4b2ea8e8a9ce3ba106b0a6deac62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
    }

}