-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrengthCheckerTest.java
More file actions
43 lines (32 loc) · 1.38 KB
/
Copy pathPasswordStrengthCheckerTest.java
File metadata and controls
43 lines (32 loc) · 1.38 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
package com.mrhays.security.passwordchecker;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class PasswordStrengthCheckerTest {
private final PasswordStrengthChecker checker = new PasswordStrengthChecker();
@Test
void shouldReturnWeakForEmptyPassword() {
PasswordAnalysis analysis = checker.analyze("");
assertEquals(PasswordRating.WEAK, analysis.getRating());
assertEquals(0, analysis.getScore());
}
@Test
void shouldReturnWeakForCommonPassword() {
PasswordAnalysis analysis = checker.analyze("password123");
assertEquals(PasswordRating.WEAK, analysis.getRating());
assertTrue(analysis.getSuggestions().stream()
.anyMatch(suggestion -> suggestion.contains("Avoid common passwords")));
}
@Test
void shouldReturnStrongForComplexPassword() {
PasswordAnalysis analysis = checker.analyze("Str0ng!Pass2026");
assertEquals(PasswordRating.STRONG, analysis.getRating());
assertTrue(analysis.getScore() >= 80);
}
@Test
void shouldSuggestSymbolsWhenMissing() {
PasswordAnalysis analysis = checker.analyze("StrongPass2026");
assertTrue(analysis.getSuggestions().stream()
.anyMatch(suggestion -> suggestion.contains("Add symbols")));
}
}