aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-17 17:10:38 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-17 17:10:38 -0400
commitc4316368ccd2e724de838fa6648ff390d4f417a6 (patch)
treeda20406da93c33f1fab350802cbdf5be5131560e /ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
parentb998a4e7ca580f19ab10862de61d7458031027f2 (diff)
parented3d0e5e5f9c58c3926ea55a422212f4da1c8849 (diff)
downloadJellySolutions-c4316368ccd2e724de838fa6648ff390d4f417a6.tar.gz
JellySolutions-c4316368ccd2e724de838fa6648ff390d4f417a6.tar.bz2
JellySolutions-c4316368ccd2e724de838fa6648ff390d4f417a6.zip
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java63
1 files changed, 63 insertions, 0 deletions
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
new file mode 100644
index 0000000..f7db747
--- /dev/null
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java
@@ -0,0 +1,63 @@
+package com.ufund.api.ufundapi.persistence;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+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.fasterxml.jackson.databind.ObjectMapper;
+import com.ufund.api.ufundapi.model.UserAuth;
+
+@Tag("Persistence-tier")
+public class UserAuthFileDAOTest {
+
+ private UserAuthFIleDAO userAuthFIleDAO;
+ private ObjectMapper mockObjectMapper;
+ private UserAuth[] userAuths;
+
+ @BeforeEach
+ public void setupUserAuthFileDAO() throws IOException {
+
+ mockObjectMapper = mock(ObjectMapper.class);
+ userAuths = new UserAuth[]{
+ new UserAuth("123", "Phil", null),
+ new UserAuth("456", "Bob", null),
+ new UserAuth("789", "Steve", null)
+ };
+ // 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))
+ .thenReturn(userAuths);
+ userAuthFIleDAO = new UserAuthFIleDAO(mockObjectMapper, "doesnt_matter.txt");
+ }
+
+ @Test
+ public void getUserAuthTest() {
+ String key = "123";
+ UserAuth auth = userAuthFIleDAO.getUserAuth(key);
+
+ assertEquals(auth, userAuths[0]);
+ }
+
+ @Test
+ public void addUserAuthTest() throws IOException {
+ UserAuth auth = new UserAuth("999", "Fish", null);
+
+ assertDoesNotThrow(() -> userAuthFIleDAO.addUserAuth(auth));
+ }
+
+ @Test
+ public void removeUserAuthTest() throws IOException {
+ String key = "123";
+
+ assertDoesNotThrow(() -> userAuthFIleDAO.removeUserAuth(key));
+ }
+
+}