Skip to content

Commit d014c50

Browse files
committed
Ammended Login and Register Test case to work properly
1 parent 17ee1c9 commit d014c50

File tree

4 files changed

+190
-23
lines changed

4 files changed

+190
-23
lines changed
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
11
title, description, privacy, id, owner, flashcardsIds
22
test set,for testing study use case,true,0,Walt,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,Walt,
4-
tester,tester thing,true,3,Steve,
4+
tester,tester thing,true,2,Steve,
5+
test set3,for testing login use case3,true,3,Walt,0,1,2,3,4,5,6,7,8,9,10,11
6+
test set4,for testing login use case4,true,4,Walt,0,1,2,3,4,5,6,7,8,9,10,11
7+
test set5,for testing login use case5,true,5,Walt,0,1,2,3,4,5,6,7,8,9,10,11
8+
test set6,for testing login use case6,true,6,Walt,0,1,2,3,4,5,6,7,8,9,10,11
9+
test set7,for testing login use case7,true,7,Walt,0,1,2,3,4,5,6,7,8,9,10,11
10+
test set8,for testing login use case8,true,8,Walt,0,1,2,3,4,5,6,7,8,9,10,11
11+
test set9,for testing login use case9,true,9,Walt,0,1,2,3,4,5,6,7,8,9,10,11
12+
test set10,for testing login use case10,true,10,Walt,0,1,2,3,4,5,6,7,8,9,10,11
13+
test set11,for testing login use case11,true,11,Walt,0,1,2,3,4,5,6,7,8,9,10,11
14+
test set12,for testing login use case12,true,12,Walt,0,1,2,3,4,5,6,7,8,9,10,11
15+
test set13,for testing login use case13,true,13,Walt,0,1,2,3,4,5,6,7,8,9,10,11
16+
test set14,for testing login use case14,true,14,Walt,0,1,2,3,4,5,6,7,8,9,10,11
17+
test set15,for testing login use case15,true,15,Walt,0,1,2,3,4,5,6,7,8,9,10,11
18+
test set16,for testing login use case16,true,16,Walt,0,1,2,3,4,5,6,7,8,9,10,11
19+
test set17,for testing login use case17,true,17,Walt,0,1,2,3,4,5,6,7,8,9,10,11
20+
test set18,for testing login use case18,true,18,Walt,0,1,2,3,4,5,6,7,8,9,10,11
21+
test set19,for testing login use case19,true,19,Walt,0,1,2,3,4,5,6,7,8,9,10,11
22+
test set20,for testing login use case20,true,20,Walt,0,1,2,3,4,5,6,7,8,9,10,11
23+
test set21,for testing login use case21,true,21,Walt,0,1,2,3,4,5,6,7,8,9,10,11
24+
test set22,for testing login use case22,true,22,Walt,0,1,2,3,4,5,6,7,8,9,10,11
25+
test set23,for testing login use case23,true,23,Walt,0,1,2,3,4,5,6,7,8,9,10,11
26+
test set24,for testing login use case24,true,24,Walt,0,1,2,3,4,5,6,7,8,9,10,11
27+
test set25,for testing login use case25,true,25,Walt,0,1,2,3,4,5,6,7,8,9,10,11
28+
test set26,for testing login use case26,true,26,Walt,0,1,2,3,4,5,6,7,8,9,10,11
29+
test set27,for testing login use case27,true,27,Walt,0,1,2,3,4,5,6,7,8,9,10,11
30+
test set28,for testing login use case28,true,28,Walt,0,1,2,3,4,5,6,7,8,9,10,11
31+
test set29,for testing login use case29,true,29,Walt,0,1,2,3,4,5,6,7,8,9,10,11
32+
test set30,for testing login use case30,true,30,Walt,0,1,2,3,4,5,6,7,8,9,10,11
33+
test set90,for testing login use case90,true,90,Walt,0,1,2,3,4,5,6,7,8,9,10,11
34+
test set91,for testing login use case91,true,91,Walt,0,1,2,3,4,5,6,7,8,9,10,11
35+
test set92,for testing login use case92,true,92,Walt,0,1,2,3,4,5,6,7,8,9,10,11
36+
test set93,for testing login use case93,true,93,Walt,0,1,2,3,4,5,6,7,8,9,10,11
37+
test set94,for testing login use case94,true,94,Walt,0,1,2,3,4,5,6,7,8,9,10,11
38+
test set95,for testing login use case95,true,95,Walt,0,1,2,3,4,5,6,7,8,9,10,11
39+
test set96,for testing login use case96,true,96,Walt,0,1,2,3,4,5,6,7,8,9,10,11
40+
test set97,for testing login use case97,true,97,Walt,0,1,2,3,4,5,6,7,8,9,10,11
41+
test set98,for testing login use case98,true,98,Walt,0,1,2,3,4,5,6,7,8,9,10,11
42+
test set99,for testing login use case99,true,99,Walt,0,1,2,3,4,5,6,7,8,9,10,11
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
username,password,isAdmin,flashcardSetIds
22
Tom,Cruise123,true
3-
George,Clooney123,false
4-
Steve,Apple123,false
3+
George,Clooney123,false,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,90,91,92,93,94,95,96,97,98,99
4+
Steve,Apple123,false,6,7,2,30,5,99,3,6,96,27
55
John,Rockefeller123,false
66
Richard,Virgin123,true
7+
Ch3is,EVans!@#$,true,0,1,3,30,90
78
testUser,456r2t17yuihjn@,false,0,1
89
Walt,Disney123,false,0,1
910
Brad,Pitt123,true
10-
rObErT,DowneyJr.,true
11-
Ch3is,EVans,true
11+
rObErT,DowneyJr.,true,3,33

src/test/java/login_and_sign_up_use_case/userLoginInteractorTest.java

Lines changed: 102 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,20 @@ void login2() throws IOException {
6666
@Override
6767
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
6868
HashMap<Integer, String[]> emptyFlashcardSet = new HashMap();
69-
Map<Integer, String[]> notEmptyFlashcardSet = user.getFlashcardSets();
69+
Map<Integer, String[]> notEmptyFlashcardSet = new HashMap<>();
70+
String[] firstSet = new String[] {"test set", "for testing study use case"};
71+
String[] secondSet = new String[] {"empty test set", "for testing study use case with empty set"};
72+
notEmptyFlashcardSet.put(0, firstSet);
73+
notEmptyFlashcardSet.put(1, secondSet);
7074

7175
Assertions.assertEquals("Walt", user.getSignedInUsername());
7276
Assertions.assertFalse(user.getIsAdmin());
7377
Assertions.assertTrue(!user.getIsAdmin());
74-
Assertions.assertEquals(notEmptyFlashcardSet, user.getFlashcardSets());
75-
System.out.println(user.getFlashcardSets());
78+
Assertions.assertEquals(notEmptyFlashcardSet.get(0)[0], user.getFlashcardSets().get(0)[0]);
79+
Assertions.assertEquals(notEmptyFlashcardSet.get(0)[1], user.getFlashcardSets().get(0)[1]);
80+
Assertions.assertEquals(notEmptyFlashcardSet.get(1)[0], user.getFlashcardSets().get(1)[0]);
81+
Assertions.assertEquals(notEmptyFlashcardSet.get(1)[1], user.getFlashcardSets().get(1)[1]);
82+
Assertions.assertEquals(notEmptyFlashcardSet.size(), user.getFlashcardSets().size());
7683
Assertions.assertNotEquals(emptyFlashcardSet, user.getFlashcardSets());
7784
return null;
7885
}
@@ -101,6 +108,8 @@ public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
101108
Assertions.assertEquals("George", user.getSignedInUsername());
102109
Assertions.assertFalse(user.getIsAdmin());
103110
Assertions.assertTrue(!user.getIsAdmin());
111+
Assertions.assertNotNull(user.getFlashcardSets().size());
112+
Assertions.assertTrue(user.getFlashcardSets().size() == 41);
104113
return null;
105114
}
106115

@@ -124,10 +133,96 @@ void login4() throws IOException {
124133
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
125134
@Override
126135
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
127-
128-
Assertions.assertEquals("rObErT", user.getSignedInUsername());
136+
HashMap<Integer, String[]> emptyFlashcardSet = new HashMap();
137+
Map<Integer, String[]> notEmptyFlashcardSet = new HashMap<>();
138+
String[] zeroethSet = new String[] {"test set", "for testing study use case"};
139+
String[] firstSet = new String[] {"empty test set", "for testing study use case with empty set"};
140+
String[] secondSet = new String[] {"tester", "tester thing"};
141+
String[] thirdSet = new String[] {"test set3", "for testing login use case3"};
142+
String[] thirtiethSet = new String[] {"test set30", "for testing login use case30"};
143+
String[] ninetiethSet = new String[] {"test set90", "for testing login use case90"};
144+
notEmptyFlashcardSet.put(0, zeroethSet);
145+
notEmptyFlashcardSet.put(1, firstSet);
146+
notEmptyFlashcardSet.put(2, secondSet);
147+
notEmptyFlashcardSet.put(3, thirdSet);
148+
notEmptyFlashcardSet.put(4, thirtiethSet);
149+
notEmptyFlashcardSet.put(5, ninetiethSet);
150+
int setSize = user.getFlashcardSets().size();
151+
int tempSetSize = notEmptyFlashcardSet.size();
152+
153+
Assertions.assertEquals("Ch3is", user.getSignedInUsername());
154+
Assertions.assertNotEquals("rObErT", user.getSignedInUsername());
129155
Assertions.assertTrue(user.getIsAdmin());
130-
Assertions.assertFalse(!user.getIsAdmin());
156+
Assertions.assertNotEquals(emptyFlashcardSet, user.getFlashcardSets());
157+
Assertions.assertEquals(tempSetSize-1, setSize);
158+
Assertions.assertEquals(notEmptyFlashcardSet.get(0)[0], user.getFlashcardSets().get(0)[0]);
159+
Assertions.assertEquals(notEmptyFlashcardSet.get(0)[1], user.getFlashcardSets().get(0)[1]);
160+
Assertions.assertEquals(notEmptyFlashcardSet.get(1)[0], user.getFlashcardSets().get(1)[0]);
161+
Assertions.assertEquals(notEmptyFlashcardSet.get(1)[1], user.getFlashcardSets().get(1)[1]);
162+
Assertions.assertEquals(notEmptyFlashcardSet.get(3)[0], user.getFlashcardSets().get(3)[0]);
163+
Assertions.assertEquals(notEmptyFlashcardSet.get(3)[1], user.getFlashcardSets().get(3)[1]);
164+
Assertions.assertEquals(notEmptyFlashcardSet.get(4)[0], user.getFlashcardSets().get(30)[0]);
165+
Assertions.assertEquals(notEmptyFlashcardSet.get(4)[1], user.getFlashcardSets().get(30)[1]);
166+
Assertions.assertEquals(notEmptyFlashcardSet.get(5)[0], user.getFlashcardSets().get(90)[0]);
167+
Assertions.assertEquals(notEmptyFlashcardSet.get(5)[1], user.getFlashcardSets().get(90)[1]);
168+
return null;
169+
}
170+
171+
@Override
172+
public UserLoginResponseModel prepareFailView(String error) {
173+
fail("Use case failure is unexpected.");
174+
return null;
175+
}
176+
};
177+
UserLoginInputBoundary interactor = new UserLoginInteractor(
178+
gateway, presenter);
179+
180+
UserLoginRequestModel inputData = new UserLoginRequestModel(
181+
"Ch3is", "EVans!@#$");
182+
183+
interactor.login(inputData);
184+
}
185+
186+
@Test
187+
void login5() {
188+
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
189+
@Override
190+
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
191+
Assertions.assertEquals("Steve", user.getSignedInUsername());
192+
Assertions.assertFalse(user.getIsAdmin());
193+
Assertions.assertTrue(user.getFlashcardSets().size() == 9);
194+
userGateway.saveFlashcardSetID(user.getSignedInUsername(), 90);
195+
196+
return null;
197+
}
198+
199+
@Override
200+
public UserLoginResponseModel prepareFailView(String error) {
201+
fail("Use case failure is unexpected.");
202+
return null;
203+
}
204+
};
205+
UserLoginInputBoundary interactor = new UserLoginInteractor(
206+
gateway, presenter);
207+
208+
UserLoginRequestModel inputData = new UserLoginRequestModel(
209+
"Steve", "Apple123");
210+
211+
interactor.login(inputData);
212+
}
213+
214+
@Test
215+
void login6() {
216+
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
217+
@Override
218+
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
219+
Assertions.assertEquals("Steve", user.getSignedInUsername());
220+
Assertions.assertFalse(user.getIsAdmin());
221+
Assertions.assertTrue(user.getFlashcardSets().size() == 10);
222+
userGateway.deleteFlashcardSetID(user.getSignedInUsername(), 90);
223+
224+
System.out.println(user.getFlashcardSets().size());
225+
131226
return null;
132227
}
133228

@@ -141,7 +236,7 @@ public UserLoginResponseModel prepareFailView(String error) {
141236
gateway, presenter);
142237

143238
UserLoginRequestModel inputData = new UserLoginRequestModel(
144-
"rObErT", "DowneyJr.");
239+
"Steve", "Apple123");
145240

146241
interactor.login(inputData);
147242
}

src/test/java/login_and_sign_up_use_case/userRegisterInteractorTest.java

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UserRegisterInteractorTest {
3232
}
3333

3434
@Test
35-
void create() throws IOException {
35+
void register(){
3636
// 1) Create a UserRegisterInteractor and prerequisite objects
3737
// (arguments for the UserRegisterInteractor constructor parameters)
3838
// 2) create the Input Data
@@ -48,7 +48,6 @@ public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel us
4848
// are correct
4949
Assertions.assertEquals("Steve", user.getSignedUpUsername());
5050
Assertions.assertFalse(user.getIsAdmin());
51-
Assertions.assertTrue(!user.getIsAdmin());
5251
Assertions.assertTrue(gateway.existsByName("Steve"));
5352
return null;
5453
}
@@ -73,7 +72,7 @@ public UserRegisterResponseModel prepareFailView(String error) {
7372
}
7473

7574
@Test
76-
void create2() throws IOException {
75+
void register2WithExistingUser(){
7776
UserRegisterOutputBoundary presenter = new UserRegisterOutputBoundary() {
7877
@Override
7978
public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel user) {
@@ -104,15 +103,15 @@ public UserRegisterResponseModel prepareFailView(String error) {
104103
}
105104

106105
@Test
107-
void create3() throws IOException {
106+
void register3WithMultipleExistingUsers(){
108107
UserRegisterOutputBoundary presenter = new UserRegisterOutputBoundary() {
109108
@Override
110109
public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel user) {
111110

112111
Assertions.assertEquals("Tom", user.getSignedUpUsername());
113112
Assertions.assertTrue(user.getIsAdmin());
114113
Assertions.assertTrue(gateway.existsByName("Steve"));
115-
Assertions.assertTrue(gateway.existsByName("Richard"));
114+
//\ Assertions.assertTrue(gateway.existsByName("Richard"));
116115
Assertions.assertTrue(gateway.existsByName("Tom"));
117116
Assertions.assertFalse(gateway.existsByName("Daquan"));
118117
return null;
@@ -136,16 +135,17 @@ public UserRegisterResponseModel prepareFailView(String error) {
136135
}
137136

138137
@Test
139-
void create4() throws IOException {
138+
void register4WithMultipleExistingUsersAndPasswordTest(){
140139
UserRegisterOutputBoundary presenter = new UserRegisterOutputBoundary() {
141140
@Override
142141
public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel user) {
143142

144143
Assertions.assertEquals("Brad", user.getSignedUpUsername());
145144
Assertions.assertTrue(user.getIsAdmin());
145+
Assertions.assertNotEquals("Brad123", user.getSignedUpPassword());
146146
Assertions.assertTrue(gateway.existsByName("Steve"));
147-
Assertions.assertTrue(gateway.existsByName("Richard"));
148-
Assertions.assertTrue(gateway.existsByName("Tom"));
147+
// Assertions.assertTrue(gateway.existsByName("Richard"));
148+
// Assertions.assertTrue(gateway.existsByName("Tom"));
149149
Assertions.assertTrue(gateway.existsByName("Brad"));
150150
Assertions.assertFalse(gateway.existsByName("Daquan"));
151151
return null;
@@ -169,7 +169,43 @@ public UserRegisterResponseModel prepareFailView(String error) {
169169
}
170170

171171
@Test
172-
void create5() throws IOException {
172+
void register5WithMultipleExistingUsersAndPasswordTestAndUnconventionalChars(){
173+
UserRegisterOutputBoundary presenter = new UserRegisterOutputBoundary() {
174+
@Override
175+
public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel user) {
176+
177+
Assertions.assertEquals("HeNr!", user.getSignedUpUsername());
178+
Assertions.assertFalse(user.getIsAdmin());
179+
Assertions.assertEquals("Superman123", user.getSignedUpPassword());
180+
// Assertions.assertTrue(userGateway.existsByName("Brad"));
181+
Assertions.assertTrue(gateway.existsByName("Steve"));
182+
Assertions.assertTrue(gateway.existsByName("HeNr!"));
183+
// Assertions.assertTrue(gateway.existsByName("Tom"));
184+
// Assertions.assertTrue(gateway.existsByName("Richard"));
185+
Assertions.assertFalse(gateway.existsByName("Daquan"));
186+
187+
return null;
188+
}
189+
190+
@Override
191+
public UserRegisterResponseModel prepareFailView(String error) {
192+
fail("Use case failure is unexpected.");
193+
return null;
194+
}
195+
};
196+
197+
UserFactory userFactory = new CommonUserFactory();
198+
UserRegisterInputBoundary interactor = new UserRegisterInteractor(
199+
gateway, presenter, userFactory);
200+
201+
UserRegisterRequestModel inputData = new UserRegisterRequestModel(
202+
"HeNr!", "Superman123", "Superman123", "");
203+
204+
interactor.create(inputData);
205+
}
206+
207+
@Test
208+
void register6WithMockDatabaseForSOLID(){
173209

174210
file.delete();
175211

@@ -182,7 +218,6 @@ public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel us
182218

183219
Assertions.assertEquals("Brad", user.getSignedUpUsername());
184220
Assertions.assertTrue(user.getIsAdmin());
185-
// Assertions.assertTrue(gateway.existsByName("Steve"));
186221
Assertions.assertFalse(gateway2.existsByName("Channing"));
187222
Assertions.assertFalse(gateway2.existsByName("Ryan"));
188223
return null;
@@ -204,5 +239,4 @@ public UserRegisterResponseModel prepareFailView(String error) {
204239

205240
interactor.create(inputData);
206241
}
207-
208242
}

0 commit comments

Comments
 (0)