Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for data access classses #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/main/java/entities/QuizQuestion.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package entities;

import entities.Flashcard;

import java.util.List;

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/frameworks_and_drivers/database/DBGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public DBGateway(IFlashcardDataAccess flashcardGateway,
this.userGateway = userGateway;
}

/**
* Gets the user object with a given username.
* @param username the user's username.
* @return the user object with the given username.
*/
public CommonUserDsRequestModel getUser(String username) { return this.userGateway.getUser(username); }
/**
* Returns the value for if the user contains the given username.
* @param username the user's username.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class FlashcardSetInteractorTest {
public class CreateFlashcardSetUseCaseTest {

/**
* [Feature 3: Creating a Flashcard Set]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Tests for create_flashcard_use_case.FcCInteractor
* @author Junyu Chen
*/
public class FcCInteractorTest {
public class CreateFlashcardUseCaseTest {

/**
* Test for creation of valid flashcard.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package data_access_use_case;

import frameworks_and_drivers.database.CommonUserDataAccess;
import frameworks_and_drivers.database.DBGateway;
import frameworks_and_drivers.database.FlashcardDataAccess;
import frameworks_and_drivers.database.FlashcardSetDataAccess;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.LocalDateTime;

import java.util.List;


public class DataAccessClassesUseCaseTest {

private static final String flashcardPath = "src/test/java/data_access_use_case/test_data/Flashcards.csv";

private static final String flashcardSetPath = "src/test/java/data_access_use_case/test_data/FlashcardSets.csv";

private static final String userPath = "src/test/java/data_access_use_case/test_data/Users.csv";


DBGateway setup() throws IOException {
IFlashcardDataAccess flashcardGateway = new FlashcardDataAccess(flashcardPath);
IFlashcardSetDataAccess flashcardSetGateway = new FlashcardSetDataAccess(flashcardSetPath);
IUserDataAccess userGateway = new CommonUserDataAccess(userPath);

return new DBGateway(flashcardGateway, flashcardSetGateway, userGateway);
}

// Test for user data access
@Test
void testUserData() throws IOException {
DBGateway gateway = this.setup();

List<Integer> testIdList = List.of(0);
Assertions.assertTrue(gateway.existsByName("testUser1"));
Assertions.assertEquals(testIdList, gateway.getUser("testUser1").getFlashcardSetIds());
Assertions.assertFalse(gateway.getUser("testUser1").getIsAdmin());
Assertions.assertEquals("testUser1", gateway.getUser("testUser1").getUsername());
Assertions.assertEquals("search", gateway.getUser("testUser1").getPassword());

Assertions.assertEquals("src/data/Users.csv", DBGateway.getUserPath());
}

// test for flashcard access data
@Test
void testFlashcardData() throws IOException {
DBGateway gateway = this.setup();

Assertions.assertEquals(0, gateway.getFlashcard(0).getFlashcardId());
Assertions.assertEquals("test card 1", gateway.getFlashcard(0).getTerm());
Assertions.assertEquals("the first test card", gateway.getFlashcard(0).getDefinition());
Assertions.assertEquals(0, gateway.getFlashcard(0).getBelongsToId());
Assertions.assertEquals(LocalDateTime.parse("2022-11-13T15:32:26.666982800"), gateway.getFlashcard(0).getCreationDate());

Assertions.assertEquals("src/data/Flashcards.csv", DBGateway.getFlashcardPath());
}

// test for flashcard set data access
@Test
void testFlashcardSetData() throws IOException {
DBGateway gateway = this.setup();

Assertions.assertEquals(0, gateway.getFlashcardSet(0).getFlashcardSetId());
Assertions.assertEquals("test1", gateway.getFlashcardSet(0).getTitle());
Assertions.assertEquals("d1", gateway.getFlashcardSet(0).getDescription());
Assertions.assertEquals("testUser1", gateway.getFlashcardSet(0).getOwnerUsername());
List <Integer> testFlashcardIdList = List.of(0);
Assertions.assertEquals(testFlashcardIdList, gateway.getFlashcardSet(0).getFlashcardIds());
Assertions.assertEquals(false, gateway.getFlashcardSet(0).getIsPrivate());

Assertions.assertEquals("src/data/FlashcardSets.csv", DBGateway.getFlashcardSetPath());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title,description,privacy,id,owner,flashcardsIds
test1,d1,false,0,testUser1,0
test2,d2,false,1,testUser2,0
test3,d3,false,2,testUser3,0
test4,d4,false,3,testUser4,0
test5,d5,true,4,testUser4,0
test6,d6,true,5,testUser4,0
5 changes: 5 additions & 0 deletions src/test/java/data_access_use_case/test_data/Flashcards.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
term,definition,creationDate,flashcardId,belongsToId
test card 1,the first test card,2022-11-13T15:32:26.666982800,0,0
test card 2,the second test card,2022-11-13T15:32:27.666982800,1,0
test card 3,the third test card,2022-11-13T15:32:28.666982800,2,0
alphabetical order checker,to test if alphabetical order is working,2022-11-13T15:32:29.666982800,3,0
5 changes: 5 additions & 0 deletions src/test/java/data_access_use_case/test_data/Users.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
username,password,isAdmin,flashcardSetsIds
testUser1,search,false,0
testUser2,use,false,1
testUser3,test,true,2
testUser4,file,false,3,4,5
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author Edward Ishii
*/
public class DeleteFlashcardScreenFlashcardSetInteractorTest {
public class DeleteFlashcardSetUseCaseTest {

IFlashcardSetDataAccess flashcardSetRepo;
IFlashcardDataAccess flashcardRepo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Tests for delete_flashcard_use_case.FcRInteractor
* @author Junyu Chen
*/
public class FcRInteractorTest {
public class DeleteFlashcardUseCaseTest {
/**
* Test deletion for valid delete request.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.ArrayList;
import java.util.List;

public class FCSetEditorInteractorTest {
public class EditFlashcardSetUseCaseTest {

@Test
public void editSuccess(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;

public class FlashcardInteractorTest {
public class EditFlashcardUseCaseTest {

@Test
public void editSuccess(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import static org.junit.jupiter.api.Assertions.*;

public class StudySessionUseCaseUnitTest {
public class StudySessionUseCaseTest {

/**
* the id of the study test set in the test database
Expand Down