diff options
| -rw-r--r-- | docs/CodeCoverage.png | bin | 84383 -> 33191 bytes | |||
| -rw-r--r-- | docs/DesignDoc.md | 6 | ||||
| -rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java | 160 | ||||
| -rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java | 39 | 
4 files changed, 201 insertions, 4 deletions
| diff --git a/docs/CodeCoverage.png b/docs/CodeCoverage.pngBinary files differ index a795ef8..ef835fd 100644 --- a/docs/CodeCoverage.png +++ b/docs/CodeCoverage.png diff --git a/docs/DesignDoc.md b/docs/DesignDoc.md index 7f1c457..e20bc33 100644 --- a/docs/DesignDoc.md +++ b/docs/DesignDoc.md @@ -191,7 +191,7 @@ In our model tier we have a Need class, a User class, and a UserAuth class. The  > _This section will provide information about the testing performed  > and the results of the testing._ -Currently around 100 tests, with roughly 95% coverage overall. Model tier is above 95% individually. +Currently around 2,200 tests, with roughly 90% coverage overall. Model tier is above 95% individually.  ### Acceptance Testing @@ -220,4 +220,6 @@ We have 24 passing Acceptance Tests and 5 failing Acceptance Tests. 4 of these f  **(2025/02/15): Sprint #1: Outlined structure of Back-End Application.** -**(2025/03/17): Sprint #2: Decided on Important Stories for Sprint 2 Backlog, and reworked Design Architecture.**
\ No newline at end of file +**(2025/03/17): Sprint #2: Decided on Important Stories for Sprint 2 Backlog, and reworked Design Architecture.** + +**(2025/04/03): Sprint #3: Unanimously decided on enhancements, while narrowing focus on what needs to be finished for the sprint.**
\ No newline at end of file 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 2a3c8ee..da098d0 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 @@ -81,6 +81,78 @@ public class CupboardServiceTest {      }      @Test +    public void testCreateNeedBadPhysicalGoal() throws IOException { +        // Setup +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 1.23; +        GoalType type = Need.GoalType.PHYSICAL; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.addNeed(any())).thenReturn(need); +        when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); + +        // Invoke +        // Need response = cupboardService.createNeed(name, maxGoal, type); + +        // Analyze +        assertThrows(IllegalArgumentException.class, () -> +                cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); +    } + +    @Test +    public void testCreateNeedBadBlankFields() throws IOException { +        // Setup +        String name = ""; +        String location = "Atlantis"; +        double maxGoal = 1.23; +        GoalType type = Need.GoalType.PHYSICAL; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.addNeed(any())).thenReturn(need); +        when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); + +        // Invoke +        // Need response = cupboardService.createNeed(name, maxGoal, type); + +        // Analyze +        assertThrows(IllegalArgumentException.class, () -> +                cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); +    } + +    @Test +    public void testCreateNeedNullFields() throws IOException { +        // Setup +        String name = ""; +        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); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.addNeed(any())).thenReturn(need); +        when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); + +        // Invoke +        // Need response = cupboardService.createNeed(name, maxGoal, type); + +        // Analyze +        assertThrows(IllegalArgumentException.class, () -> +                cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); +    } + +    @Test      public void testCreateNeedDuplicate() throws IOException {          // Setup          String name = "Jellyfish"; @@ -198,6 +270,94 @@ public class CupboardServiceTest {      }      @Test +    public void testUpdateNeedBadGoal() throws IOException { +        // Setup +        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); +        // goal should not be 0, should throw error +        Need newNeed = new Need(name, image, location, 0, type, urgent, description); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed); + +        // Invoke and Analyze +        assertThrows(IllegalArgumentException.class, () -> +            cupboardService.updateNeed(newNeed, need.getId())); +    } + +    @Test +    public void testUpdateNeedBadPhysicalGoal() throws IOException { +        // Setup +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 10; +        GoalType type = Need.GoalType.PHYSICAL; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        // goal should be integer, should throw error +        Need newNeed = new Need(name, image, location, 1.23, type, urgent, description); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed); + +        // Invoke and Analyze +        assertThrows(IllegalArgumentException.class, () -> +            cupboardService.updateNeed(newNeed, need.getId())); +    } + +    @Test +    public void testUpdateNeedBlankFields() throws IOException { +        // Setup +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 10; +        GoalType type = Need.GoalType.PHYSICAL; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        // passed in blank name, should throw error +        Need newNeed = new Need("", image, location, maxGoal, type, urgent, description); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed); + +        // Invoke and Analyze +        assertThrows(IllegalArgumentException.class, () -> +            cupboardService.updateNeed(newNeed, need.getId())); +    } + +    @Test +    public void testUpdateNeedNotMatchingIDs() throws IOException { +        // Setup +        String name = "Jellyfish"; +        String location = "Atlantis"; +        double maxGoal = 10; +        GoalType type = Need.GoalType.PHYSICAL; +        boolean urgent = false; +        String image = ""; +        String description = ""; +        var need = new Need(name, image, location, maxGoal, type, urgent, description); +        // passed in blank name, should throw error +        Need newNeed = new Need(name, image, location, maxGoal, type, urgent, description); + +        // When the same id is passed in, our mock User DAO will return the User object +        when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed); + +        // Invoke and Analyze +        assertThrows(IllegalArgumentException.class, () -> +            cupboardService.updateNeed(newNeed, -1)); +    } + +    @Test      public void testDeleteNeed() throws IOException {          // Setup          String name = "Jellyfish"; diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java index 5adabf1..6234416 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java @@ -3,6 +3,7 @@ package com.ufund.api.ufundapi.service;  import java.io.IOException;  import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull;  import static org.junit.jupiter.api.Assertions.assertThrows;  import static org.junit.jupiter.api.Assertions.assertTrue;  import org.junit.jupiter.api.BeforeEach; @@ -75,6 +76,40 @@ public class UserServiceTest {      }      @Test +    public void testGetUserBlank() throws IOException { +        // Setup +        String username = "Jelly"; +        String password = "Fish"; +        User user = User.create(username, password); + +        // Mock +        when(mockUserDAO.getUser("notReal")).thenReturn(user); + +        // Analyze +        assertNull(userService.getUser(username)); +    } + +    @Test public void testGetUserCount() throws IOException { +        // Setup +        String username = "Jelly"; +        String password = "Fish"; +        User user = User.create(username, password); + +        // Mock +        when(mockUserDAO.getUser(username)).thenReturn(null); +        when(mockUserDAO.addUser(any())).thenReturn(user); +        when(mockUserDAO.getUserCount()).thenReturn(1); + +        // Invoke +        mockUserDAO.addUser(user); +        int userCount = userService.getUserCount(); + +        // Analyze +        assertEquals(userCount, 1); + +    } + +    @Test      public void testUpdateUser() throws IOException {          // Setup          String username = "Jelly"; @@ -118,10 +153,10 @@ public class UserServiceTest {          User user = User.create(username, password);          // Mock -        when(mockUserDAO.deleteUser(username)).thenReturn(true); +        when(mockUserDAO.deleteUser(user.getUsername())).thenReturn(true);          // Analyze -        assertTrue(userService.deleteUser(username)); +        assertTrue(userService.deleteUser(user.getUsername()));      }  } | 
