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); } }