aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/test/java/com')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java7
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java29
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java8
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java4
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java74
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java18
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java18
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java37
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java27
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java13
10 files changed, 138 insertions, 97 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
index 3d4637d..f4b5980 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/AuthControllerTest.java
@@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.mockito.ArgumentMatchers.any;
-import org.mockito.Mockito;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -26,7 +25,7 @@ public class AuthControllerTest {
private Map<String, String> authMap;
@BeforeEach
- private void setupAuthController() {
+ public void setupAuthController() {
mockAuthService = mock(AuthService.class);
authController = new AuthController(mockAuthService);
@@ -76,7 +75,7 @@ public class AuthControllerTest {
}
@Test
- public void testLogout() throws IllegalAccessException, IOException {
+ public void testLogout() {
// Setup
String key = "123";
@@ -88,7 +87,7 @@ public class AuthControllerTest {
}
@Test
- public void testLogoutIOException() throws IllegalAccessException, IOException {
+ public void testLogoutIOException() throws IOException {
// Setup
String key = "123";
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
index 6ef6710..89697bf 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
@@ -7,10 +7,11 @@ import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.*;
+
+import com.ufund.api.ufundapi.service.AuthService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import org.springframework.http.HttpStatus;
import com.ufund.api.ufundapi.DuplicateKeyException;
@@ -21,11 +22,17 @@ import com.ufund.api.ufundapi.service.CupboardService;
public class CupboardControllerTest {
private CupboardController cupboardController;
private CupboardService mockCupboardService;
+ private final String key = "dummyKey";
@BeforeEach
public void setupCupboardDAO() {
+ AuthService mockAuthService = mock(AuthService.class);
mockCupboardService = mock(CupboardService.class);
- cupboardController = new CupboardController(mockCupboardService);
+ cupboardController = new CupboardController(mockCupboardService, mockAuthService);
+
+ try {
+ doThrow().when(mockAuthService).keyHasAccessToCupboard(key);
+ } catch (Exception ignored) {}
}
@Test
@@ -43,7 +50,7 @@ public class CupboardControllerTest {
entry("type", "MONETARY")
);
- var res = cupboardController.createNeed(needMap);
+ var res = cupboardController.createNeed(needMap, key);
assertEquals(HttpStatus.OK, res.getStatusCode());
assertEquals(need, res.getBody());
@@ -58,7 +65,7 @@ public class CupboardControllerTest {
entry("maxGoal", -100.0),
entry("type", "MONETARY"));
- var res = cupboardController.createNeed(needMap);
+ var res = cupboardController.createNeed(needMap, key);
assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode());
}
@@ -72,7 +79,7 @@ public class CupboardControllerTest {
entry("maxGoal", 100.0),
entry("type", "MONETARY"));
- var res = cupboardController.createNeed(needMap);
+ var res = cupboardController.createNeed(needMap, key);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
}
@@ -174,7 +181,7 @@ public class CupboardControllerTest {
var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(need);
- var res = cupboardController.updateNeed(need, 1);
+ var res = cupboardController.updateNeed(need, 1, key);
assertEquals(HttpStatus.OK, res.getStatusCode());
assertEquals(need, res.getBody());
@@ -185,7 +192,7 @@ public class CupboardControllerTest {
var need = new Need("Name", 1, 100, Need.GoalType.MONETARY);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException());
- var res = cupboardController.updateNeed(need, 1);
+ var res = cupboardController.updateNeed(need, 1, key);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
}
@@ -196,7 +203,7 @@ public class CupboardControllerTest {
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenReturn(true);
- var res = cupboardController.deleteNeed(1);
+ var res = cupboardController.deleteNeed(1, key);
assertEquals(HttpStatus.OK, res.getStatusCode());
}
@@ -206,7 +213,7 @@ public class CupboardControllerTest {
when(mockCupboardService.getNeed(1)).thenReturn(null);
when(mockCupboardService.deleteNeed(1)).thenReturn(false);
- var res = cupboardController.deleteNeed(1);
+ var res = cupboardController.deleteNeed(1, key);
assertEquals(HttpStatus.NOT_FOUND, res.getStatusCode());
}
@@ -217,7 +224,7 @@ public class CupboardControllerTest {
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException());
- var res = cupboardController.deleteNeed(1);
+ var res = cupboardController.deleteNeed(1, key);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode());
}
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java
index 5542f49..06fb6cd 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java
@@ -82,7 +82,7 @@ public class UserControllerTest {
String key = UserAuth.generate(username).getKey();
// When getUser is called on the Mock User service, throw an IOException
// doThrow(new IllegalAccessException()).when(mockUserService).getUser(username);
- doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);
// Invoke
ResponseEntity<User> response = userController.getUser(username, key);
@@ -237,14 +237,14 @@ public class UserControllerTest {
String key = UserAuth.generate(username).getKey();
// When updateUser is called on the Mock User service, throw a Invalid Parameter exception
// exception
- doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);
// Invoke
ResponseEntity<User> response = userController.updateUser(user, username, key);
// Analyze
- assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
+ assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}
@Test
@@ -298,7 +298,7 @@ public class UserControllerTest {
String username = "Test";
String key = UserAuth.generate(username).getKey();
// When deleteUser is called on the Mock User service, throw an IOException
- doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key);
+ doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key);
// Invoke
ResponseEntity<Boolean> response = userController.deleteUser(username, key);
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
index 55b7f07..517a7e2 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
@@ -59,7 +59,7 @@ public class UserTest {
user.addToBasket(need);
- Need getNeed = cupboardService.getNeed(user.getNeeds()[0]);
+ Need getNeed = cupboardService.getNeed(user.getBasket()[0]);
assertEquals(needs[0], getNeed);
@@ -80,7 +80,7 @@ public class UserTest {
user.removeBasketNeed(need.getId());
user.addToBasket(need2);
- Need getNeed = cupboardService.getNeed(user.getNeeds()[0]);
+ Need getNeed = cupboardService.getNeed(user.getBasket()[0]);
assertEquals(need2, getNeed);
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
index f786a8c..d83e825 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -20,44 +21,42 @@ import com.ufund.api.ufundapi.model.Need.GoalType;
@Tag("Persistence-tier")
public class CupboardFileDAOTest {
- private CupboardFileDAO cupboardFileDao;
- private Need[] testNeeds;
- private ObjectMapper mockObjectMapper;
+ private CupboardFileDAO cupboardFileDao;
+ private Need[] testNeeds;
@BeforeEach
- public void setupCupboardFileDao() throws IOException {
- mockObjectMapper = mock(ObjectMapper.class);
- testNeeds = new Need[]{
- new Need("one", 0, 100, Need.GoalType.MONETARY),
- new Need("two", 1, 100, Need.GoalType.MONETARY),
- new Need("three", 2, 100, Need.GoalType.MONETARY)
+ public void setupCupboardFileDao() throws IOException {
+ ObjectMapper mockObjectMapper = mock(ObjectMapper.class);
+ testNeeds = new Need[] {
+ new Need("one", 0, 100, Need.GoalType.MONETARY),
+ new Need("two", 1, 100, Need.GoalType.MONETARY),
+ new Need("three", 2, 100, Need.GoalType.MONETARY)
};
- // When the object mapper is supposed to read from the file
- // the mock object mapper will return the hero array above
- when(mockObjectMapper
- .readValue(new File("doesnt_matter.txt"),Need[].class))
- .thenReturn(testNeeds);
- cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt",mockObjectMapper);
- }
-
- @Test
- public void getNeedsTest() {
- Need[] needs = cupboardFileDao.getNeeds();
- assertEquals(needs.length,testNeeds.length);
+ // When the object mapper is supposed to read from the file
+ // the mock object mapper will return the hero array above
+ when(mockObjectMapper
+ .readValue(new File("doesnt_matter.txt"), Need[].class))
+ .thenReturn(testNeeds);
+ cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt", mockObjectMapper);
+ }
+
+ @Test
+ public void getNeedsTest() {
+ Need[] needs = cupboardFileDao.getNeeds();
+ assertEquals(needs.length, testNeeds.length);
assertEquals(needs[0].getName(), testNeeds[0].getName());
- }
+ }
- @Test
- public void getNeedTest() {
+ @Test
+ public void getNeedTest() {
Need need1 = cupboardFileDao.getNeed(0);
-
+
assertEquals(testNeeds[0], need1);
- }
+ }
@Test
public void createNeedTest() throws IOException {
Need newNeed = new Need("sea urchin hats", 3, 100, GoalType.PHYSICAL);
-
Need actualNeed = cupboardFileDao.addNeed(newNeed);
@@ -79,6 +78,15 @@ public class CupboardFileDAOTest {
}
@Test
+ public void deleteNeedTestFail() throws IOException {
+ Need undeletedNeed = cupboardFileDao.getNeed(0);
+ assertNotNull(undeletedNeed);
+
+ boolean nullNeed = cupboardFileDao.deleteNeed(20);
+ assertFalse(nullNeed);
+ }
+
+ @Test
public void updateNeedTest() throws IOException {
Need[] needs = cupboardFileDao.getNeeds();
Need unupdatedNeed = needs[needs.length - 1];
@@ -91,4 +99,16 @@ public class CupboardFileDAOTest {
assertNotEquals(actualNeed, unupdatedNeed);
}
+ @Test
+ public void updateNeedTestFail() throws IOException {
+ Need[] needs = cupboardFileDao.getNeeds();
+ Need unupdatedNeed = needs[needs.length - 1];
+ assertNotNull(unupdatedNeed);
+
+ Need updatedNeed = new Need("sequin sea urchin hats", 20, 100, GoalType.PHYSICAL);
+
+ Need actualNeed = cupboardFileDao.updateNeed(updatedNeed);
+ assertNull(actualNeed);
+ }
+
}
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
index f7db747..a4842c5 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
@@ -2,6 +2,7 @@ package com.ufund.api.ufundapi.persistence;
import java.io.File;
import java.io.IOException;
+import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -18,22 +19,21 @@ import com.ufund.api.ufundapi.model.UserAuth;
public class UserAuthFileDAOTest {
private UserAuthFIleDAO userAuthFIleDAO;
- private ObjectMapper mockObjectMapper;
private UserAuth[] userAuths;
@BeforeEach
public void setupUserAuthFileDAO() throws IOException {
- mockObjectMapper = mock(ObjectMapper.class);
+ ObjectMapper mockObjectMapper = mock(ObjectMapper.class);
userAuths = new UserAuth[]{
- new UserAuth("123", "Phil", null),
- new UserAuth("456", "Bob", null),
- new UserAuth("789", "Steve", null)
+ new UserAuth("123", "Phil", LocalDateTime.MAX),
+ new UserAuth("456", "Bob", LocalDateTime.MAX),
+ new UserAuth("789", "Steve", LocalDateTime.MAX)
};
// When the object mapper is supposed to read from the file
// the mock object mapper will return the hero array above
when(mockObjectMapper
- .readValue(new File("doesnt_matter.txt"),UserAuth[].class))
+ .readValue(new File("doesnt_matter.txt"),UserAuth[].class))
.thenReturn(userAuths);
userAuthFIleDAO = new UserAuthFIleDAO(mockObjectMapper, "doesnt_matter.txt");
}
@@ -43,18 +43,18 @@ public class UserAuthFileDAOTest {
String key = "123";
UserAuth auth = userAuthFIleDAO.getUserAuth(key);
- assertEquals(auth, userAuths[0]);
+ assertEquals(userAuths[0], auth);
}
@Test
- public void addUserAuthTest() throws IOException {
+ public void addUserAuthTest() {
UserAuth auth = new UserAuth("999", "Fish", null);
assertDoesNotThrow(() -> userAuthFIleDAO.addUserAuth(auth));
}
@Test
- public void removeUserAuthTest() throws IOException {
+ public void removeUserAuthTest() {
String key = "123";
assertDoesNotThrow(() -> userAuthFIleDAO.removeUserAuth(key));
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
index 9361188..2ee0fc0 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
@@ -39,6 +39,24 @@ public class UserFileDAOTest {
userFileDAO = new UserFileDAO("doesnt_matter.txt",mockObjectMapper);
}
+ @Test
+ public void addUsersTest() throws IOException {
+ User user = User.create("Name", "Pass");
+
+ User addedUser = userFileDAO.addUser(user);
+
+ assertEquals(addedUser, user);
+ }
+
+ @Test
+ public void addUsersTestFail() throws IOException {
+ User user = User.create("bob", "test");
+
+ User existingUser = userFileDAO.addUser(user);
+
+ assertEquals(existingUser, testUsers[0]);
+ }
+
@Test
public void getUsersTest() {
User[] users = userFileDAO.getUsers();
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
index 55cf7a9..4f58b12 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java
@@ -11,7 +11,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import com.ufund.api.ufundapi.DuplicateKeyException;
import com.ufund.api.ufundapi.model.User;
import com.ufund.api.ufundapi.model.UserAuth;
import com.ufund.api.ufundapi.persistence.UserAuthDAO;
@@ -41,39 +40,39 @@ public class AuthServiceTest {
}
@Test
- public void testAuthenticate() throws IOException {
+ public void testKeyIsValid() throws IOException {
// Mock
when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, username, null));
when(mockUserService.getUser(username)).thenReturn(user);
// Analyze
- assertDoesNotThrow(() -> authService.authenticate(username, key));
+ assertDoesNotThrow(() -> authService.keyHasAccessToUser(username, key));
}
-// @Test
-// public void testAuthenticateMismatchName() throws IOException {
-// // Mock
-// when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, "EvilFish", null));
-// when(mockUserService.getUser("EvilFish")).thenReturn(user);
-//
-// // Analyze
-// assertThrows(IllegalAccessException.class, () -> authService.authenticate(username, key));
-//
-// }
+ @Test
+ public void testKeyIsValidMismatchName() throws IOException {
+ // Mock
+ when(mockAuthDAO.getUserAuth(key)).thenReturn(new UserAuth(key, "EvilFish", null));
+ when(mockUserService.getUser("EvilFish")).thenReturn(user);
+
+ // Analyze
+ assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToUser(username, key));
+
+ }
@Test
- public void testAuthenticateMissingUserAuth() throws IOException {
+ public void testKeyIsValidMissingUserAuth() throws IOException {
// Mock
when(mockAuthDAO.getUserAuth(key)).thenReturn(null);
// Analyze
- assertThrows(IllegalAccessException.class, () -> authService.authenticate(username, key));
+ assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToUser(username, key));
}
@Test
- public void testLogin() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLogin() throws IOException {
// Mock
when(mockUserService.getUser(username)).thenReturn(user);
@@ -83,7 +82,7 @@ public class AuthServiceTest {
}
@Test
- public void testLoginNullUser() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLoginNullUser() throws IOException {
// Mock
when(mockUserService.getUser(username)).thenReturn(null);
@@ -92,7 +91,7 @@ public class AuthServiceTest {
}
@Test
- public void testLoginMismatchPasswords() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLoginMismatchPasswords() throws IOException {
// Mock
when(mockUserService.getUser(username)).thenReturn(User.create(username, "fries"));
@@ -101,7 +100,7 @@ public class AuthServiceTest {
}
@Test
- public void testLogout() throws IOException, DuplicateKeyException, IllegalAccessException {
+ public void testLogout() {
// Analyze
assertDoesNotThrow(() -> authService.logout(key));
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 99ca23c..05ea2e8 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
@@ -27,7 +27,8 @@ public class CupboardServiceTest {
@BeforeEach
public void setupCupboardService() {
mockCupboardDAO = mock(CupboardDAO.class);
- cupboardService = new CupboardService(mockCupboardDAO);
+ AuthService mockAuthService = mock(AuthService.class);
+ cupboardService = new CupboardService(mockAuthService, mockCupboardDAO);
}
@@ -52,7 +53,7 @@ public class CupboardServiceTest {
}
@Test
- public void testCreateNeedBadGoal() throws IOException, DuplicateKeyException {
+ public void testCreateNeedBadGoal() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = -100.00;
@@ -67,13 +68,12 @@ public class CupboardServiceTest {
// Need response = cupboardService.createNeed(name, maxGoal, type);
// Analyze
- assertThrows(IllegalArgumentException.class, () -> {
- cupboardService.createNeed(name, maxGoal, type);
- });
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.createNeed(name, maxGoal, type));
}
@Test
- public void testCreateNeedDuplicate() throws IOException, DuplicateKeyException {
+ public void testCreateNeedDuplicate() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = 100.00;
@@ -89,13 +89,12 @@ public class CupboardServiceTest {
// Need response = cupboardService.createNeed(name, maxGoal, type);
// Analyze
- assertThrows(DuplicateKeyException.class, () -> {
- cupboardService.createNeed(name, maxGoal, type);
- });
+ assertThrows(DuplicateKeyException.class, () ->
+ cupboardService.createNeed(name, maxGoal, type));
}
@Test
- public void testSearchNeeds() throws IOException, DuplicateKeyException {
+ public void testSearchNeeds() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = 100.00;
@@ -115,7 +114,7 @@ public class CupboardServiceTest {
}
@Test
- public void testSearchNeedsFail() throws IOException, DuplicateKeyException {
+ public void testSearchNeedsFail() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = 100.00;
@@ -134,7 +133,7 @@ public class CupboardServiceTest {
}
@Test
- public void testGetNeed() throws IOException, DuplicateKeyException {
+ public void testGetNeed() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = 100.00;
@@ -153,7 +152,7 @@ public class CupboardServiceTest {
}
@Test
- public void testUpdateNeed() throws IOException, DuplicateKeyException {
+ public void testUpdateNeed() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = 100.00;
@@ -173,7 +172,7 @@ public class CupboardServiceTest {
}
@Test
- public void testDeleteNeed() throws IOException, DuplicateKeyException {
+ public void testDeleteNeed() throws IOException {
// Setup
String name = "Jellyfish";
double maxGoal = 100.00;
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 e57c5a3..5adabf1 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
@@ -19,13 +19,12 @@ public class UserServiceTest {
private UserService userService;
private UserDAO mockUserDAO;
- private CupboardService mockCupboardService;
@BeforeEach
public void setupUserService() {
mockUserDAO = mock(UserDAO.class);
- mockCupboardService = mock(CupboardService.class);
+ CupboardService mockCupboardService = mock(CupboardService.class);
userService = new UserService(mockUserDAO, mockCupboardService);
}
@@ -47,7 +46,7 @@ public class UserServiceTest {
}
@Test
- public void testCreateUserDuplicate() throws IOException, DuplicateKeyException {
+ public void testCreateUserDuplicate() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -62,7 +61,7 @@ public class UserServiceTest {
}
@Test
- public void testGetUser() throws IOException, DuplicateKeyException {
+ public void testGetUser() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -76,7 +75,7 @@ public class UserServiceTest {
}
@Test
- public void testUpdateUser() throws IOException, DuplicateKeyException {
+ public void testUpdateUser() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -94,7 +93,7 @@ public class UserServiceTest {
}
@Test
- public void testUpdateUserDifferentUsernames() throws IOException, DuplicateKeyException {
+ public void testUpdateUserDifferentUsernames() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";
@@ -112,7 +111,7 @@ public class UserServiceTest {
}
@Test
- public void testDeleteUser() throws IOException, DuplicateKeyException {
+ public void testDeleteUser() throws IOException {
// Setup
String username = "Jelly";
String password = "Fish";