diff options
| -rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java | 75 | 
1 files changed, 69 insertions, 6 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 index da098d0..57cb0bf 100644 --- 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 @@ -2,11 +2,7 @@ package com.ufund.api.ufundapi.service;  import java.io.IOException; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*;  import static org.mockito.Mockito.*;  import org.junit.jupiter.api.BeforeEach; @@ -23,13 +19,14 @@ public class CupboardServiceTest {      private CupboardDAO mockCupboardDAO;      private CupboardService cupboardService; +    private AuthService mockAuthService;      @BeforeEach      public void setupCupboardService() {          mockCupboardDAO = mock(CupboardDAO.class);          AuthService mockAuthService = mock(AuthService.class);          cupboardService = new CupboardService(mockAuthService, mockCupboardDAO); - +        this.mockAuthService = mock(AuthService.class);      }      @Test @@ -382,4 +379,70 @@ public class CupboardServiceTest {          assertArrayEquals(new Need[0], responseNeeds);      } +    @Test +    void checkoutNeed() throws IOException, IllegalAccessException { +        int id = 1; +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 100.0; +        GoalType type = Need.GoalType.MONETARY; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        String key = "anything"; +        var amount = 10; + +        doNothing().when(mockAuthService).keyIsValid(key); +        when(mockCupboardDAO.getNeed(id)).thenReturn(need); + +        assertDoesNotThrow(() -> cupboardService.checkoutNeed(id, amount, key)); +    } + +    @Test +    void checkoutNeed2() { +        int id = 1; +        String key = "anything"; +        var amount = -5; + +        assertThrows(IllegalArgumentException.class, () -> cupboardService.checkoutNeed(id, amount, key)); +    } + +    @Test +    void checkoutNeed3() throws IOException { +        int id = 1; +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 100.0; +        GoalType type = GoalType.PHYSICAL; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        String key = "anything"; +        var amount = 3.1459; + +        when(mockCupboardDAO.getNeed(id)).thenReturn(need); + +        assertThrows(IllegalArgumentException.class, () -> cupboardService.checkoutNeed(id, amount, key)); +    } + +    @Test +    void checkoutNeed4() throws IOException { +        int id = 1; +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 100.0; +        GoalType type = GoalType.MONETARY; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        String key = "anything"; +        var amount = 3.1459; + +        when(mockCupboardDAO.getNeed(id)).thenReturn(need); + +        assertDoesNotThrow(() -> cupboardService.checkoutNeed(id, amount, key)); +    }  }
\ No newline at end of file | 
