Skip to content

Commit 3256777

Browse files
committed
Completed Testing for login and sign up use case
1 parent 6c6077e commit 3256777

File tree

6 files changed

+235
-187
lines changed

6 files changed

+235
-187
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package loginAndSignUpUseCase;
2+
3+
import dataAccess.IUserDataAccess;
4+
import entityRequestModels.CommonUserDsRequestModel;
5+
6+
import java.util.Collection;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public class InMemoryUser implements IUserDataAccess {
11+
12+
final private Map<String, CommonUserDsRequestModel> users = new HashMap<>();
13+
@Override
14+
public CommonUserDsRequestModel getUser(String username) {
15+
return null;
16+
}
17+
18+
@Override
19+
public boolean existsByName(String username) {
20+
return users.containsKey(username);
21+
}
22+
23+
@Override
24+
public Collection<CommonUserDsRequestModel> getAllUsers() {
25+
return null;
26+
}
27+
28+
@Override
29+
public void saveFlashcardSetID(String username, int FlashcardSetID) {
30+
31+
}
32+
33+
@Override
34+
public void deleteFlashcardSetID(String username, int FlashcardSetID) {
35+
36+
}
37+
38+
@Override
39+
public void saveUser(CommonUserDsRequestModel user) {
40+
System.out.println("Save " + user.getUsername());
41+
users.put(user.getUsername(), user);
42+
}
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
title, description, privacy, id, owner, flashcardsIds
22
test set,for testing study use case,true,0,testUser,0,1,2,3,4,5,6,7,8,9,10,11
33
empty test set,for testing study use case with empty set,true,1,testUser,
4+
tester, tester thing, true, 0, Steve,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
username,password,isAdmin,flashcardSetsIds
2-
testUser,456r2t17yuihjn@,false,0,1
1+
username,password,isAdmin,flashcardSetIds
2+
testUser,456r2t17yuihjn@,false,0,1
Lines changed: 85 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,85 @@
1-
//package loginAndSignUpUseCase;
2-
//
3-
//import dataAccess.CommonUserDataAccess;
4-
//import dataAccess.DBGateway;
5-
//import dataAccess.IUserDataAccess;
6-
//import entities.CommonUserFactory;
7-
//import entities.UserFactory;
8-
//import org.junit.jupiter.api.BeforeEach;
9-
//import org.junit.jupiter.api.Test;
10-
//import loginAndSignupUseCase.*;
11-
//import org.junit.jupiter.api.Test;
12-
//import org.testing.annotations.Test;
13-
//
14-
//import static org.junit.jupiter.api.Assertions.*;
15-
//import java.io.IOException;
16-
//
17-
//import static org.junit.Assert.*;
18-
//import static org.testng.AssertJUnit.*;
19-
//
20-
//class UserRegisterInteractorTest {
21-
// UserRegisterOutputBoundary presenter = new UserRegisterOutputBoundary() {
22-
//
23-
// UserFactory userFactory = new CommonUserFactory();
24-
// UserRegisterInputBoundary interactor = new UserRegisterInteractor(
25-
// userRepository, presenter, userFactory);
26-
//
27-
// UserRegisterRequestModel inputData = new UserRegisterRequestModel(
28-
// "Richard", "Virgin123", "Virgin123", "BuiltDifferent");
29-
//
30-
// UserRegisterRequestModel inputData2 = new UserRegisterRequestModel(
31-
// "Branson", "Virgin123", "Virgin123", "");
32-
//
33-
// interactor.create(inputData);
34-
// interactor.create(inputData2);
35-
36-
// IFlashcardDataAccess flashcardGateway = new FlashcardDataAccess(
37-
// "src/test/java/quizUseCase/testData/Flashcards.csv");
38-
// IFlashcardSetDataAccess flashcardSetGateway = new FlashcardSetDataAccess(
39-
// "src/test/java/quizUseCase/testData/FlashcardSets.csv");
40-
// IUserDataAccess userGateway = new CommonUserDataAccess(
41-
// "src/test/java/quizUseCase/testData/Users.csv");
42-
//
43-
// DBGateway gateway = new DBGateway(flashcardGateway, flashcardSetGateway, userGateway);
44-
//
45-
// @Test
46-
// void login() throws IOException {
47-
//
48-
// UserLoginOutputBoundary presenter = new UserLoginOutputBoundary() {
49-
// @Override
50-
// public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
51-
// assertEquals("Richard", user.getSignedInUsername());
52-
// assertEquals(true, user.getIsAdmin());
53-
// assertEquals({}, user.getFlashcardSet());
54-
// return null;
55-
// }
56-
//
57-
// @Override
58-
// public UserLoginResponseModel prepareFailView(String error) {
59-
// fail("Use case failure is unexpected.");
60-
// return null;
61-
// }
62-
// };
63-
//
64-
// UserLoginInputBoundary interactor = new UserLoginInteractor(
65-
// userRepository, presenter, userFactory);
66-
//
67-
// }
68-
//
69-
// @Test
70-
// void create2() throws IOException {
71-
//
72-
//
73-
// }
74-
//
75-
//}
1+
package loginAndSignUpUseCase;
2+
3+
import dataAccess.*;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
import static org.junit.Assert.fail;
7+
import java.io.IOException;
8+
import loginAndSignupUseCase.loginAndSignupUseCaseScreens.UserLoginPresenter;
9+
import loginAndSignupUseCase.UserLoginOutputBoundary;
10+
import loginAndSignupUseCase.UserLoginInputBoundary;
11+
import loginAndSignupUseCase.UserLoginResponseModel;
12+
import loginAndSignupUseCase.UserLoginRequestModel;
13+
import loginAndSignupUseCase.UserLoginInteractor;
14+
15+
class UserLoginInteractorTest {
16+
17+
// 1) UserLoginInteractorTest and prerequisite objects
18+
19+
IUserDataAccess userGateway = new CommonUserDataAccess(
20+
"src/test/java/loginAndSignUpUseCase/testData/Users.csv");
21+
22+
23+
DBGateway gateway = new DBGateway(null, null, userGateway);
24+
25+
UserLoginInteractorTest() throws IOException {
26+
}
27+
28+
@Test
29+
void create() throws IOException {
30+
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
31+
@Override
32+
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
33+
34+
Assertions.assertEquals("Steve", user.getSignedInUsername());
35+
Assertions.assertFalse(user.getIsAdmin());
36+
//assertEquals(Map, user.getFlashcardSets());
37+
return null;
38+
}
39+
40+
@Override
41+
public UserLoginResponseModel prepareFailView(String error) {
42+
fail("Use case failure is unexpected.");
43+
return null;
44+
}
45+
};
46+
UserLoginInputBoundary interactor = new UserLoginInteractor(
47+
gateway, presenter);
48+
49+
// 2) Input data — Normally created by the Controller.
50+
UserLoginRequestModel inputData = new UserLoginRequestModel(
51+
"Steve", "Apple123");
52+
53+
// 3) Run the use case
54+
interactor.login(inputData);
55+
}
56+
57+
@Test
58+
void create2() throws IOException {
59+
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
60+
@Override
61+
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
62+
63+
Assertions.assertEquals("Richard", user.getSignedInUsername());
64+
Assertions.assertTrue(user.getIsAdmin());
65+
//assertEquals({}, user.getFlashcardSets());
66+
return null;
67+
}
68+
69+
@Override
70+
public UserLoginResponseModel prepareFailView(String error) {
71+
fail("Use case failure is unexpected.");
72+
return null;
73+
}
74+
};
75+
UserLoginInputBoundary interactor = new UserLoginInteractor(
76+
gateway, presenter);
77+
78+
// 2) Input data — Normally created by the Controller.
79+
UserLoginRequestModel inputData = new UserLoginRequestModel(
80+
"Richard", "Virgin123");
81+
82+
// 3) Run the use case
83+
interactor.login(inputData);
84+
}
85+
}

0 commit comments

Comments
 (0)