aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java
diff options
context:
space:
mode:
authorAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-04-08 00:52:47 -0400
committerAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-04-08 00:52:47 -0400
commit78e9791da675783124c76a20f756886005ffa904 (patch)
tree56faeae845c2d22876c0f5978c164c10a1bccbdb /ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java
parentef62e670a4af08026581db83410bbc8b98e45d7d (diff)
downloadJellySolutions-78e9791da675783124c76a20f756886005ffa904.tar.gz
JellySolutions-78e9791da675783124c76a20f756886005ffa904.tar.bz2
JellySolutions-78e9791da675783124c76a20f756886005ffa904.zip
update designdoc and add more test coverage
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java39
1 files changed, 37 insertions, 2 deletions
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()));
}
}