-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPasswordCheckerTest_STUDENT.java
More file actions
206 lines (154 loc) · 5.26 KB
/
PasswordCheckerTest_STUDENT.java
File metadata and controls
206 lines (154 loc) · 5.26 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* STUDENT tests for the methods of PasswordChecker
*
* @author
*
*/
public class PasswordCheckerTest_STUDENT {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
/**
* Test if the password is less than 8 characters long. This test should throw a
* LengthException for second case.
*/
@Test
public void testIsValidPasswordTooShort() {
try {
PasswordCheckerUtility.isValidPassword("ab12#");
assertTrue("Password is long", false);
} catch (LengthException e) {
System.out.println("Successfully threw a lengthExcepetion");
assertTrue("Successfully threw a lengthExcepetion", true);
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue("Threw some other exception besides lengthException", false);
}
}
/**
* Test if the password has at least one uppercase alpha character This test
* should throw a NoUpperAlphaException for second case
*/
@Test
public void testIsValidPasswordNoUpperAlpha() {
try {
PasswordCheckerUtility.isValidPassword("aa3ggh45");
assertTrue("Password Uppercase Letters", false);
} catch (NoUpperAlphaException e) {
System.out.println("Successfully threw a no upper case exception");
assertTrue("Successfully threw a no upper case exception", true);
} catch (Exception e) {
System.out.print(e.getMessage());
assertTrue("Threw some other exception besides upper case exception", true);
}
}
/**
* Test if the password has at least one lowercase alpha character This test
* should throw a NoLowerAlphaException for second case
*/
@Test
public void testIsValidPasswordNoLowerAlpha() {
try {
PasswordCheckerUtility.isValidPassword("A80A542#0");
assertTrue("Password has lower Letter", false);
} catch (NoLowerAlphaException e) {
System.out.println("Successfully threw a no lower case exception");
assertTrue("Successfully threw a no lower case exception", true);
} catch (Exception e) {
System.out.print(e.getMessage());
assertTrue("Threw some other exception besides lower case exception", true);
}
}
/**
* Test if the password has more than 2 of the same character in sequence This
* test should throw a InvalidSequenceException for second case
*/
@Test
public void testIsWeakPassword() {
try {
PasswordCheckerUtility.isWeakPassword("aVajA25@");
assertTrue("Passwordd is between 6 to 9 characters", true);
} catch (Exception e) {
System.out.print(e.getMessage());
assertTrue("Threw some other exception besides weak exception", false);
}
}
/**
* Test if the password has more than 2 of the same character in sequence This
* test should throw a InvalidSequenceException for second case
*/
@Test
public void testIsValidPasswordInvalidSequence() {
try {
assertTrue(PasswordCheckerUtility.isValidPassword("d1eeA#e"));
PasswordCheckerUtility.isValidPassword("d1eeeA#");
assertTrue("Password is with 2 or more same chracters in sequence", false);
} catch (InvalidSequenceException e) {
System.out.println("Successfully threw an InvalidSequenceExcepetion");
assertTrue("Successfully threw an InvalidSequenceExcepetion", true);
} catch (Exception e) {
System.out.println("Successfully threw an InvalidSequenceExcepetion");
assertTrue("Threw some other exception besides an InvalidSequenceException", true);
}
}
/**
* Test if the password has at least one digit One test should throw a
* NoDigitException
*/
@Test
public void testIsValidPasswordNoDigit() {
try {
PasswordCheckerUtility.isValidPassword("AWeeA");
assertTrue("Password has atleast one digit", false);
} catch (NoDigitException e) {
System.out.println("Successfully threw an NoDigitExcepetion");
assertTrue("Successfully threw an InvalidSequenceExcepetion", true);
} catch (Exception e) {
System.out.println("Succesfully threw an NoDigitExcepetion");
assertTrue("Threw some other exception besides an InvalidSequenceException", true);
}
}
/**
* Test correct passwords This test should not throw an exception
*/
@Test
public void testIsValidPasswordSuccessful() {
try{
PasswordCheckerUtility.isValidPassword("1234aAA#zE");
assertTrue("Did not throw an any exceptions",true);
}
catch(Exception e)
{
assertTrue("Didnot Throw some other exception",true);
}
finally
{
System.out.println("Complete");
}
}
/**
* Test the invalidPasswords method Check the results of the ArrayList of
* Strings returned by the validPasswords method
*/
@Test
public void testInvalidPasswords() {
try {
PasswordCheckerUtility.isValidPassword("A@");
assertTrue("Password is valid", false);
} catch (Exception e) {
System.out.println("Password is invalid, less than 6, misses either Upper or lower characters, and specail characters.");
assertTrue("Password is invalid", true);
}
}
}