diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-15 23:19:53 -0400 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-15 23:19:53 -0400 |
commit | 28e46060c8bcf7fd2adc19793bd63e27df4e7356 (patch) | |
tree | ab5d642d785bf0a4c284885973c1a196e7203dfb | |
parent | 5117f5eace7c6c905b5c1cf5871a3dbd29d67d5c (diff) | |
download | JellySolutions-28e46060c8bcf7fd2adc19793bd63e27df4e7356.tar.gz JellySolutions-28e46060c8bcf7fd2adc19793bd63e27df4e7356.tar.bz2 JellySolutions-28e46060c8bcf7fd2adc19793bd63e27df4e7356.zip |
Created class and began implementing createNeed test, but having issues with mocking
-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); + } + +} |